Advertisement
ivana_andreevska

AV6 Voved vo MVC

Jun 2nd, 2022
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.74 KB | None | 0 0
  1. M O V I E :
  2. @model Aud1._1_MVC.Models.MovieRentals
  3.  
  4. @{
  5.     ViewBag.Title = "Random";
  6. }
  7.  
  8. <h2>@Model.movie.Name<h2>
  9.  
  10. <h5>Rating: @Model.movie.Rating</h5>
  11.  
  12. <img src="@Model.movie.ImageUrl" />
  13.  
  14. <h3>Rented: </h3>
  15. <ul>
  16. @{
  17.     int i = 0;
  18.     foreach (var client in Model.clients)
  19.     {
  20.                <li> <a href="ShowClient/@i">@client.Name , @client.ClenskaKarticka</a></li>
  21.             i++;
  22.        
  23.     }
  24. }
  25.     </ul>
  26.  
  27. C L I E N T :
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Web;
  32.  
  33. namespace Aud1._1_MVC.Models
  34. {
  35.     public class Client
  36.     {
  37.         public int Id { get; set; }
  38.         public string Name  { get; set; }
  39.  
  40.         public string Address { get; set; }
  41.         public string Phone { get; set; }
  42.         public string ClenskaKarticka { get; set; }
  43.         public int Age  { get; set; }
  44.     }
  45. }
  46.  
  47. M O V I E  R E N T A L S :
  48. using System;
  49. using System.Collections.Generic;
  50. using System.Linq;
  51. using System.Web;
  52.  
  53. namespace Aud1._1_MVC.Models
  54. {
  55.     public class MovieRentals
  56.     {
  57.        public Movie movie { get; set; }
  58.         public List<Client> clients { get; set; }  
  59.         public MovieRentals()
  60.         {
  61.             clients=new List<Client>();
  62.  
  63.         }
  64.     }
  65. }
  66.  
  67. M O V I E  C O N T R O L L E R
  68. using System;
  69. using System.Collections.Generic;
  70. using System.Linq;
  71. using System.Web;
  72. using System.Web.Mvc;
  73. using Aud1._1_MVC.Models;
  74.  
  75. namespace Aud1._1_MVC.Controllers
  76. {
  77.     public class MoviesController : Controller
  78.     {
  79.         public static Movie movie = new Movie()
  80.         {
  81.             Name ="Shrek!",
  82.             Rating =5,
  83.             DownloadURL ="test",
  84.             ImageUrl = @"https://www.looper.com/img/gallery/things-only-adults-notice-in-shrek/intro-1573597941.jpg"
  85.         };
  86.         public static List<Client> clients = new List<Client>()
  87.        {
  88.           new Client()
  89.           {
  90.               Name="Ivana",
  91.               ClenskaKarticka="203123",
  92.               Address="Nekoja adresa",
  93.               Age=20,
  94.               Phone="075210307"
  95.           },
  96.           new Client()
  97.           {
  98.               Name="Ivona",
  99.               ClenskaKarticka="19811",
  100.               Address="Nekoja adresa2",
  101.               Age=15,
  102.               Phone="07210447"
  103.           },
  104.           new Client()
  105.           {
  106.               Name="Aleksandar",
  107.               ClenskaKarticka="203412",
  108.               Address="Nekoja adresa3",
  109.               Age=29,
  110.               Phone="071297221"
  111.           }
  112.  
  113.        };
  114.         public ActionResult Index()
  115.         {
  116.             return View();
  117.         }
  118.         public ActionResult Random()
  119.         {
  120.             MovieRentals model=new MovieRentals();
  121.             model.clients = clients;
  122.             model.movie = movie;
  123.             return View(model);
  124.         }
  125.         public ActionResult ShowClient(int id)
  126.         {
  127.             var model=clients.ElementAt(id);
  128.  
  129.             return View(model);
  130.         }
  131.     }
  132. }
  133.  
  134. R A N D O M  V I E W:
  135. @model Aud1._1_MVC.Models.MovieRentals
  136.  
  137. @{
  138.     ViewBag.Title = "Random";
  139. }
  140.  
  141. <h2>@Model.movie.Name<h2>
  142.  
  143. <h5>Rating: @Model.movie.Rating</h5>
  144.  
  145. <img src="@Model.movie.ImageUrl" />
  146.  
  147. <h3>Rented: </h3>
  148. <ul>
  149. @{
  150.     int i = 0;
  151.     foreach (var client in Model.clients)
  152.     {
  153.                <li> <a href="ShowClient/@i">@client.Name , @client.ClenskaKarticka</a></li>
  154.             i++;
  155.        
  156.     }
  157. }
  158.     </ul>
  159.  
  160. S H O W  C L I E N T  V I E W :
  161. @model Aud1._1_MVC.Models.Client
  162. @{
  163.     ViewBag.Title = "ShowClient";
  164. }
  165. @if(Model.Age<18)
  166. {
  167.     <h2 style="color:red">Potreben nadzor od roditel</h2>                
  168.  }
  169.  
  170.  
  171.  
  172. <h2>@Model.Name ,  @Model.ClenskaKarticka </h2>
  173. <h5>Adresa: @Model.Address</h5>
  174. <h5>Phone number: @Model.Phone</h5>
  175.  
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement