Ejemplo n.º 1
0
        public async Task <ActionResult <Danhgia> > CreateReviewAsync(ReviewCreateDto review)
        {
            Danhgia reviewModel = _mapper.Map <Danhgia>(review);
            await _reviewService.CreateReviewAsync(reviewModel);

            return(CreatedAtRoute(nameof(GetReviewByIdAsync), new { id = reviewModel.MaDanhGia }, reviewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateReview([FromBody] NewReviewModel review)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var reviewCreated = await _reviewService.CreateReviewAsync(review.TermId, review.Grade, review.Description);

            return(CreatedAtAction("GetReview", new { id = reviewCreated.ReviewId }, review));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateReview(
            [FromForm] int userId,
            [FromForm] int productId,
            [FromForm] string userName,
            [FromForm] string reviewContent,
            [FromForm] int reviewRating)

        {
            await _reviewService.CreateReviewAsync(userId, productId, userName, reviewContent, reviewRating);

            return(Ok());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(CreateReviewViewModel reviewViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var userId = _userManager.GetUserId(HttpContext.User);
            await _reviewService.CreateReviewAsync(Guid.Parse(userId), reviewViewModel.ReviewText, reviewViewModel.GameName, reviewViewModel.GamePublisher, reviewViewModel.ReleaseYear, reviewViewModel.VideoReview);

            return(Redirect("~/Reviews"));
        }
        public async Task <IActionResult> AddReview([FromBody] CreateReviewRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Select(x => x.Value.Errors)
                                  .Where(x => x.Count > 0)
                                  .ToList()));
            }

            var review = await _reviewService.CreateReviewAsync(request);

            return(new OkObjectResult(review));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PostReview([FromBody] ReviewRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var postRequest = await _reviewService.CreateReviewAsync(request);

            if (postRequest.Entity == null)
            {
                return(BadRequest(postRequest.Message));
            }

            return(Ok(postRequest.Entity));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> CreateReview([FromBody] ReviewDto model)
        {
            var response = CreateSingleModelResponse();

            //*** check for model is valid or not if invalid returning bad request response
            if (model == null)
            {
                return(response.ToErrorResponse(ApiMessages.InvalidRequest, HttpStatusCode.BadRequest));
            }

            model.Guid     = Guid.NewGuid();
            model.IsActive = false;
            var entity = await _reviewService.CreateReviewAsync(model);

            response.Model   = entity;
            response.Message = entity.Id != 0 ? ApiMessages.SavedRecord : ApiMessages.SavedFailedRecord;
            return(response.ToHttpResponse());
            //return CreatedAtRoute("GetAll", new { id = response.Model.Id }, response.Model);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> ReviewBook(ReviewViewModel vm)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user.Id == null || vm.Id == null)
            {
                ViewBag.ErrorTitle   = $"You are tring to Review a book with invalid User state!";
                ViewBag.ErrorMessage = "User or review Id cannot be null!";
                return(View("Error"));
            }
            var sameBooks = await _bookService.GetAllSameBooks(vm.Id);

            if (await _reviewService.CheckIfUserCanReview(user.Id, vm.Id))
            {
                //var sameBooksVm = sameBooks.Select(b => b.MapToReviewViewModel(user.Id)).ToList();
                await _reviewService.CreateReviewAsync(user.Id, (decimal)vm.Grade, vm.Description, vm.Id);

                return(RedirectToAction("Index", "Book"));
            }

            return(BadRequest("You cannot review book you have already reviewed!"));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Post([FromBody] ReviewRequest reviewRequest)
        {
            try
            {
                // map request to domain object
                var newReview = reviewRequest.MapToReview();

                return((await _reviewService.CreateReviewAsync(newReview))
                       .Match <IActionResult>(
                           review =>
                {
                    var baseUrl = $"{Request.Scheme}://{Request.Host.ToUriComponent()}";
                    var locationUri = $"{baseUrl}{Request.Path}/{review.Id}";
                    return Created(locationUri, review.MapToReviewResponse());
                },
                           error => BadRequest(error)));
            }
            catch (InvalidUserRatingException ex)
            {
                return(BadRequest(ex.Message));
            }
        }