public async Task <IActionResult> Order(Cart cart) { foreach (var position in cart.Positions) { if (!FiguresStorage.CheckIfAvailable(position.Figure, position.Count)) { return(new BadRequestResult()); } position.Figure = await _figureStorage.GetFigureById(position.Figure.FigureId); // получаем фигуру из хранилища и кладем его в заказ } var order = new Order { Positions = cart.Positions.Select(p => { p.Figure.Validate(); return(p); }).ToList() }; foreach (var position in cart.Positions) { FiguresStorage.Reserve(position.Figure, position.Count); // резервируем резерв в Redis } var result = await _orderStorage.Save(order); return(new OkObjectResult(result)); }
private async Task <decimal> CreateOrder(Cart cart) { var order = _cartConvertor.ConvertTo(cart); Update(cart); return(await _orderStorage.Save(order)); }
public async Task <decimal> OrderFigures(Cart cart) { Order order = new Order { Positions = cart.Positions.Select(x => new OrderFigure(x)).ToList() }; order.Positions.ForEach(x => x.Figure.Validate()); cart.Positions.ForEach(x => { if (_figuresStorage.CheckIfAvailable(x.Type, x.Count)) { throw new FigureNotAvailableException(); } }); cart.Positions.ForEach(x => _figuresStorage.Reserve(x.Type, x.Count)); return(await _orderStorage.Save(order)); }