public IActionResult Create([FromBody] UserClassDto classDto) { // map dto to entity var @class = _mapper.Map <UserClass>(classDto); try { // save Log.Information($"Attempting to save class"); var newClass = _userClassService.Create(@class); return(Ok(newClass)); } catch (AppException ex) { // return error message if there was an exception Log.Error($"Failed to save Class"); Log.Error(ex.StackTrace.ToString()); return(BadRequest(new { message = ex.Message })); } }
public IActionResult Update(int id, [FromBody] UserClassDto classDto) { // map dto to entity and set id var @class = _mapper.Map <UserClass>(classDto); @class.Id = id; try { // save Log.Information($"Attempting to save class"); var userClassDto = _mapper.Map <UserClassDto>(_userClassService.Update(@class)); Log.Information("Update Successful"); return(Ok(userClassDto)); } catch (AppException ex) { // return error message if there was an exception Log.Error($"Failed to update Class with id: {@class.Id}"); Log.Error(ex.StackTrace.ToString()); return(BadRequest(new { message = ex.Message })); } }