Пример #1
0
        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)));
        }
 public void Remove(CustomerProductData customerProductData)
 {
     _context.CustomerProductData.Remove(customerProductData);
 }
 public void Add(CustomerProductData customerProductData)
 {
     _context.CustomerProductData.Add(customerProductData);
 }