public async Task <NewOrderResponse> CreateOrder(NewOrderRequest request) { var customer = await _unitOfWork.CustomerRepository.FindAsync(request.CustomerId); var order = Order.Create(customer, request.Now); foreach (var orderProductRequest in request.Products) { var product = await _unitOfWork.ProductRepository.FindAsync(orderProductRequest.ProductId); var orderProduct = OrderProduct.Create(product, request.Now); orderProduct.IncreaseAmount(orderProductRequest.Amount); order.AddProduct(orderProduct); } try { _unitOfWork.OrderRepository.Attach(order); await _unitOfWork.SaveChangesAsync(); _eventDistpacher.Distpach(order); _response.Success = true; } catch (Exception e) { Console.WriteLine(e); _response.MessageError = e.Message; } return(_response); }
public async Task <StartProductoResponse> Start(StartProductRequest request) { var order = await _unitOfWork.OrderRepository.FindAsync(request.OrderId); var gCode = order.StarProduct(request.ProductId, request.Now); try { _unitOfWork.OrderRepository.Update(order); await _unitOfWork.SaveChangesAsync(); } catch (Exception e) { return(new StartProductoResponse()); } return(new StartProductoResponse() { GCode = gCode }); }