Ejemplo n.º 1
0
        public static void Create(PlacePhotoDTO placePhotoDTO)
        {
            PlacePhoto placePhoto = MapperTransform <PlacePhoto, PlacePhotoDTO> .ToEntity(placePhotoDTO);

            Database.PlacePhotos.Create(placePhoto);
            Database.Save();
        }
Ejemplo n.º 2
0
        public static void Update(PlacePhotoDTO placePhotoDTO)
        {
            PlacePhoto placePhoto = Database.PlacePhotos.Get(placePhotoDTO.Id);

            placePhoto.SRC  = placePhotoDTO.SRC;
            placePhoto.Main = placePhotoDTO.Main;
            Database.PlacePhotos.Update(placePhoto);
            Database.Save();
        }
Ejemplo n.º 3
0
        // Users can only submit local files.
        public async Task <IActionResult> Create(UploadPhotoViewModel model) // This implementation because this is form file uploading.
        {
            if (model.PlaceId == -1 || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var place = context.Places.FirstOrDefault(p => p.Id == model.PlaceId);

            if (place == null)
            {
                return(NotFound());
            }
            if (place.PlacePhotos == null)
            {
                place.PlacePhotos = new List <PlacePhoto>();
            }
            var photo = new PlacePhoto {
                Place = place,
                IsGooglePlacesImage = false,
                FileName            = model.File.FileName
            };

            context.PlacePhotos.Add(photo);
            context.SaveChanges();
            var fileExt = model.File.ContentType.Split('/').Last();

            try {
                await S3Client.PutObjectAsync(new PutObjectRequest {
                    BucketName  = bucketName,
                    Key         = $"{photo.Id}-{model.File.FileName}",
                    InputStream = model.File.OpenReadStream()
                });
            } catch (Exception e) {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
            place.PlacePhotos.Add(photo);
            context.Places.Update(place);
            context.SaveChanges();
            return(Ok());
        }
 public static async Task <PlacePhotoResponse> GetAsync(this PlacePhoto request)
 => await request.GetAsync <PlacePhotoResponse>(request.ToString());
Ejemplo n.º 5
0
        public static PlacePhotoDTO Get(int id)
        {
            PlacePhoto placePhoto = Database.PlacePhotos.Get(id);

            return(MapperTransform <PlacePhoto, PlacePhotoDTO> .ToModel(placePhoto));
        }