Пример #1
0
        public IActionResult UpdateCreditProfileById(int id, int profileId, [FromBody] UpdateCreditProfileRequest body)
        {
            if (id <= 0 || profileId <= 0)
            {
                return(BadRequest("Invalid Id"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            CreditProfile profile = _context.CreditProfile
                                    .Where(x => x.CustomerId == id && x.Id == profileId)
                                    .SingleOrDefault();

            if (profile == null)
            {
                return(NotFound("Account not found"));
            }

            if (profile.Balance + body.WithdrawalAmount > profile.LineOfCredit)
            {
                return(StatusCode(StatusCodes.Status403Forbidden, "Insufficient funds"));
            }

            profile.Balance   += body.WithdrawalAmount;
            profile.ModifiedOn = DateTime.Now;
            profile.ModifiedBy = 1;

            _context.SaveChanges();

            return(NoContent());
        }
Пример #2
0
        public IActionResult GetCreditProfileByCustomerId(int id, int profileId)
        {
            if (id <= 0 || profileId <= 0)
            {
                return(BadRequest("Invalid Id"));
            }

            CreditProfile profile = _context.CreditProfile
                                    .Where(x => x.CustomerId == id && x.Id == profileId)
                                    .SingleOrDefault();

            return(profile == null
                ? (ActionResult)NotFound("Account not found")
                : Ok(_mapper.Map <GetCreditProfileResponse>(profile)));
        }