public IActionResult AddMovie(AddMovieRequestModel movie) { if (ModelState.IsValid) { _mediator.Send(movie); return(RedirectToAction("ViewAll")); } else { return(View(movie)); } }
public async Task <IActionResult> AddMovie([FromBody] AddMovieRequestViewModel addMovieModel, CancellationToken token = default) { AddMovieRequestModel requestModel = await addMovieModel.BuildAdapter().AdaptToTypeAsync <AddMovieRequestModel>(); AddMovieResponseModel response = await _movieService.AddMovieAsync(requestModel, token); AddMovieResponseViewModel responseViewModel = await response.BuildAdapter().AdaptToTypeAsync <AddMovieResponseViewModel>(); if (responseViewModel == null) { return(BadRequest()); } return(Ok(responseViewModel)); }
public async Task <AddMovieResponseModel> AddMovieAsync(AddMovieRequestModel model, CancellationToken token = default) { try { await _validatorService.ValidationCheck <AddMovieRequestModelValidator, AddMovieRequestModel>(model); MovieEntity entity = await model.BuildAdapter().AdaptToTypeAsync <MovieEntity>(); await _movieRepository.AddAsync(entity, token); AddMovieResponseModel responseModel = await entity.BuildAdapter().AdaptToTypeAsync <AddMovieResponseModel>(); return(responseModel); } catch (Exception) { return(null); } }