private TblPromoCriteria UpdateOrInsertTblPromoCriteria(TblPromoCriteria newRow, string company) { using (var context = new ccnewEntities(GetSqlConnectionString(company))) { var oldRow = (from e in context.TblPromoCriterias where e.Glserial == newRow.Glserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); var oldStores = (from e in context.TblStorePromoDetails where e.Glserial == newRow.Glserial select e); foreach (var oldstore in oldStores) { context.DeleteObject(oldstore); } foreach (var storeRow in newRow.TblStorePromoDetails.ToList()) { storeRow.TblPromoCriteria1 = null; storeRow.TblPromoCriteria = newRow.Glserial; context.TblStorePromoDetails.AddObject(storeRow); } var oldbrands = (from e in context.TblBrandPromoDetails where e.Glserial == newRow.Glserial select e); foreach (var oldbrand in oldbrands) { context.DeleteObject(oldbrand); } foreach (var Brandrow in newRow.TblBrandPromoDetails.ToList()) { Brandrow.TblPromoCriteria1 = null; Brandrow.TblPromoCriteria = newRow.Glserial; context.TblBrandPromoDetails.AddObject(Brandrow); } } //else //{ // context.TblPromoCriterias.AddObject(newRow); //} context.SaveChanges(); return(newRow); } }
private int DeleteTblPromoCriteria(TblPromoCriteria row, string company) { using (var context = new ccnewEntities(GetSqlConnectionString(company))) { var oldRow = (from e in context.TblPromoCriterias where e.Glserial == row.Glserial select e).SingleOrDefault(); if (oldRow != null) { context.DeleteObject(oldRow); context.SaveChanges(); } return(row.Glserial); } }
private TblPromoCriteria UpdateOrInsertTblPromoCriteria(TblPromoCriteria newRow, ccnewEntities context) { var oldRow = (from e in context.TblPromoCriterias where e.Glserial == newRow.Glserial select e).SingleOrDefault(); if (oldRow != null) { GenericUpdate(oldRow, newRow, context); var oldStores = (from e in context.TblStorePromoDetails where e.Glserial == newRow.Glserial select e); foreach (var oldstore in oldStores) { context.DeleteObject(oldstore); } foreach (var storeRow in newRow.TblStorePromoDetails.ToList()) { storeRow.TblPromoCriteria1 = null; storeRow.TblPromoCriteria = newRow.Glserial; context.TblStorePromoDetails.AddObject(storeRow); } var oldbrands = (from e in context.TblBrandPromoDetails where e.Glserial == newRow.Glserial select e); foreach (var oldbrand in oldbrands) { context.DeleteObject(oldbrand); } foreach (var Brandrow in newRow.TblBrandPromoDetails.ToList()) { Brandrow.TblPromoCriteria1 = null; Brandrow.TblPromoCriteria = newRow.Glserial; context.TblBrandPromoDetails.AddObject(Brandrow); } } return(newRow); }