public async Task <NpvProfile> AddAsync(NpvProfile newProfile) { context.Add(newProfile); await context.SaveChangesAsync(); return(newProfile); }
public NpvProfile Add(NpvProfile newProfile) { context.Add(newProfile); context.SaveChanges(); return(newProfile); }
public void GetByIdTest() { NpvProfile npvP = null; using (var context = this.TestingContext) { var repository = new NpvProfileRepository(context); npvP = repository.GetById(1); } Assert.IsNotNull(npvP, "npvP is null"); Assert.IsTrue(npvP.Id == 1, "npvP.Id is not 1"); Assert.IsNotNull(npvP.CashFlows, "CashFlow is null"); Assert.IsTrue(npvP.CashFlows.Count == 3, "CashFlow count is not 3"); Assert.IsNotNull(npvP.NPVs, "NPVs is null"); Assert.IsTrue(npvP.NPVs.Count == 3, "CashFlow count is not 3"); }
public void UpdateTest() { NpvProfile npvP = null; using (var context = this.TestingContext) { var repository = new NpvProfileRepository(context); npvP = new NpvProfile { Id = 2, Name = "Profile 2 Updated", InitialCost = 100M, LowerBoundRate = 0.1F, UpperBoundRate = 0.2F, RateIncrement = 0.5F, CashFlows = new List <CashFlow> { new CashFlow { Value = 1 } }, NPVs = new List <RateNpv> { new RateNpv { Rate = 0.1F, Npv = 1000M } } }; npvP = repository.Update(npvP); } Assert.IsNotNull(npvP, "npvP is null"); Assert.AreEqual(2, npvP.Id, "Id is not equal"); Assert.AreEqual("Profile 2 Updated", npvP.Name, "Name is not equal"); Assert.IsNotNull(npvP.CashFlows, "CashFlow is null"); Assert.IsTrue(npvP.CashFlows.Count == 1, "CashFlow count is not 1"); Assert.IsNotNull(npvP.NPVs, "NPVs is null"); Assert.IsTrue(npvP.NPVs.Count == 1, "CashFlow count is not 1"); }
public async Task <NpvProfile> UpdateAsync(NpvProfile updatedProfile) { // delete related records first await DeleteNpvProfileRelations(updatedProfile.Id); context.Entry(updatedProfile).State = EntityState.Modified; updatedProfile.CashFlows.ToList().ForEach(_ => { context.Attach(_); }); updatedProfile.NPVs.ToList().ForEach(_ => { context.Attach(_); }); await context.SaveChangesAsync(); return(updatedProfile); }
public NpvProfile Update(NpvProfile updatedProfile) { // delete related records first DeleteNpvProfileRelations(updatedProfile.Id); context.Entry(updatedProfile).State = EntityState.Modified; updatedProfile.CashFlows.ToList().ForEach(n => { context.Attach(n); }); updatedProfile.NPVs.ToList().ForEach(n => { context.Attach(n); }); context.SaveChanges(); return(updatedProfile); }