1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+ using System . Threading . Tasks ;
5+ using Microsoft . AspNetCore . Mvc ;
6+ using MVC . Models ;
7+
8+ namespace MVC . Controllers
9+ {
10+ public class PhoneController : Controller
11+ {
12+ List < Phone > phones ;
13+ public PhoneController ( )
14+ {
15+ // Задаем структуру для отображения
16+ phones = new List < Phone >
17+ {
18+ new Phone { Id = 1 , Name = "IPhone 8" , Manufactorer = "Apple" } ,
19+ new Phone { Id = 2 , Name = "Galaxy S9" , Manufactorer = "Samsung" } ,
20+ new Phone { Id = 3 , Name = "Nexus 5" , Manufactorer = "Google" } ,
21+ new Phone { Id = 4 , Name = "IPhone X" , Manufactorer = "Apple" } ,
22+ new Phone { Id = 5 , Name = "Note 8" , Manufactorer = "Samsung" }
23+ } ;
24+ }
25+ public IActionResult Index ( )
26+ {
27+ return View ( phones ) ;
28+ }
29+
30+ public string Show ( int id )
31+ {
32+ return $ "{ phones [ id - 1 ] . Name } ";
33+ }
34+
35+ [ HttpGet ]
36+ public IActionResult Buy ( int id )
37+ {
38+ ViewBag . PhoneId = id ;
39+ return View ( phones [ id - 1 ] ) ;
40+ }
41+
42+ [ HttpPost ]
43+ public string Buy ( int PhoneId , string User )
44+ {
45+ return $ "Thanks, { User } , for the order { PhoneId } ";
46+ }
47+ }
48+ }
0 commit comments