public async Task <DistraintExemptModel> ExemptAsync(DistraintExemptModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException("DistraintExemptModel is null");
            }

            var distraint = await _context.Distraint
                            .Where(x => x.Id == model.Id)
                            .FirstOrDefaultAsync();

            if (distraint == null)
            {
                throw new Exception("Distraint to be exempted was not found");
            }

            if (distraint.StatusCode.ToUpper() != Shared.Enums.DistraintStatus.ENFORCED.ToString())
            {
                throw new Exception("Distraint is not in valid status to be exempted");
            }

            model.ExemptedAt = DateTime.SpecifyKind(DateTime.Now.ToUniversalTime(), DateTimeKind.Utc);

            distraint.StatusCode    = Shared.Enums.DistraintStatus.EXEMPTED.ToString();
            distraint.ExemptionDate = model.ExemptionDate.HasValue == true?DateTime.SpecifyKind(model.ExemptionDate.Value.ToUniversalTime(), DateTimeKind.Utc) : DateTime.UtcNow;

            distraint.ExemptedAt = model.ExemptedAt;
            distraint.ExemptedBy = model.ExemptedBy;

            _context.Distraint.Update(distraint);
            await _context.SaveChangesAsync();

            return(model);
        }
示例#2
0
        public async Task <IActionResult> Exempt([FromBody] DistraintExemptModel model)
        {
            if (!ModelState.IsValid)
            {
                string msg = $"{_localizer.GetString("Invalid DistraintExemptModel").Value}!<br />{ModelState.GetErrors()}";
                Log.Information($"DistraintController/Exempt/{CurrentUserId}/{CurrentUserUsername} - {msg}");
                return(BadRequest(msg));
            }

            try
            {
                var distraint = await _distraintService.ExemptAsync(model);

                string msg = $"{_localizer.GetString("Distraint exempted successfully").Value}! (Id: {distraint.Id})";
                Log.Information($"DistraintController/Exempt/{CurrentUserId}/{CurrentUserUsername} - {msg}");
                return(Ok(distraint.Id));
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"ERROR exempting distraint by user {CurrentUserId}/{CurrentUserUsername}");
                return(BadRequest("Error exempting distraint"));
            }
        }