コード例 #1
0
        public IActionResult Delete(string id)
        {
            if (id != null)
            {
                CertificateOfDeposit certificateOfDeposit = _context.CertificateOfDeposits.Find(id);
                _context.CertificateOfDeposits.Remove(certificateOfDeposit);
                _context.SaveChanges();

                return(Ok(certificateOfDeposit));
            }

            return(RedirectToAction("Index"));
        }
コード例 #2
0
        public IActionResult Create([FromBody] CertificateOfDeposit model)
        {
            if (ModelState.IsValid)
            {
                CertificateOfDeposit certificateOfDeposit = new CertificateOfDeposit
                {
                    AccountNumber = model.AccountNumber,
                    Type          = model.Type,
                    Term          = model.Term,
                    InterestRate  = model.InterestRate,
                    PortfolioId   = model.PortfolioId
                };

                _context.CertificateOfDeposits.Add(certificateOfDeposit);
                _context.SaveChanges();

                return(Ok(certificateOfDeposit));
            }

            return(Ok(model));
        }
コード例 #3
0
        public IActionResult Edit([FromBody] CertificateOfDeposit model)
        {
            if (ModelState.IsValid)
            {
                CertificateOfDeposit certificateOfDeposit = _context.CertificateOfDeposits.Find(model.Id);

                if (certificateOfDeposit != null)
                {
                    certificateOfDeposit.AccountNumber = model.AccountNumber;
                    certificateOfDeposit.Type          = model.Type;
                    certificateOfDeposit.Term          = model.Term;
                    certificateOfDeposit.InterestRate  = model.InterestRate;

                    var certificateOfDepositUpdate = _context.CertificateOfDeposits.Attach(certificateOfDeposit);
                    certificateOfDepositUpdate.State = EntityState.Modified;
                    _context.SaveChanges();

                    return(Ok(certificateOfDeposit));
                }
            }

            return(Ok(model));
        }