Exemplo n.º 1
0
        public IActionResult CreateReview(CreateReviewModel reviewModel)
        {
            Review review = reviewModel.Review;

            _reviewRepo.Save(review);
            return(RedirectToAction("details", "Products", new { id = reviewModel.Review.ProductId }));
        }
Exemplo n.º 2
0
        public IActionResult CreateReview(string id)
        {
            if (id != null && id.Length > 0)
            {
                Guid result = Guid.Empty;
                var  model  = new CreateReviewModel();

                if (Guid.TryParse(id, out result))
                {
                    var productEntity = _productService.GetProductById(result);
                    model.ProductId   = productEntity.Id;
                    model.ProductName = productEntity.Name;
                    model.ProductSeo  = productEntity.SeoUrl;
                    model.Rating      = 1;

                    var userReview = _reviewService.GetReviewByProductIdUserId(result, GetCurrentUserId());
                    if (userReview != null)
                    {
                        model.Title              = userReview.Title;
                        model.Message            = userReview.Message;
                        model.Rating             = userReview.Rating;
                        ViewData["ReviewEdited"] = true;
                    }
                }

                return(View(model));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public async Task AddReviewToOffer(CreateReviewModel inputModel)
        {
            var offer = await this.context.Offers.FirstOrDefaultAsync(x => x.Id == inputModel.Id);

            if (offer == null)
            {
                return;
            }

            var userComments = this.GetOfferCommentsAsync(inputModel.Id).Result.Where(x => x.CreatorId == inputModel.CreatorId).ToList();

            var comment = new Comment()
            {
                Description = inputModel.Review,
                OfferId     = inputModel.Id,
                CreatorId   = inputModel.CreatorId,
            };

            var rated = await this.offerService.IsOfferRatedAsync(offer.Id, inputModel.CreatorId);

            int?offerRatedByUser = 0;

            offerRatedByUser = await this.offerService.GetRateForOffer(offer.Id, inputModel.CreatorId);

            if (userComments.Any())
            {
                var offerUserRate = await this.context.OfferUserRates
                                    .FirstOrDefaultAsync(x => x.UserId == inputModel.CreatorId && x.OfferId == inputModel.Id);

                offerUserRate.Rate = int.Parse(inputModel.Rating);
            }

            OfferUserRate offerRate = null;

            if (offerRatedByUser == 0)
            {
                offerRate = new OfferUserRate()
                {
                    OfferId = offer.Id,
                    UserId  = inputModel.CreatorId,
                    Rate    = int.Parse(inputModel.Rating),
                };

                if (offerRatedByUser == 0)
                {
                    this.context.OfferUserRates.Add(offerRate);
                }
            }

            if (comment.Description != null)
            {
                offer.Comments.Add(comment);
            }

            await this.context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public ActionResult Create()
        {
            var pl    = publishingService.GetPublishings();
            var model = new CreateReviewModel()
            {
                PublishingList = mapper.Map <IEnumerable <PublishingModel> >(pl),
                ReviwerId      = GetUserId()
            };

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddReview(CreateReviewModel commentInputModel, string id) // index post requsest for create
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect($"/Offer/Edit?id={id}"));
            }

            commentInputModel.CreatorId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            commentInputModel.Id        = id;

            await this.commentService.AddReviewToOffer(commentInputModel);

            return(this.Redirect($"/Offer/Details?id={commentInputModel.Id}"));
        }
Exemplo n.º 6
0
        public ActionResult Create(CreateReviewModel createReview)
        {
            if (ModelState.IsValid)
            {
                var createReviewCommand = new CreateReviewCommand(createReview.ServiceId, UserInfo.Id, createReview.Score, createReview.Body);
                ExecuteCommand(createReviewCommand);

                var updateScreeningsCommand = new UpdateScreeningsCommand(createReview.ServiceId);
                ExecuteNonBlockingCommand(updateScreeningsCommand);

                TempData[ViewDataKeys.Message] = new SuccessMessage(Resources.Reviewed);
            }

            return RedirectToAction("Profile", "Accounts");
        }
Exemplo n.º 7
0
        public ActionResult Create(CreateReviewModel createReview)
        {
            if (ModelState.IsValid)
            {
                var createReviewCommand = new CreateReviewCommand(createReview.ServiceId, UserInfo.Id, createReview.Score, createReview.Body);
                ExecuteCommand(createReviewCommand);

                var updateScreeningsCommand = new UpdateScreeningsCommand(createReview.ServiceId);
                ExecuteNonBlockingCommand(updateScreeningsCommand);

                TempData[ViewDataKeys.Message] = new SuccessMessage(Resources.Reviewed);
            }

            return(RedirectToAction("Profile", "Accounts"));
        }
Exemplo n.º 8
0
        public Guid CreateReview(Guid bookId, CreateReviewModel model)
        {
            Book books = BookFromAuthor(bookId);


            var newReview = new Review
            {
                Comment      = model.Comment,
                Rating       = model.Rating,
                ReviewerName = model.ReviewerName
            };

            books.Reviews.Add(newReview);
            return(newReview.Id);
        }
        public IActionResult Post(int foodTruckId, [FromBody] CreateReviewModel createModel)
        {
            var createCommand = new CreateReviewCommand()
            {
                FoodTruckId = foodTruckId
            };

            this.mapper.Map <CreateReviewModel, CreateReviewCommand>(createModel, createCommand);

            Review foodTruck = this.foodTruckService.CreateFoodTruckReview(createCommand);

            var model = this.mapper.Map <Review, ReviewModel>(foodTruck);

            return(this.CreatedAtRoute(GET_SINGLE_FOOD_TRUCK_REVIEW,
                                       new { FoodTruckId = model.FoodTruckId, ReviewId = model.ReviewId }, model));
        }
Exemplo n.º 10
0
        public IActionResult CreateReview(int id)
        {
            Product product = GetProductById(id);

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                CreateReviewModel reviewModel = new CreateReviewModel();
                reviewModel.Product = product;
                reviewModel.Review  = new Review();
                return(View(reviewModel));
            }
        }
Exemplo n.º 11
0
        public async Task <ActionResult> OnPostCreateReviewAsync(CreateReviewModel model)
        {
            var user = await _authenticationService.GetCurrentUserAsync();

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

            if (ModelState.IsValid)
            {
                await _filmsService.CreateReview(model.Title, model.Body, model.FilmId, user.Id);
            }

            return(RedirectToPage(new
            {
                id = model.FilmId
            }));
        }
Exemplo n.º 12
0
        public IActionResult EditReview(CreateReviewModel model)
        {
            if (ModelState.IsValid)
            {
                var reviewEntity = _reviewService.GetReviewByProductIdUserId(model.ProductId, GetCurrentUserId());
                if (reviewEntity != null)
                {
                    reviewEntity.Title        = model.Title;
                    reviewEntity.Message      = model.Message;
                    reviewEntity.Rating       = model.Rating;
                    reviewEntity.DateModified = DateTime.Now;

                    _reviewService.UpdateReview(reviewEntity);
                }

                return(RedirectToAction("ProductInfo", "Home", new { seo = model.ProductSeo }, "Reviews"));
            }

            return(View(model));
        }
Exemplo n.º 13
0
        public IActionResult EditReview(CreateReviewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var reviewEntity = _reviewService.GetReviewByProductIdUserId(model.ProductId, GetCurrentUserId());

            if (reviewEntity != null)
            {
                reviewEntity.Title        = model.Title;
                reviewEntity.Message      = model.Message;
                reviewEntity.Rating       = model.Rating;
                reviewEntity.DateModified = DateTime.Now;

                _reviewService.UpdateReview(reviewEntity);
            }

            return(new RedirectResult("/Product/" + model.ProductSeo + "#!#reviews"));
        }
