public async Task <int> CreateOrderAsync(CartOrderCreateDtoModel dtoModel) { var recipient = await this.recipientService.GetRecipientByIdAsync(dtoModel.RecipientId); var items = await this.itemService.GetItemsByItemsIdsAsync(dtoModel.ItemsIds); var orderStatus = await this.orderStatusService.GetOrderStatusByName(GlobalConstants.PendingStatus); var currentOrder = new Order() { IssuedOn = DateTime.UtcNow.AddHours(2), OrderStatus = orderStatus, Recipient = recipient, Items = items, }; // add orderId and set isordered to be true this.itemService.UpdateItems(items, currentOrder); await this.orders.AddAsync(currentOrder); await this.orders.SaveChangesAsync(); return(currentOrder.Id); }
public static CartOrderCreateDtoModel Map(int recipientId, List <CartViewModel> cartViewModels) { var itemsIds = cartViewModels.Select(x => x.ItemId).ToList(); var model = new CartOrderCreateDtoModel { RecipientId = recipientId, ItemsIds = itemsIds, }; return(model); }