/// <summary> /// Update OrderItem's information in DB /// </summary> /// <param name="orderItem"></param> /// <returns>result status</returns> public async Task <bool> UpdateAsync(OrderItemServiceModel orderItem) { var product = await productRepository .GetById(orderItem.ProductId) .FirstAsync(); var oldOrderItem = await this.GetOrderItemFromDBAsync(orderItem.Id); var updatedOrderItem = orderItem.UpdateProperties(oldOrderItem); updatedOrderItem.PurchasePrice = updatedOrderItem.Quantity * product.Price; return(await this.orderItemRepository.UpdateAsync(updatedOrderItem)); }
/// <summary> /// Add new OrderItem to DB /// </summary> /// <param name="orderItem"></param> /// <returns>new OrderItems's id</returns> public async Task <Guid> SaveAsync(OrderItemServiceModel orderItem) { var product = await productRepository .GetById(orderItem.ProductId) .FirstAsync(); var repositoryOrderItem = new OrderItem { Id = orderItem.Id, Quantity = orderItem.Quantity, PurchasePrice = orderItem.Quantity * product.Price, Color = (int)(Colors)Enum.Parse(typeof(Colors), orderItem.Color), OrderId = orderItem.OrderId, ProductId = orderItem.ProductId }; return(await this.orderItemRepository.InsertAsync(repositoryOrderItem)); }