ПИбд-22 Боровков М В 5 лабораторная работа #6

Closed
bekodeg wants to merge 44 commits from labWork5 into labWork4
3 changed files with 19 additions and 19 deletions
Showing only changes of commit ff0dd6f3eb - Show all commits

View File

@ -115,7 +115,7 @@ namespace SushiBarClientApp.Controllers
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Create(int iceCream, int count) public void Create(int sushi, int count)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
@ -129,19 +129,19 @@ namespace SushiBarClientApp.Controllers
OrderBindingModel OrderBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
SushiId = iceCream, SushiId = sushi,
Count = count, Count = count,
Sum = Calc(count, iceCream) Sum = Calc(count, sushi)
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public double Calc(int count, int iceCream) public double Calc(int count, int sushi)
{ {
var _iceCream = var _sushi =
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiid={iceCream}" APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiid={sushi}"
); );
return Math.Round(count * (_iceCream?.Price ?? 1), 2); return Math.Round(count * (_sushi?.Price ?? 1), 2);
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace SushiBarDatabaseImplement.Implements
(!model.Id.HasValue || c.Id == model.Id) && (!model.Id.HasValue || c.Id == model.Id) &&
(string.IsNullOrEmpty(model.ClientFIO) || c.ClientFIO.Contains(model.ClientFIO)) && (string.IsNullOrEmpty(model.ClientFIO) || c.ClientFIO.Contains(model.ClientFIO)) &&
(string.IsNullOrEmpty(model.Email) || c.Email.Contains(model.Email)) && (string.IsNullOrEmpty(model.Email) || c.Email.Contains(model.Email)) &&
(string.IsNullOrEmpty(model.Password) || c.Password.Contains(model.Password))) (string.IsNullOrEmpty(model.Password) || c.Password.Equals(model.Password)))
.Select(c => c.GetViewModel) .Select(c => c.GetViewModel)
.ToList(); .ToList();
} }
@ -35,8 +35,8 @@ namespace SushiBarDatabaseImplement.Implements
.FirstOrDefault(c => .FirstOrDefault(c =>
(!model.Id.HasValue || c.Id == model.Id) && (!model.Id.HasValue || c.Id == model.Id) &&
(string.IsNullOrEmpty(model.ClientFIO) || c.ClientFIO.Contains(model.ClientFIO)) && (string.IsNullOrEmpty(model.ClientFIO) || c.ClientFIO.Contains(model.ClientFIO)) &&
(string.IsNullOrEmpty(model.Email) || c.Email.Contains(model.Email)) && (string.IsNullOrEmpty(model.Email) || c.Email.Equals(model.Email)) &&
(string.IsNullOrEmpty(model.Password) || c.Password.Contains(model.Password)))? (string.IsNullOrEmpty(model.Password) || c.Password.Equals(model.Password)))?
.GetViewModel; .GetViewModel;
} }
public ClientViewModel? Insert(ClientBindingModel model) public ClientViewModel? Insert(ClientBindingModel model)

View File

@ -12,39 +12,39 @@ namespace SushiBarRestApi.Controllers
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _order; private readonly IOrderLogic _order;
private readonly ISushiLogic _iceCream; private readonly ISushiLogic _sushi;
public MainController(ILogger<MainController> logger, IOrderLogic order, ISushiLogic iceCream) public MainController(ILogger<MainController> logger, IOrderLogic order, ISushiLogic sushi)
{ {
_logger = logger; _logger = logger;
_order = order; _order = order;
_iceCream = iceCream; _sushi = sushi;
} }
[HttpGet] [HttpGet]
public List<SushiViewModel>? GetSushiList() public List<SushiViewModel>? GetSushiList()
{ {
try try
{ {
return _iceCream.ReadList(null); return _sushi.ReadList(null);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения списка мороженного"); _logger.LogError(ex, "Ошибка получения списка суши");
throw; throw;
} }
} }
[HttpGet] [HttpGet]
public SushiViewModel? GetSushi(int iceCreamId) public SushiViewModel? GetSushi(int sushiId)
{ {
try try
{ {
return _iceCream.ReadElement(new SushiSearchModel return _sushi.ReadElement(new SushiSearchModel
{ {
Id = iceCreamId Id = sushiId
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", iceCreamId); _logger.LogError(ex, "Ошибка получения продукта по id={Id}", sushiId);
throw; throw;
} }
} }