Beispiel #1
0
        public IActionResult Put(int id, [FromBody] ReviewUpdateDTO DTO)
        {
            if (DTO == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = _rep.Get <Review>(id);

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

            Mapper.Map(DTO, entity);

            if (!_rep.Save())
            {
                return(StatusCode(500,
                                  "A Problem Happend while handling your request."));
            }
            return(NoContent());
        }
        public async Task <ActionResult> UpdateReviewById(int id, ReviewUpdateDTO reviewUpdateDTO)
        {
            try
            {
                var review = await _db.Reviews.GetById(id);

                if (review == null)
                {
                    _logger.LogError($"PUT api/reviews/{id} - Not Found");
                    return(NotFound());
                }

                var eduMatID   = reviewUpdateDTO.EduMaterialNavPointID;
                var eduMatById = await _db.EduMaterialNavPoints.GetById(eduMatID);

                if (eduMatById == null)
                {
                    _logger.LogError($"PUT api/reviews - Bad Request - EduMaterialNavPoint with id:{eduMatID} doesn't exists");
                    return(BadRequest($"Error - EduMaterialNavPoint with id:{eduMatID} doesn't exists"));
                }

                _mapper.Map(reviewUpdateDTO, review);
                await _db.Reviews.Update(review);

                await _db.Save();

                _logger.LogInformation($"PUT api/reviews/{id} - No Content - Review updated");
                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.LogError("GET api/authors - Problem with Database");
                return(StatusCode(500, "Internal Server Error. Cannot connect wiht Database!"));
            }
        }
Beispiel #3
0
 public async Task <IActionResult> UpdateReviewById(long reviewId, ReviewUpdateDTO review)
 {
     try
     {
         return(Ok(await _gamesRepository.UpdateReviewById(review, reviewId, Convert.ToInt64(User.Identity.Name))));
     }
     catch (MethodAccessException) {
         return(Forbid());
     }
     catch (Exception e) {
         return(NotFound(e.Message));
     }
 }
        public async Task <Review> UpdateReviewById(ReviewUpdateDTO updatedReview, long id, long userId)
        {
            var review = await GetReviewById(id);

            if (userId != review.User.UserId)
            {
                throw new MethodAccessException("Method not allowed");
            }
            review.Title       = updatedReview.Title;
            review.Description = updatedReview.Description;
            review.Rating      = updatedReview.Rating;
            var result = _context.Reviews.Update(review);
            await _context.SaveChangesAsync();

            return(result.Entity);
        }