public <b>async Task<IActionResult></b> ByMake(int makeId, string makeName)
{
ViewBag.MakeName = makeName;
return View(<b>await _serviceWrapper.GetCarsByMakeAsync(makeId)</b>);
}
[HttpGet("{id?}")]
public <b>async Task<IActionResult></b> Details(int? id)
{
if (!id.HasValue)
{
return BadRequest();
}
var car = await <b>GetOneCarAsync(id)</b>;
if (car == null)
{
return NotFound();
}
return View(car);
}
[HttpGet]
public <b>async Task<IActionResult></b> Create()
{
ViewData["MakeId"] = <b>await GetMakesAsync()</b>;
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public <b>async Task<IActionResult></b> Create(Car car)
{
if (ModelState.IsValid)
{
<b>await _serviceWrapper.AddCarAsync(car)</b>;
return RedirectToAction(nameof(Index));
}
ViewData["MakeId"] = <b>await GetMakesAsync()</b>;
return View(car);
}
[HttpGet("{id?}")]
public <b>async Task<IActionResult></b> Edit(int? id)
{
<b>var car = await GetOneCarAsync(id)</b>;
if (car == null)
{
return NotFound();
}
ViewData["MakeId"] = <b>await GetMakesAsync()</b>;
return View(car);
}
[HttpPost("{id}")]
[ValidateAntiForgeryToken]
public <b>async Task<IActionResult></b> Edit(int id, Car car)
{
if (id != car.Id)
(window.adrunTag = window.adrunTag || []).push({v: 1, el: 'adrun-4-390', c: 4, b: 390})
{
return BadRequest();
}
if (ModelState.IsValid)
{
<b>await _serviceWrapper.UpdateCarAsync(id,car)</b>;
return RedirectToAction(nameof(Index));
}
ViewData["MakeId"] = <b>await GetMakesAsync()</b>;
return View(car);
}
[HttpGet("{id?}")]
public <b>async Task<IActionResult></b> Delete(int? id)
{
<b> var car = await GetOneCarAsync(id);</b>
if (car == null)
{
return NotFound();
}
return View(car);
}
[HttpPost("{id}")]
[ValidateAntiForgeryToken]
public <b>async Task<IActionResult></b> Delete(int id, Car car)
{
<b> await _serviceWrapper.DeleteCarAsync(id,car);</b>
return RedirectToAction(nameof(Index));
}
Обновление компонента представления
В текущий момент внутри компонента представления MenuViewComponent применяется уровень доступа к данным и синхронная версия Invoke(). Внесите в класс следующие изменения:
using System.Linq;
<b>using System.Threading.Tasks;</b>
using AutoLot.Dal.Repos.Interfaces;
<b>using AutoLot.Services.ApiWrapper;</b>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewComponents;
namespace AutoLot.Mvc.ViewComponents
{
public class MenuViewComponent : ViewComponent
{
<b> private readonly IApiServiceWrapper _serviceWrapper;</b>
<b> public MenuViewComponent(IApiServiceWrapper serviceWrapper)</b>
<b> {</b>
<b> _serviceWrapper = serviceWrapper;</b>