public RatingTypeDTO CreateRatingType(RatingTypeCreationDTO ratingType)
        {
            RatingType type = mapper.Map <RatingType>(ratingType);

            try
            {
                var createdType = _ratingTypeRepository.CreateRatingType(type);
                _ratingTypeRepository.SaveChanges();
                return(mapper.Map <RatingTypeDTO>(createdType));
            }
            catch (Exception ex)
            {
                throw new ErrorOccurException(ex.Message);
            }
        }
Beispiel #2
0
        public ActionResult <RatingTypeDTO> CreateRatingType([FromHeader] string key, [FromBody] RatingTypeCreationDTO type)
        {
            if (!_authService.Authorize(key))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!"));
            }

            try
            {
                var createdType = _ratingTypeService.CreateRatingType(type);

                string location = linkGenerator.GetPathByAction("GetRatingTypeByID", "RatingType", new { ratingTypeID = createdType.RatingTypeID });

                return(Created(location, createdType));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Error creating new type of raiting: " + ex.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, "Error creating new type of rating!"));
            }
        }