public ActionResult Create(Product item) { item.Supplier = Supplier.TryFind(item.SupplierId); item.ProductService = SatProductService.TryFind(item.ProductServiceId); item.UnitOfMeasurement = SatUnitOfMeasurement.TryFind(item.UnitOfMeasurementId); if (!ModelState.IsValid) { return(PartialView("_Create", item)); } item.MinimumOrderQuantity = 1; item.TaxRate = WebConfig.DefaultVAT; item.IsTaxIncluded = WebConfig.IsTaxIncluded; item.PriceType = WebConfig.DefaultPriceType; item.Photo = WebConfig.DefaultPhotoFile; using (var scope = new TransactionScope()) { item.Create(); foreach (var l in PriceList.Queryable.ToList()) { var price = new ProductPrice { Product = item, List = l }; price.Create(); } scope.Flush(); } return(PartialView("_CreateSuccesful", item)); }
public ActionResult Edit(Product item) { item.Supplier = Supplier.TryFind(item.SupplierId); item.ProductService = SatProductService.TryFind(item.ProductServiceId); item.UnitOfMeasurement = SatUnitOfMeasurement.TryFind(item.UnitOfMeasurementId); if (!ModelState.IsValid) { return(PartialView("_Edit", item)); } var entity = Product.Find(item.Id); entity.Brand = item.Brand; entity.Code = item.Code; entity.Comment = item.Comment; entity.IsStockable = item.IsStockable; entity.IsPerishable = item.IsPerishable; entity.IsSeriable = item.IsSeriable; entity.IsPurchasable = item.IsPurchasable; entity.IsSalable = item.IsSalable; entity.IsInvoiceable = item.IsInvoiceable; entity.Location = item.Location; entity.Model = item.Model; entity.Name = item.Name; entity.SKU = item.SKU; entity.UnitOfMeasurement = item.UnitOfMeasurement; entity.Supplier = item.Supplier; entity.ProductService = item.ProductService; using (var scope = new TransactionScope()) { entity.UpdateAndFlush(); } return(PartialView("_Refresh")); }