public IActionResult AddComment(int id)
        {
            try
            {
                var product = _productService.GetProduct(id);

                if (product == null)
                {
                    TempData["InfoMessage"] = AppStrings.ProductNotFoundMessage;
                    return(RedirectToAction(nameof(Index)));
                }

                var formModel = new ReviewFormModel
                {
                    Product = _mapper.Map <ProductViewModel>(product)
                };

                return(View("ReviewForm", formModel));
            }
            catch (Exception ex)
            {
                _logger.LogMessage(ex.Message);
                TempData["ErrorMessage"] = AppStrings.GenericErrorMsg;

                return(RedirectToAction(nameof(Details), new { id }));
            }
        }
        public IActionResult Review(ReviewFormModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.sales
            .Create(model.CarId, model.CustomerId, model.Discount);

            this.logs.Create(this.User.Identity.Name, MethodBase.GetCurrentMethod().Name, ModelType);

            return(this.RedirectToAction(nameof(this.All)));
        }
Example #3
0
        public IActionResult SubmitReview(int id, ReviewFormModel review)
        {
            Reviews review_obj = new Reviews {
                RoomId = id,
                Rate   = review.Rate,
                Text   = review.Text,
                UserId = 1
            };

            _db.Reviews.Add(review_obj);
            _db.SaveChanges();

            return(RedirectToAction("Room", "Hotels", new { id }));
        }
        public IActionResult CreateReview([FromBody] ReviewFormModel request)
        {
            var appointment = _context.Appointments.Find(request.AppointmentId);
            var review      = _mapper.Map <Review>(request);

            review.Appointment = appointment;
            if (_context.Reviews.Any(r => r.Appointment.Id == appointment.Id))
            {
                return(BadRequest());
            }
            _context.Reviews.Add(review);
            _context.SaveChanges();
            return(Ok());
        }
        public IActionResult SaveComment(int id, ReviewFormModel formModel)
        {
            try
            {
                var product = _productService.GetProduct(id);

                if (product == null)
                {
                    TempData["InfoMessage"] = AppStrings.ProductNotFoundMessage;
                    return(RedirectToAction(nameof(Index)));
                }

                var _validator = new ReviewValidator();
                var results    = _validator.Validate(formModel);

                if (results.Errors.Any())
                {
                    foreach (var error in results.Errors)
                    {
                        ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                    }
                }

                if (ModelState.IsValid)
                {
                    _productService.SaveReview(_mapper.Map <ProductReview>(formModel));

                    TempData["SuccessMessage"] = AppStrings.ReviewEditSuccessMsg;
                    return(RedirectToAction(nameof(Details), new { id }));
                }

                formModel.Product = _mapper.Map <ProductViewModel>(product);
                return(View("ReviewForm", formModel));
            }
            catch (Exception ex)
            {
                _logger.LogMessage(ex.Message);
                TempData["ErrorMessage"] = AppStrings.GenericErrorMsg;

                return(RedirectToAction(nameof(Details), new { id }));
            }
        }
Example #6
0
        public IActionResult Edit(int id, ReviewFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            bool success = this.reviews.Edit(id, model.Description);

            if (!success)
            {
                this.GenerateAlertMessage(string.Format(WebConstants.Message.NonExistingEntity, WebConstants.Entity.Review, id), Alert.Warning);

                return(RedirectToHome());
            }

            this.GenerateAlertMessage(string.Format(WebConstants.Message.EntityEdited, WebConstants.Entity.Review), Alert.Success);

            return(RedirectToAction(WebConstants.Action.Details, WebConstants.Controller.Companies, new { id = model.CompanyId }));
        }
Example #7
0
        public virtual ActionResult Submit(ReviewFormModel formModel)
        {
            Session["movieId"] = formModel.Id;

            if (ModelState.IsValid)
            {
                var reviewData = new Review
                {
                    MovieId         = Session["movieId"].ToString(),
                    Name            = formModel.Author,
                    Text            = formModel.Text,
                    Rating          = Convert.ToDouble(formModel.Rating) == 0 ? 1 : Convert.ToDouble(formModel.Rating),
                    PublicationDate = DateTime.Now
                };

                _dataStoreRepository.Save(reviewData);

                AddToSession(formModel.Id);
            }

            return(RedirectToAction(nameof(Index), new { id = formModel.Id }));
        }
Example #8
0
        public async Task <ActionResult> Create([FromBody] ReviewFormModel model, string authorFullName, string bookTitle)
        {
            var entity = Mapper.Map <Review>(model);

            entity.User = Users.GetUserWithBorrows(User.Identity.Name);
            entity.Book = Books.GetBook(authorFullName, bookTitle);

            var isBorrowed = entity.User.Borrows.FirstOrDefault(b => b.Book.Title == bookTitle && b.Book.AuthorFullName == authorFullName);

            if (isBorrowed == null)
            {
                return(Forbid());
            }

            if (Reviews.IsReviewed(entity.Book.AuthorFullName, entity.Book.Title, entity.User.UserID))
            {
                return(Conflict());
            }

            Reviews.Create(entity);

            return(CreatedAtAction(nameof(Fetch), new { id = entity.ReviewId }, Mapper.Map <ReviewViewModel>(entity)));
        }
Example #9
0
        public IActionResult Add(ReviewFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (!this.companies.Exists(model.CompanyId))
            {
                this.GenerateAlertMessage(WebConstants.Message.InvalidCompany, Alert.Danger);

                return(RedirectToAction(WebConstants.Action.Index, WebConstants.Controller.Home));
            }

            var userId = this.userManager.GetUserId(User);

            if (model.CompanyId == userId)
            {
                this.GenerateAlertMessage(WebConstants.Message.OwnerAddReview, Alert.Warning);

                return(RedirectToAction(WebConstants.Action.Details, WebConstants.Controller.Companies, new { id = model.CompanyId }));
            }

            bool success = this.reviews.Add(model.CompanyId, userId, model.Description);

            if (!success)
            {
                this.GenerateAlertMessage(WebConstants.Message.UnableToAddReview, Alert.Warning);

                return(RedirectToAction(WebConstants.Action.Details, WebConstants.Controller.Companies, new { id = model.CompanyId }));
            }

            this.GenerateAlertMessage(string.Format(WebConstants.Message.EntityCreated, WebConstants.Entity.Review), Alert.Success);

            return(RedirectToAction(WebConstants.Action.Details, WebConstants.Controller.Companies, new { id = model.CompanyId }));
        }