public async Task <IActionResult> Post([FromBody] MovieOrderViewModel movieOrderVM) { try { if (ModelState.IsValid) { var movieOrder = _mapper.Map <MovieOrderViewModel, MovieOrder>(movieOrderVM); var loggedInUser = await _userManager.FindByNameAsync(User.Identity.Name); movieOrder.User = loggedInUser; _movieRepository.AddMovieOrder(movieOrder); if (_movieRepository.Save()) { return(Created($"/api/movieorders/{movieOrder.Id}", _mapper.Map <MovieOrder, MovieOrderViewModel>(movieOrder))); } } else { return(BadRequest(ModelState)); } } catch (Exception ex) { _logger.LogError($"Failed to save record: {ex}"); } return(BadRequest("Failed to save record")); }