Commit c784e08b authored by TTrueBenji's avatar TTrueBenji

Добавить Action About.

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

#1
parent ea32df3f
......@@ -27,18 +27,13 @@ namespace PhoneStore.Controllers
_environment = environment;
_uploadService = uploadService;
}
/// <summary>
/// Действие, которое возвращает страницу со списком смартфонов
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Index(int? brandId, string name)
{
IEnumerable<Brand> brands = _db.Brands;
IQueryable<Phone> phones = _db.Phones
.Include(p => p.Brand)
.AsQueryable();
IEnumerable<Brand> brands = _db.Brands;
if (brandId is > 0)
phones = _db.Phones.Where(p => p.BrandId == brandId);
......@@ -106,6 +101,7 @@ namespace PhoneStore.Controllers
[HttpGet]
public IActionResult Edit(int phoneId)
{
var brands = _db.Brands.ToList();
var phone = _db.Phones.FirstOrDefault(p => p.Id == phoneId);
if (phone is null)
{
......@@ -117,7 +113,7 @@ namespace PhoneStore.Controllers
Name = phone.Name,
Price = phone.Price,
BrandId = (int)phone.BrandId,
Brands = _db.Brands.ToList()
Brands = brands
};
return View(model);
}
......@@ -151,5 +147,18 @@ namespace PhoneStore.Controllers
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