示例#1
0
        public async Task <ActionResult> Post([FromBody] SchoolDtoCreate school)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await _service.Post(school);

                if (result != null)
                {
                    return(Created(new Uri(Url.Link("GetSchoolWithId", new { id = result.Id })), result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
示例#2
0
        public async Task <SchoolDtoCreateResult> Post(SchoolDtoCreate school)
        {
            var model  = _mapper.Map <SchoolModel>(school);
            var entity = _mapper.Map <SchoolEntity>(model);
            var result = await _repository.InsertAsync(entity);

            return(_mapper.Map <SchoolDtoCreateResult>(result));
        }