public ActionResult Products_Update([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable <CustomerProductItem> products) { foreach (var product in products) { var customerId = SessionService.Get().CustomerViewModel.Id; var cpd = _customerProductDataRepository.GetByProduct(product.Id) .SingleOrDefault(p => p.CustomerId == customerId); if (product.IsSelected) { var target = new CustomerProductData { CustomerId = customerId, ProductId = product.Id, ProductCode = product.ProductCode, ProductDescription = product.ProductDescription, Gtin = product.Gtin, PricePerPound = product.PricePerPound, BoxQuantity = product.BoxQuantity, PieceQuantity = product.PieceQuantity, BagSizeId = product.BagSize != null ? product.BagSize.Id : (int?)null, BoxSizeId = product.BoxSize != null ? product.BoxSize.Id : (int?)null }; if (cpd != null) { _customerProductDataRepository.Remove(cpd); } _customerProductDataRepository.Add(target); } else { _customerProductDataRepository.Remove(cpd); } _customerProductDataRepository.Save(); } return(Json(products.ToDataSourceResult(request))); }
private void FillOrderDetail(OrderDetail orderDetail, OrderDetailItem orderDetailItem) { orderDetail.ProductId = orderDetailItem.ProductId; orderDetail.CustomerLocationId = orderDetailItem.CustomerLocationId; var customer = _orderRepository.Get(orderDetail.OrderId); var customerProduct = _customerProductDataRepository.GetByProduct(orderDetailItem.ProductId).FirstOrDefault(x => x.CustomerId == customer.CustomerId); if (customerProduct != null) { if (customerProduct.BoxQuantity.HasValue) { orderDetailItem.BagPieceQuantity = customerProduct.PieceQuantity.GetValueOrDefault(); } if (customerProduct.PieceQuantity.HasValue) { orderDetailItem.BoxBagQuantity = customerProduct.BoxQuantity.GetValueOrDefault(); } } orderDetail.PieceQuantity = Math.Abs(orderDetailItem.PieceQuantity); orderDetail.BoxQuantity = CalculateBoxQuantity(Math.Abs(orderDetailItem.PieceQuantity), Math.Abs(orderDetailItem.BagPieceQuantity), Math.Abs(orderDetailItem.BoxBagQuantity)); }