public static void UpdateDBBond(this Models.DBBond dbBond, ViewModels.Bond viewBond) { dbBond.Company = viewBond.Company; dbBond.PurchasePrice = viewBond.PurchasePrice; dbBond.PurchaseDate = viewBond.PurchaseDate; dbBond.SellingPrice = viewBond.SellingPrice; dbBond.SellingDate = viewBond.SellingDate; dbBond.CurrentPurchasePrice = viewBond.CurrentPurchasePrice; dbBond.CurrentSellingPrice = viewBond.CurrentSellingPrice; dbBond.Risk = viewBond.Risk; dbBond.InterestRate = viewBond.InterestRate; dbBond.CouponFrequency = viewBond.CouponFrequency; }
public static ViewModels.Bond ToViewBond(this Models.DBBond dbUser) { return(new ViewModels.Bond { Id = dbUser.Id, Company = dbUser.Company, CouponFrequency = dbUser.CouponFrequency, CurrentPurchasePrice = dbUser.CurrentPurchasePrice, CurrentSellingPrice = dbUser.CurrentSellingPrice, InterestRate = dbUser.InterestRate, PurchaseDate = dbUser.PurchaseDate, PurchasePrice = dbUser.PurchasePrice, Risk = dbUser.Risk, SellingDate = dbUser.SellingDate, SellingPrice = dbUser.SellingPrice }); }
public async Task <ActionResult <IEnumerable <ViewModels.Bond> > > PostBond(IEnumerable <ViewModels.Bond> bonds) { var accessAllowed = _roleChecker.CheckAccessList(User, null, _adminAccessList, "PostBond"); if (!accessAllowed) { return(StatusCode(StatusCodes.Status403Forbidden, new { error = "Access denied" })); } foreach (ViewModels.Bond bond in bonds) { var company = await _context.Companies.FindAsync(bond.Company.Name); if (company is null) { _context.Add(bond.Company); } if (bond.Id is null) { var bdBond = new Models.DBBond(); bdBond.UpdateDBBond(bond); _context.Bonds.Add(bdBond); } else { var bdBond = await _context.Bonds.FindAsync(bond.Id); if (bdBond is null) { bdBond = new Models.DBBond(); bdBond.UpdateDBBond(bond); _context.Bonds.Add(bdBond); } else { bdBond.UpdateDBBond(bond); } } } await _context.SaveChangesAsync(); return(Ok(bonds)); }