Esempio n. 1
0
 public async Task <LuminaryResponse> ToLuminaryResponse(Luminary luminary)
 {
     return(new LuminaryResponse
     {
         Address = luminary.Address,
         BasePhoto = luminary.BasePhoto,
         TopPhoto = luminary.TopPhoto,
         FullPhoto = luminary.FullPhoto,
         Date = luminary.Date,
         Id = luminary.Id,
         Remarks = luminary.Remarks,
         User = ToUserResponse(await _context.Users.FindAsync(luminary.User.Id)),
         Latitude = luminary.Latitude,
         Longitude = luminary.Longitude,
         Tipo = luminary.Type,
     });
 }
Esempio n. 2
0
        public async Task <IActionResult> PostLuminary([FromBody] LuminaryRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Foto1
            var imageUrl1 = string.Empty;

            if (request.BasePhotoArray != null && request.BasePhotoArray.Length > 0)
            {
                var stream   = new MemoryStream(request.BasePhotoArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "wwwroot\\images\\Luminaries";
                var fullPath = $"~/images/Luminaries/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    imageUrl1 = fullPath;
                }
            }
            //Foto2
            var imageUrl2 = string.Empty;

            if (request.TopPhotoArray != null && request.TopPhotoArray.Length > 0)
            {
                var stream   = new MemoryStream(request.TopPhotoArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "wwwroot\\images\\Luminaries";
                var fullPath = $"~/images/Luminaries/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    imageUrl2 = fullPath;
                }
            }
            //Foto3
            var imageUrl3 = string.Empty;

            if (request.FullPhotoArray != null && request.FullPhotoArray.Length > 0)
            {
                var stream   = new MemoryStream(request.FullPhotoArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "wwwroot\\images\\Luminaries";
                var fullPath = $"~/images/Luminaries/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    imageUrl3 = fullPath;
                }
            }

            User User2 = await _context.Users
                         .Include(n => n.Neighborhood)
                         .FirstOrDefaultAsync(o => o.Id == request.UserId);


            var luminary = new Luminary
            {
                Date         = request.Date,
                Id           = request.Id,
                Address      = request.Address,
                BasePhoto    = imageUrl1,
                TopPhoto     = imageUrl2,
                FullPhoto    = imageUrl3,
                Type         = request.Tipo,
                Remarks      = request.Remarks,
                User         = User2,
                Latitude     = request.Latitude,
                Longitude    = request.Longitude,
                Neighborhood = User2.Neighborhood,
                State        = request.State,
            };

            _context.Luminaries.Add(luminary);
            await _context.SaveChangesAsync();

            return(Ok(_converterHelper.ToLuminaryResponse(luminary)));
            //return NoContent();
        }