public void UpdateRatingType(RatingTypeModifyingDTO ratingType, int typeID)
        {
            var oldType = _ratingTypeRepository.GetRatingTypeByID(typeID);

            if (oldType == null)
            {
                throw new NotFoundException("There is no type of rating with that ID");
            }

            var newType = mapper.Map <RatingType>(ratingType);

            newType.RatingTypeID = typeID;

            try
            {
                mapper.Map(newType, oldType);
                _ratingTypeRepository.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new ErrorOccurException("Error updating type of rating: " + ex.Message);
            }
        }
示例#2
0
        public IActionResult UpdateRatingType([FromHeader] string key, [FromBody] RatingTypeModifyingDTO updatedType, int typeID)
        {
            if (!_authService.Authorize(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            var newType = mapper.Map <RatingType>(updatedType);

            try
            {
                _ratingTypeService.UpdateRatingType(updatedType, typeID);
                var res = mapper.Map <RatingType>(newType);
                res.RatingTypeID = typeID;

                return(Ok(res));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error updating type of rating: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }