Exemple #1
0
        /// <summary>
        /// Handling save request and response
        /// </summary>
        /// <param name="request">Messaging.MovieRatings.SaveMovieRatingRequest</param>
        /// <returns>Messaging.MovieRatings.SaveMovieRatingResponse</returns>
        SaveMovieRatingResponse IMovieRatingService.SaveMovieRating(SaveMovieRatingRequest request)
        {
            var response = new SaveMovieRatingResponse()
            {
                Request       = request,
                ResponseToken = Guid.NewGuid()
            };

            try
            {
                if (request.MovieRating?.MovieId == 0)
                {
                    response.MovieRating         = request.MovieRating;
                    response.MovieRating.MovieId = _repository.Add(request.MovieRating.MapToModel());
                    response.Success             = true;
                }
                else if (request.MovieRating?.MovieId > 0)
                {
                    response.MovieRating = _repository.Save(request.MovieRating.MapToModel()).MapToView();
                    response.Success     = true;
                }
                else
                {
                    response.Success = false;
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Success = false;
            }
            return(response);
        }
Exemple #2
0
        public async Task <ActionResult <MovieRatingViewModel> > PostMovieRating(MovieRatingViewModel viewModel)
        {
            try
            {
                var entity = GetMapperMovieRatingViewModelToMovieRating(viewModel);
                var model  = await _movieRatingRepository.Add(entity);

                return(GetMapperMovieRatingToMovieRatingViewModel(model));
            }
            catch (InvalidDataException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }