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)));
        }
示例#2
0
        public async Task <IActionResult> PutUser(ApplicationUser userBody)
        {
            try
            {
                var user = await _context.Users
                           .Include(u => u.Invite).FirstOrDefaultAsync(u => u.UserName == User.Identity.Name);

                if (user == null)
                {
                    return(Unauthorized());
                }

                user.IsAgreedToEmails = userBody.IsAgreedToEmails;
                user.LastUpdated      = DateTime.UtcNow;

                await _context.SaveChangesAsync();

                await _sesService.SendUpdateEmailSettingsNotification(user);

                return(Ok(new UserDTO(user)));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
示例#3
0
        public async Task <IActionResult> FinalizeLivery([FromRoute] Guid id)
        {
            var livery = _context.Liveries.Include(l => l.Car)
                         .Include(l => l.User)
                         .Include(l => l.Series)
                         .FirstOrDefault(l => l.Id == id);

            if (livery == null)
            {
                return(NotFound($"Unable to find livery with id {id}"));
            }
            if (livery.Status != UploadStatus.WAITING)
            {
                return(BadRequest("Livery is not in Waiting status"));
            }

            if (livery.LiveryType != LiveryType.SpecMap)
            {
                var outputStream = new MemoryStream();
                try
                {
                    var watch = new Stopwatch();
                    _logger.Log(LogLevel.Debug, "Beginning tga to img conversion");
                    watch.Start();

                    var tgaStream = await _s3Service.GetTgaStreamFromLivery(livery);

                    tgaStream.Position = 0;
                    using (var image = Image.Load(tgaStream))
                    {
                        image.SaveAsJpeg(outputStream, new JpegEncoder()
                        {
                            Quality = 80
                        });
                    }
                    _logger.Log(LogLevel.Debug, $"Elapsed Time after converting to jpeg: {watch.ElapsedMilliseconds}");
                    outputStream.Position = 0;
                    _logger.Log(LogLevel.Debug, $"Elapsed Time after resetting stream: {watch.ElapsedMilliseconds}");
                } catch (Exception)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError,
                                      "An error occured converting the tga to a thumbnail. Please contact Support for assistance."));
                }
                try
                {
                    await _s3Service.UploadPreview(livery, outputStream);
                }
                catch (Exception)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError,
                                      "An error occured uploading the thumbnail. Please contact Support for assistance."));
                }
            }
            livery.Status      = UploadStatus.UPLOADED;
            livery.LastUpdated = DateTime.UtcNow;
            await _context.SaveChangesAsync();

            return(Ok(new LiveryDTO(livery, _s3Service.GetPreview(livery))));
        }