Exemplo n.º 14
0
        public IActionResult CreateReview(CreateReviewModel model)
        {
            if (ModelState.IsValid)
            {
                var reviewEntity = new Review
                {
                    Id        = Guid.NewGuid(),
                    UserId    = GetCurrentUserId(),
                    ProductId = model.ProductId,
                    Title     = model.Title,
                    Message   = model.Message,
                    Rating    = model.Rating,
                    CreatedOn = DateTime.Now
                };

                _reviewService.InsertReview(reviewEntity);

                return(RedirectToAction("ProductInfo", "Home", new { seo = model.ProductSeo }, "Reviews"));
            }

            return(View(model));
        }
Exemplo n.º 15
0
        public IActionResult CreateReview(CreateReviewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var reviewEntity = new Review
            {
                Id        = Guid.NewGuid(),
                UserId    = GetCurrentUserId(),
                ProductId = model.ProductId,
                Title     = model.Title,
                Message   = model.Message,
                Rating    = model.Rating,
                CreatedOn = DateTime.Now
            };

            _reviewService.InsertReview(reviewEntity);

            return(new RedirectResult("/Product/" + model.ProductSeo + "#!#reviews"));
        }
Exemplo n.º 16
0
        public IActionResult Create(CreateReviewModel createReviewModel)
        {
            _createReviewCommand.Execute(createReviewModel);

            return(StatusCode(StatusCodes.Status201Created));
        }
Exemplo n.º 17
0
        public IActionResult Create(Guid bookId, [FromBody] CreateReviewModel model)
        {
            var newlyCreated = ReviewService.CreateReview(bookId, model);

            return(CreatedAtRoute("GetReview", new { bookid = bookId, reviewid = newlyCreated }, newlyCreated));
        }
Exemplo n.º 18
0
        public IActionResult Create([FromForm] CreateReviewModel review)
        {
            string userId = User.Identity.Name;
            // does film exist
            var      films = _mongoDB.GetCollection <BsonDocument>("films");
            ObjectId filmId;

            if (!ObjectId.TryParse(review.FilmId, out filmId))
            {
                return(NotFound());
            }

            var filmBson = films.Find($"{{ _id: ObjectId('{filmId}') }}").FirstOrDefault();

            if (filmBson == null)
            {
                return(NotFound());
            }

            var film = BsonSerializer.Deserialize <Film>(filmBson);

            //does review for film from user already exist
            var reviews = _mongoDB.GetCollection <BsonDocument>("reviews");

            var exist = reviews.FindOneAndDelete($"{{FilmId: ObjectId('{filmId}'), UserId: ObjectId('{userId}')}}");

            if (exist != null)
            {
                var oldReview = BsonSerializer.Deserialize <ReviewModel>(exist);

                if (oldReview.IsPositive)
                {
                    films.UpdateOne($"{{_id: ObjectId('{film.Id}')}}", "{$inc: { Positive: -1}}");
                }
                else
                {
                    films.UpdateOne($"{{_id: ObjectId('{film.Id}')}}", "{$inc: { Negative: -1}}");
                }
            }

            ReviewModel toAdd = new ReviewModel()
            {
                Comment    = review.Comment,
                FilmId     = filmId,
                IsPositive = review.IsPositive,
                UserId     = ObjectId.Parse(userId),
                UserName   = User.FindFirst(x => x.Type == ClaimTypes.NameIdentifier).Value,
                Time       = DateTime.Now
            };

            if (toAdd.IsPositive)
            {
                films.UpdateOne($"{{_id: ObjectId('{film.Id}')}}", "{$inc: { Positive: 1}}");
            }
            else
            {
                films.UpdateOne($"{{_id: ObjectId('{film.Id}')}}", "{$inc: { Negative: 1}}");
            }

            reviews.InsertOne(toAdd.ToBsonDocument());
            return(Redirect("/film/detail/?id=" + review.FilmId));
        }