public async Task <ActionResult <Models.Term> > Post([FromBody] Models.Term model) { if (!ModelState.IsValid) { return(BadRequest(string.Join(",", ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage))))); } // Add var id = await _termsRepository.AddTerm(GetUserId(User), _mapper.Map <Models.Dto.Term>(model)); // Return model.TermId = id; return(Ok(model)); }
public async Task <IActionResult> Post([FromBody] TermViewModel model) { if (!ModelState.IsValid) { return(BadRequest(string.Join(",", ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage))))); } try { // Add var id = await _termsRepository.AddTerm(_userManager.GetUserId(User), _mapper.Map <Term>(model)); // Return model.TermId = id; return(Json(model)); } catch (Exception e) { _logger.LogError(e, "Add failed for term. {User} {Term}", _userManager.GetUserId(User), model.TermId); return(StatusCode(500, $"Add failed for term. Please try again. {e.Message}")); } }