public async Task <IActionResult> Post([FromBody] RejectionNoticeDTO dto, [FromRoute] Guid liveryId) { var livery = await _context.Liveries .Include(l => l.User) .Include(l => l.Series) .FirstOrDefaultAsync(l => l.Id == liveryId); if (livery == null) { return(NotFound($"Could not find livery with id {dto.LiveryId}")); } if (livery.IsRejected) { return(BadRequest("Livery is already in the rejected state")); } var rejections = _context.Rejections .Count(s => s.LiveryId == dto.LiveryId && s.Status == RejectionStatus.Rejected); if (rejections > 0) { return(BadRequest("Livery has existing rejections but is not marked as rejected. Contact Support")); } var obj = new RejectionNotice() { LiveryId = liveryId, Livery = livery, Message = dto.Message, Status = RejectionStatus.Rejected }; await _context.Rejections.AddAsync(obj); livery.IsRejected = true; await _context.SaveChangesAsync(); if (livery.User.IsAgreedToEmails) { try { await _sesService.SendRejectionEmail(livery); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } } return(Ok(new RejectionNoticeDTO(obj))); }
public RejectionNoticeDTO(RejectionNotice notice) { this.Id = notice.Id; this.LiveryId = notice.LiveryId; this.Status = notice.Status; this.Message = notice.Message; if (notice.Livery != null) { this.Type = notice.Livery.LiveryType.ToString(); this.SeriesId = notice.Livery.SeriesId; if (notice.Livery.Series != null) { this.SeriesName = notice.Livery.Series.Name; } } }