private void SetProductPrimaryKey(IModelStore <SubCategory> subcate, IModelStore <Product> product) { if (subcate.TrackedCount(StateTrackable.Deleted) == 0 && subcate.Count > 0) { var subCateId = subcate.FirstOrDefault().Productsubcategoryid; for (int i = 0; i < product.Count; i++) { if (product.GetModelState(i) == ModelState.NewModified) { product.SetValue(i, "Productsubcategoryid", subCateId); } } } }
private void SetPricePrimaryKey(IModelStore <Product> product, IModelStore <HistoryPrice> prices) { if (product.TrackedCount(StateTrackable.Deleted) == 0 && product.Count > 0) { var productId = product.FirstOrDefault().Productid; for (int i = 0; i < prices.Count; i++) { if (prices.GetModelState(i) == ModelState.NewModified) { prices.SetValue(i, "Productid", productId); } } } }
private void SetPrimaryKey(IModelStore <SalesOrderHeader> salesOrderHeaders, IModelStore <SalesOrderDetail> salesOrderDetails) { if (salesOrderHeaders.TrackedCount(StateTrackable.Deleted) == 0 && salesOrderHeaders.Count > 0) { var salesOrderId = salesOrderHeaders.FirstOrDefault().SalesOrderID; for (int i = 0; i < salesOrderDetails.Count; i++) { if (salesOrderDetails.GetModelState(i) == ModelState.NewModified) { salesOrderDetails.SetValue(i, "SalesOrderID", salesOrderId); } } } }
public int SavePerson(IModelStore <Person> person, IModelStore <BusinessEntityAddress> addresses, IModelStore <PersonPhone> phones, IModelStore <Customer> customers) { int intPersonId = 0; _context.BeginTransaction(); if (person.TrackedCount(StateTrackable.NewModified) == 1) { var businessEntity = new ModelStore <BusinessEntity>() .TrackChanges(ChangeTrackingStrategy.PropertyState); businessEntity.Add(new BusinessEntity() { ModifiedDate = DateTime.Now }); var result = businessEntity.SaveChanges(_context); if (result.InsertedCount == 1) { intPersonId = businessEntity.FirstOrDefault().BusinessEntityID; person.SetValue(0, "Businessentityid", intPersonId); } } else { intPersonId = person.FirstOrDefault().Businessentityid; } SetPrimaryKey(person, addresses, phones, customers); //Save person address, phone, customer person.SaveChanges(_context); addresses.SaveChanges(_context); phones.SaveChanges(_context); customers.SaveChanges(_context); _context.Commit(); return(intPersonId); }
public int SaveProductAndPrice(IModelStore <Product> product, IModelStore <HistoryPrice> prices) { int intProductId = 0; _context.BeginTransaction(); product.SaveChanges(_context); intProductId = product.FirstOrDefault().Productid; SetPricePrimaryKey(product, prices); prices.SaveChanges(_context); _context.Commit(); return(intProductId); }
public int SaveSalesOrderAndDetail(IModelStore <SalesOrderHeader> salesOrderHeaders, IModelStore <SalesOrderDetail> salesOrderDetails) { int intSalesOrderId = 0; _context.BeginTransaction(); salesOrderHeaders.SaveChanges(_context); intSalesOrderId = salesOrderHeaders.FirstOrDefault().SalesOrderID; SetPrimaryKey(salesOrderHeaders, salesOrderDetails); salesOrderDetails.SaveChanges(_context); _context.Commit(); return(intSalesOrderId); }
public int SaveHistoryPrices(IModelStore <SubCategory> subcate, IModelStore <Product> product, IModelStore <HistoryPrice> prices) { int intSubCateId = 0; int intProductId = 0; _context.BeginTransaction(); subcate.SaveChanges(_context); intSubCateId = subcate.FirstOrDefault().Productsubcategoryid; SetProductPrimaryKey(subcate, product); product.SaveChanges(_context); intProductId = product.FirstOrDefault().Productid; SetPricePrimaryKey(product, prices); prices.SaveChanges(_context); _context.Commit(); return(intSubCateId); }
private void SetPrimaryKey(IModelStore <Person> person, IModelStore <BusinessEntityAddress> addresses, IModelStore <PersonPhone> phones, IModelStore <Customer> customers) { if (person.TrackedCount(StateTrackable.Deleted) == 0 && person.Count > 0) { var PersonID = person.FirstOrDefault().Businessentityid; for (int i = 0; i < addresses.Count; i++) { if (addresses.GetModelState(i) == ModelState.NewModified) { addresses.SetValue(i, "Businessentityid", PersonID); } } for (int i = 0; i < phones.Count; i++) { if (phones.GetModelState(i) == ModelState.NewModified) { phones.SetValue(i, "Businessentityid", PersonID); } } for (int i = 0; i < customers.Count; i++) { if (customers.GetModelState(i) == ModelState.NewModified) { customers.SetValue(i, "Personid", PersonID); } } } }