Exemplo n.º 1
0
        public async Task <IHttpActionResult> Review(ReviewViewModels viewModels)
        {
            try
            {
                int userId = (await CurrentUser()).Id;
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                List <Photo> photos = new List <Photo>();
                foreach (var item in viewModels.Photos ?? new List <string>())
                {
                    var photo = new Photo
                    {
                        UserId = userId,
                        Path   = item
                    };
                    await _photoService.Create2(photo);

                    photos.Add(photo);
                }
                _locationService.AddReview(new Review
                {
                    CreatorId   = userId,
                    Title       = viewModels.Title,
                    Description = viewModels.Description,
                    LocationId  = viewModels.LocationId,
                    Rating      = viewModels.Rating,
                    Photos      = photos
                });

                return(Ok());
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(Review), ex);

                return(InternalServerError(ex));
            }
        }