public UpdateOrderRequest SingleRequestConverter(UpdateOrdersRequest createRequest) { List <UpdateOrderProductRequest> product = new List <UpdateOrderProductRequest>() { new UpdateOrderProductRequest() { ProductId = createRequest.OrderProductsId } }; UpdateOrderRequest request = new UpdateOrderRequest() { CustomerId = createRequest.CustomerId, TransportId = createRequest.TransportId, OrderAcceptanceDate = createRequest.OrderAcceptanceDate, OrderDispatchDate = createRequest.OrderDispatchDate, OrderProducts = product }; return(request); }
public async Task <Order> CreateOrderAsync(UpdateOrderRequest createRequest) { var dbOrder = Mapper.Map <UpdateOrderRequest, KatlaSport.DataAccess.OrderCatalogue.Order>(createRequest); dbOrder.ManagerId = 2; // Add logic later var productItem = _productStoreContext.Items.FirstOrDefault(i => i.ProductId == createRequest.ProductId); dbOrder.TotalCost = createRequest.ProductAmount * productItem.Product.Price; _orderCatalogueContext.OrderProductItems.Add( new OrderProductItem() { Amount = createRequest.ProductAmount, ItemId = createRequest.ProductId }); dbOrder.OrderDate = DateTime.UtcNow; dbOrder.StatusId = 1; // Don't know how to realize logic using enum _orderCatalogueContext.Orders.Add(dbOrder); await _orderCatalogueContext.SaveChangesAsync(); return(Mapper.Map <Order>(dbOrder)); }
/// <inheritdoc/> public async Task <Order> UpdateOrderAsync(int orderId, UpdateOrderRequest updateRequest) { var dbOrders = await _context.Orders.Where(p => p.Code == updateRequest.Code && p.Id != orderId).ToArrayAsync(); if (dbOrders.Length > 0) { throw new RequestedResourceHasConflictException("code"); } dbOrders = await _context.Orders.Where(p => p.Id == orderId).ToArrayAsync(); if (dbOrders.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbOrder = dbOrders[0]; Mapper.Map(updateRequest, dbOrder); await _context.SaveChangesAsync(); return(Mapper.Map <Order>(dbOrder)); }
/// <inheritdoc/> public async Task <Order> UpdateOrderAsync(UpdateOrderRequest updateRequest) { return(await _orderRepository.Update(updateRequest)); }
/// <inheritdoc/> public async Task <Order> CreateOrderAsync(UpdateOrderRequest createRequest) { return(await _orderRepository.Add(createRequest)); }