public static int CopyProgram(int id, string loggedOnUser) { using (CustomClearviewEntities ctx = new CustomClearviewEntities()) { RateRepository repo = new RateRepository(ctx); Program current = repo.Find(r => r.ProgramId == id, type => type.ProgramVendors); Program copy = new Program { AccountNumberFixedLength = current.AccountNumberFixedLength, AccountNumberLength = current.AccountNumberLength, AccountNumberTypeId = current.AccountNumberTypeId, BrandId = current.BrandId, CancellationVerbiage = current.CancellationVerbiage, CancellationVerbiageSpanish = current.CancellationVerbiageSpanish, EffectiveEndDate = current.EffectiveEndDate, EffectiveStartDate = current.EffectiveStartDate, Etf = current.Etf, Hefpa = current.Hefpa, Market = current.Market, MeterNumber = current.MeterNumber, MeterNumberLength = current.MeterNumberLength, Msf = current.Msf, PremiseTypeId = current.PremiseTypeId, ProgramCode = current.ProgramCode + " - COPY", ProgramName = current.ProgramName + " - COPY", ProgramDescription = current.ProgramDescription + " - COPY", PromotionalCode = current.PromotionalCode, Rate = current.Rate, RateVerbiage = current.RateVerbiage, RateVerbiageSpanish = current.RateVerbiageSpanish, RescindBy = current.RescindBy, SalesChannel = current.SalesChannel, State = current.State, Term = current.Term, UnitOfMeasureId = current.UnitOfMeasureId, UtilityId = current.UtilityId, UtilityTypeId = current.UtilityTypeId, UpdatedBy = loggedOnUser, UpdatedDateTime = DateTime.Now, ServiceReference = current.ServiceReference, CreditCheck = current.CreditCheck }; foreach (ProgramVendor pv in current.ProgramVendors) { copy.ProgramVendors.Add(new ProgramVendor { VendorId = pv.VendorId, CreatedBy = "test", CreatedDateTime = DateTime.Now }); } repo.Create(copy); ctx.SaveChanges(); return(copy.ProgramId); } }
public static Program GetProgram(int id) { Program program; using (CustomClearviewEntities ctx = new CustomClearviewEntities()) { RateRepository repo = new RateRepository(ctx); program = repo.Find(x => x.ProgramId == id, t => t.ProgramVendors); } return(program); }
public static int UpdateRate(Program program) { if (program == null) { throw new System.ArgumentNullException() { Source = "program" }; } using (CustomClearviewEntities ctx = new CustomClearviewEntities()) { using (DbContextTransaction trans = ctx.Database.BeginTransaction()) { RateRepository repo = new RateRepository(ctx); Program oldRate = repo.Find(p => p.ProgramId == program.ProgramId, t => t.ProgramVendors); oldRate.ProgramId = program.ProgramId; oldRate.ProgramCode = program.ProgramCode; oldRate.ProgramName = program.ProgramName; oldRate.ProgramDescription = program.ProgramDescription; oldRate.EffectiveStartDate = program.EffectiveStartDate; oldRate.EffectiveEndDate = program.EffectiveEndDate; oldRate.Msf = program.Msf; oldRate.Etf = program.Etf; oldRate.Rate = program.Rate; oldRate.PromotionalCode = program.PromotionalCode; oldRate.UnitOfMeasureId = program.UnitOfMeasureId; oldRate.Term = program.Term; oldRate.UtilityTypeId = program.UtilityTypeId; oldRate.PremiseTypeId = program.PremiseTypeId; oldRate.State = program.State; oldRate.UtilityId = program.UtilityId; oldRate.AccountNumberTypeId = program.AccountNumberTypeId; oldRate.AccountNumberLength = program.AccountNumberLength; oldRate.AccountNumberFixedLength = program.AccountNumberFixedLength; oldRate.MeterNumber = program.MeterNumber; oldRate.MeterNumberLength = program.MeterNumberLength; oldRate.ServiceReference = program.ServiceReference; oldRate.RescindBy = program.RescindBy; oldRate.Hefpa = program.Hefpa; oldRate.Vendor = program.Vendor; oldRate.Market = program.Market; oldRate.SalesChannel = program.SalesChannel; oldRate.RateVerbiage = program.RateVerbiage; oldRate.CancellationVerbiage = program.CancellationVerbiage; oldRate.RateVerbiageSpanish = program.RateVerbiageSpanish; oldRate.CancellationVerbiageSpanish = program.CancellationVerbiageSpanish; oldRate.BrandId = program.BrandId; oldRate.UpdatedBy = program.UpdatedBy; oldRate.UpdatedDateTime = program.UpdatedDateTime; oldRate.CreditCheck = program.CreditCheck; List <ProgramVendor> deleteList = new List <ProgramVendor>(); List <ProgramVendor> addList = new List <ProgramVendor>(); foreach (ProgramVendor cpv in oldRate.ProgramVendors) { if (!program.ProgramVendors.Any(x => x.ProgramId == cpv.ProgramId && x.VendorId == cpv.VendorId)) { deleteList.Add(cpv); } } foreach (ProgramVendor pv in program.ProgramVendors) { if (!oldRate.ProgramVendors.Any(x => x.ProgramId == pv.ProgramId && x.VendorId == pv.VendorId)) { pv.ProgramId = program.ProgramId; addList.Add(pv); } } foreach (ProgramVendor d in deleteList) { oldRate.ProgramVendors.Remove(d); } foreach (ProgramVendor a in addList) { oldRate.ProgramVendors.Add(a); } repo.Update(oldRate); ctx.SaveChanges(); trans.Commit(); } } return(program.ProgramId); }