public static Custodian GetNewCustodian() { Custodian custodian = new Custodian(); custodian.InitializeActivatedProducts(); return(custodian); }
public static void SaveActivatedProducts(Custodian custodian) { using (FreeMarketEntities db = new FreeMarketEntities()) { foreach (Product product in custodian.ActivatedProducts.Products) { if (product.CustodianActivated) { ProductCustodian productCustodian = db.ProductCustodians .Where(c => c.ProductNumber == product.ProductNumber && c.SupplierNumber == product.SupplierNumber && c.CustodianNumber == custodian.CustodianNumber) .FirstOrDefault(); if (productCustodian == null) { productCustodian = new ProductCustodian { AmountLastIncreasedBySupplier = null, CustodianName = custodian.CustodianName, CustodianNumber = custodian.CustodianNumber, DateLastIncreasedBySupplier = null, ProductNumber = product.ProductNumber, SupplierNumber = product.SupplierNumber, QuantityOnHand = 0, StockReservedForOrders = 0, Active = true }; db.ProductCustodians.Add(productCustodian); db.SaveChanges(); } else { productCustodian.Active = true; db.Entry(productCustodian).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } else if (!product.CustodianActivated) { ProductCustodian productCustodian = db.ProductCustodians .Where(c => c.ProductNumber == product.ProductNumber && c.SupplierNumber == product.SupplierNumber && c.CustodianNumber == custodian.CustodianNumber) .FirstOrDefault(); if (productCustodian == null) { } else { productCustodian.Active = false; db.Entry(productCustodian).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } } } }
public static void SaveCustodian(Custodian custodian) { using (FreeMarketEntities db = new FreeMarketEntities()) { db.Entry(custodian).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); SaveActivatedProducts(custodian); } }
public static void CreateCustodian(Custodian custodian) { using (FreeMarketEntities db = new FreeMarketEntities()) { Custodian custodianDB = db.Custodians .Where(c => c.CustodianNumber == custodian.CustodianNumber) .FirstOrDefault(); if (custodianDB == null) { db.Custodians.Add(custodian); db.SaveChanges(); SaveActivatedProducts(custodian); } } }
public static Custodian GetSpecificCustodian(int custodianNumber) { Custodian custodian = new Custodian(); using (FreeMarketEntities db = new FreeMarketEntities()) { custodian = db.Custodians.Find(custodianNumber); if (custodian == null) { return(new Custodian()); } custodian.InitializeActivatedProducts(); } return(custodian); }
public static void CreateNewProduct(Product product) { try { product.DateAdded = DateTime.Now; product.DateModified = DateTime.Now; product.DepartmentNumber = int.Parse(product.SelectedDepartment); } catch { return; } using (FreeMarketEntities db = new FreeMarketEntities()) { db.Products.Add(product); db.SaveChanges(); foreach (ProductSize item in product.SizeVariations) { if (item.PricePerUnit > 0 && item.Activated == true) { ProductSupplier productSupplierDb = new ProductSupplier() { ProductNumber = product.ProductNumber, SupplierNumber = int.Parse(product.SelectedSupplier), PricePerUnit = item.PricePerUnit, SpecialPricePerUnit = 0, RetailPricePerUnit = 0, SizeType = item.SizeId }; db.ProductSuppliers.Add(productSupplierDb); db.SaveChanges(); } } Custodian custodian = db.Custodians.Find(product.SelectedCustodianNumber); if (custodian == null) { return; } try { foreach (ProductSize item in product.SizeVariations) { if (item.PricePerUnit > 0 && item.Activated == true) { ProductCustodian productCustodianDb = new ProductCustodian() { AmountLastIncreasedBySupplier = null, CustodianNumber = product.SelectedCustodianNumber, DateLastIncreasedBySupplier = null, ProductNumber = product.ProductNumber, SupplierNumber = int.Parse(product.SelectedSupplier), QuantityOnHand = 0, StockReservedForOrders = 0, SizeType = item.SizeId }; db.ProductCustodians.Add(productCustodianDb); db.SaveChanges(); } } } catch (Exception e) { ExceptionLogging.LogException(e); } } }