Example #1
0
        public void UpdateReview(Guid bookId, Guid reviewId, UpdateReviewModel model)
        {
            var child = BookFromAuthor(bookId).Reviews.Single(review => review.Id == reviewId);

            child.Comment      = model.Comment;
            child.Rating       = model.Rating;
            child.ReviewerName = model.ReviewerName;
        }
Example #2
0
        private async Task <IActionResult> UpdateIn(string objCode, UpdateReviewModel model)
        {
            if (!await HasObject(objCode, model.PlaceId))
            {
                return(BadRequest("No such place"));
            }

            if (model.Id <= 0)
            {
                return(BadRequest("invalid model"));
            }

            var exists =
                await Service.Get(model.Id);


            if (this.GetUserRole() == "admin")
            {
                if (this.GetUserId() != exists.UserId)
                {
                    var res =
                        await Service.Update(model.Id, model.Text != null, model.Text, null, model.IsVisible);

                    return(Ok(res));
                }
                else
                {
                    var res =
                        await Service.Update(model.Id, model.Text != null, model.Text, model.Rate, model.IsVisible);

                    if (model.Rate != null)
                    {
                        await RecalculateRating(objCode, model.PlaceId);
                    }

                    return(Ok(res));
                }
            }
            else
            {
                if (this.GetUserId() != exists.UserId)
                {
                    return(BadRequest());
                }

                var res =
                    await Service.Update(model.Id, model.Text != null, model.Text, model.Rate, null);

                if (model.Rate != null)
                {
                    await RecalculateRating(objCode, model.PlaceId);
                }

                return(Ok(res));
            }
        }
Example #3
0
 public Task <IActionResult> UpdateToEvent([FromBody] UpdateReviewModel model)
 => UpdateIn(PlaceTypesConfig.EventCode, model);
Example #4
0
 public Task <IActionResult> UpdateToRoute([FromBody] UpdateReviewModel model)
 => UpdateIn(PlaceTypesConfig.RouteCode, model);
Example #5
0
 public Task <IActionResult> UpdateToAttraction([FromBody] UpdateReviewModel model)
 => UpdateIn(PlaceTypesConfig.AttractionCode, model);
Example #6
0
 public Task <IActionResult> UpdateToHotel([FromBody] UpdateReviewModel model)
 => UpdateIn(PlaceTypesConfig.HotelCode, model);
 public IActionResult Update(Guid bookId, Guid reviewId, [FromBody] UpdateReviewModel model)
 {
     ReviewService.UpdateReview(bookId, reviewId, model);
     return(Ok());
 }