Ejemplo n.º 1
0
        public ValidationResult ValidateResource(EditRatingDTO editRatingDTO)
        {
            var result = new ValidationResult();

            if (editRatingDTO != null)
            {
                var validator = new RatingValidator();
                var vr        = validator.Validate(editRatingDTO);
                if (vr.IsValid)
                {
                    result.IsValid = true;
                    return(result);
                }

                if (vr.Errors.Any())
                {
                    foreach (var error in vr.Errors)
                    {
                        result.ErrorMessages.Add(error.PropertyName, error.ErrorMessage);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        // edit
        public void Update(int Id, EditRatingDTO editRatingDTO)
        {
            var updateRating = _ratingRepository.FindById(Id);

            if (updateRating != null && editRatingDTO != null)
            {
                _ratingRepository.Update(Id, _mapper.Map(editRatingDTO, updateRating));
            }
        }
        public async Task <IActionResult> EditRating([FromBody] EditRatingDTO rating, [FromRoute] string ratingId)
        {
            var result = await _ratingsServices.EditRating(rating, ratingId);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Ejemplo n.º 4
0
        // add
        public RatingDTO Add(EditRatingDTO editRatingDTO)
        {
            if (editRatingDTO == null)
            {
                throw new ArgumentException();
            }

            var currentRating = _mapper.Map <Rating>(editRatingDTO);

            try
            {
                _ratingRepository.Insert(currentRating);
            }
            catch (Exception)
            {
                throw;
            }
            return(_mapper.Map <RatingDTO>(currentRating));
        }
        public void Update(int ratingId, [FromBody] EditRatingDTO ratingDTO)
        {
            try
            {
                var result = _ratingService.ValidateResource(ratingDTO);
                if (!result.IsValid)
                {
                }

                if (result.IsValid)
                {
                    _ratingService.Update(ratingId, ratingDTO);
                }
            }
            catch (Exception)
            {
                // Implement logging MS
                //throw StatusCode(500, "Internal server error");
            }
        }
Ejemplo n.º 6
0
        public async Task <Response <EditRatingDTO> > EditRating(EditRatingDTO model, string ratingId)
        {
            var response = new Response <EditRatingDTO>();
            var rating   = _ratingsRepo.GetById(ratingId).Result;

            if (rating != null)
            {
                rating.Rating = model.Rating;
                if (await _ratingsRepo.Modify(rating))
                {
                    response.Success = true;
                    response.Data    = new EditRatingDTO {
                        Rating = rating.Rating
                    };
                    response.Message = "Rating updated successfully";
                    return(response);
                }
            }
            response.Success = false;
            response.Message = "Rating not found";
            return(response);
        }