Commit c784e08b authored by TTrueBenji's avatar TTrueBenji

Добавить Action About.

***
- Добавил Action About.
- Убрал вызов излишнего метода Include.
***

#1
parent ea32df3f
...@@ -27,19 +27,14 @@ namespace PhoneStore.Controllers ...@@ -27,19 +27,14 @@ namespace PhoneStore.Controllers
_environment = environment; _environment = environment;
_uploadService = uploadService; _uploadService = uploadService;
} }
/// <summary>
/// Действие, которое возвращает страницу со списком смартфонов
/// </summary>
/// <returns></returns>
[HttpGet] [HttpGet]
public IActionResult Index(int? brandId, string name) public IActionResult Index(int? brandId, string name)
{ {
IEnumerable<Brand> brands = _db.Brands;
IQueryable<Phone> phones = _db.Phones IQueryable<Phone> phones = _db.Phones
.Include(p => p.Brand)
.AsQueryable(); .AsQueryable();
IEnumerable<Brand> brands = _db.Brands;
if (brandId is > 0) if (brandId is > 0)
phones = _db.Phones.Where(p => p.BrandId == brandId); phones = _db.Phones.Where(p => p.BrandId == brandId);
...@@ -106,6 +101,7 @@ namespace PhoneStore.Controllers ...@@ -106,6 +101,7 @@ namespace PhoneStore.Controllers
[HttpGet] [HttpGet]
public IActionResult Edit(int phoneId) public IActionResult Edit(int phoneId)
{ {
var brands = _db.Brands.ToList();
var phone = _db.Phones.FirstOrDefault(p => p.Id == phoneId); var phone = _db.Phones.FirstOrDefault(p => p.Id == phoneId);
if (phone is null) if (phone is null)
{ {
...@@ -117,7 +113,7 @@ namespace PhoneStore.Controllers ...@@ -117,7 +113,7 @@ namespace PhoneStore.Controllers
Name = phone.Name, Name = phone.Name,
Price = phone.Price, Price = phone.Price,
BrandId = (int)phone.BrandId, BrandId = (int)phone.BrandId,
Brands = _db.Brands.ToList() Brands = brands
}; };
return View(model); return View(model);
} }
...@@ -151,5 +147,18 @@ namespace PhoneStore.Controllers ...@@ -151,5 +147,18 @@ namespace PhoneStore.Controllers
return Ok("Файл успешно загружен"); return Ok("Файл успешно загружен");
} }
[HttpGet]
public IActionResult About(int? id)
{
if (!id.HasValue) return RedirectToAction("Error", "Errors", new {statusCode = 777});
var phone = _db.Phones
.Include(p => p.Brand)
.FirstOrDefault(p => p.Id == id);
if (phone is null)
return RedirectToAction("Error", "Errors", new {statusCode = 777});
return View(phone);
}
} }
} }
\ No newline at end of file
@model Phone
@{
ViewBag.Title = "Подробная информация";
Layout = "_Layout";
}
<h2>@Model.Name</h2>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment