public async Task <ActionResult> Post([FromBody] ClassStudentDtoCreate _class) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _service.Post(_class); if (result != null) { return(Created(new Uri(Url.Link("GetClassStudentWithId", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <ClassStudentDtoCreateResult> Post(ClassStudentDtoCreate _classStudent) { var model = _mapper.Map <ClassStudentModel>(_classStudent); var entity = _mapper.Map <ClassStudentEntity>(model); var result = await _repository.InsertAsync(entity); return(_mapper.Map <ClassStudentDtoCreateResult>(result)); }