public void BackupFranchiseCoverageById(FranchiseCoverage lastCoverage) { var model = new FranchiseCoverageLog { FranchiseId = lastCoverage.FranchiseId, LastConfig = lastCoverage.LastConfig, StoresCoverage = lastCoverage.StoresCoverage, TimestampLog = lastCoverage.TimestampInsUpd, UserIdLog = lastCoverage.LastUserId, }; DbEntities.FranchiseCoverageLog.Add(model); DbEntities.SaveChanges(); }
public void SaveFranchiseCoverage(FranchiseCoverageModel franchiseCoverage, FranchiseCoverage lastCoverage, string userId, List <SetCoverageStoreModel> lstFranchiseCoverage) { var bIsNew = lastCoverage == null; if (bIsNew) { lastCoverage = new FranchiseCoverage(); } lastCoverage.FranchiseId = franchiseCoverage.Id; lastCoverage.LastConfig = franchiseCoverage.LastConfig; lastCoverage.LastUserId = userId; lastCoverage.StoresCoverage = franchiseCoverage.Stores; lastCoverage.TimestampInsUpd = DateTime.Now; if (bIsNew) { DbEntities.FranchiseCoverage.Add(lastCoverage); } DbEntities.FranchiseStoreGeoMap.RemoveRange(DbEntities.FranchiseStoreGeoMap.Where(e => e.FranchiseStore.FranchiseId == franchiseCoverage.Id)); foreach (var coverageStoreModel in lstFranchiseCoverage) { foreach (var coverage in coverageStoreModel.Coverage) { DbEntities.FranchiseStoreGeoMap.Add(new FranchiseStoreGeoMap { FranchiseStoreId = coverageStoreModel.StoreId, Coverage = coverage }); } } DbEntities.SaveChanges(); }