Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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
     });
 }
Ejemplo n.º 3
0
        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));
        }