예제 #1
0
        public async Task <IActionResult> Update(int id, [FromBody] CreateUpdateRefund update)
        {
            if (!ModelState.IsValid)
            {
                return(new BadRequestObjectResult(new ErrorsResponse(ModelState)));
            }

            var username = User.FindFirst(c => c.Type == JwtRegisteredClaimNames.Sub).Value;
            var refund   = new Refund
            {
                Id             = id,
                Amount         = update.Amount,
                CheckNumber    = update.CheckNumber,
                Date           = update.Date,
                Username       = username,
                SchoolYear     = update.SchoolYear,
                SchoolDistrict = _districts.GetByAun(update.SchoolDistrictAun),
            };

            try
            {
                await Task.Run(() => _context.SaveChanges(() => _refunds.Update(refund)));

                return(Ok());
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
        }