private void DeleteOrderItem(OrderEntity orderEntity, OrderItemWithState orderItemWithState) { if (orderItemWithState.OrderItemId == null) { throw new OrderItemIdNotProvidedException(); } // Get order item to update var orderItemEntity = _dbContext.OrderItems.SingleOrDefault(item => item.Id == orderItemWithState.OrderItemId.Value && item.OrderId == orderEntity.Id); if (orderItemEntity == null) { throw new OrderItemNotFoundException(); } // Get order item to delete var orderItemEntityToDelete = _dbContext.OrderItems.Where(item => item.Id == orderItemWithState.OrderItemId.Value && item.OrderId == orderEntity.Id); if (orderItemEntity == null) { throw new OrderItemNotFoundException(); } _dbContext.OrderItems.RemoveRange(orderItemEntityToDelete); }
private void UpdateOrderItem(OrderEntity orderEntity, List <ProductEntity> products, OrderItemWithState orderItemWithState) { if (orderItemWithState.OrderItemId == null) { throw new OrderItemIdNotProvidedException(); } var productEntity = products.SingleOrDefault(product => product.Id == orderItemWithState.OrderItem.ProductId); if (productEntity == null) { throw new ProductNotFoundException("Specified product is not found."); } // Get order item to update var orderItemEntity = _dbContext.OrderItems.SingleOrDefault(item => item.Id == orderItemWithState.OrderItemId.Value && item.OrderId == orderEntity.Id); if (orderItemEntity == null) { throw new OrderItemNotFoundException(); } //Update Order Item orderItemEntity.Quantity = orderItemWithState.OrderItem.Quantity; /* Product information needs to be recorded, in case * if master product data is changed then you'll lose the orginal information that has been viewed * at the time of order creation */ orderItemEntity.ProductId = productEntity.Id; orderItemEntity.ProductName = productEntity.Name; orderItemEntity.Height = productEntity.Height; orderItemEntity.Weight = productEntity.Weight; orderItemEntity.Barcode = productEntity.Name; orderItemEntity.Image = productEntity.Name; orderItemEntity.SKU = productEntity.SKU; }
private void AddOrderItem(OrderEntity orderEntity, List <ProductEntity> products, OrderItemWithState orderItemWithState) { var productEntity = products.SingleOrDefault(product => product.Id == orderItemWithState.OrderItem.ProductId); if (productEntity == null) { throw new ProductNotFoundException("Specified product is not found."); } var orderItemEntity = new OrderItemEntity { OrderId = orderEntity.Id, Quantity = orderItemWithState.OrderItem.Quantity, /* Product information needs to be recorded, in case * if master product data is changed then you'll lose the orginal information that has been viewed * at the time of order creation */ ProductId = productEntity.Id, ProductName = productEntity.Name, Height = productEntity.Height, Weight = productEntity.Weight, Barcode = productEntity.Name, Image = productEntity.Name, SKU = productEntity.SKU, }; _dbContext.OrderItems.Add(orderItemEntity); }