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 async Task <IActionResult> Put([FromRoute] Guid liveryId, [FromBody] RejectionNoticeDTO dto)
        {
            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 {liveryId}"));
            }
            if (!livery.IsRejected)
            {
                return(BadRequest("Livery is not in the rejected state"));
            }
            var rejections = await _context.Rejections
                             .FirstOrDefaultAsync(s => s.LiveryId == liveryId && s.Status != RejectionStatus.Rejected);

            if (rejections == null)
            {
                return(BadRequest("Unable to find record of rejection for livery. Contact Support"));
            }
            livery.IsRejected = dto.Status != RejectionStatus.Resolved;
            rejections.Status = dto.Status;
            await _context.SaveChangesAsync();

            if (livery.User.IsAgreedToEmails)
            {
                try
                {
                    if (livery.IsRejected)
                    {
                        await _sesService.SendRejectionEmail(livery);
                    }
                    else
                    {
                        await _sesService.SendApprovalEmail(livery);
                    }
                }
                catch (Exception ex)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }

            return(Ok());
        }