コード例 #1
0
        public async Task <IActionResult> Put(long id, [FromBody] AcademiaInputDTO inputDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var academia = new AcademiaEntity(inputDTO.Nome, inputDTO.Endereco, inputDTO.Email);
                academia.Id = id;
                var result = await _service.Put(academia);

                if (result != null)
                {
                    return(Ok(result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] AcademiaInputDTO inputDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var academia = new AcademiaEntity(inputDTO.Nome, inputDTO.Endereco, inputDTO.Email);
                var result   = await _service.Post(academia);

                if (result != null)
                {
                    return(Created(new Uri(Url.Link("GetWithId", new { id = result.Id })), result));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (ArgumentException e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
コード例 #3
0
 public async Task <AcademiaEntity> Put(AcademiaEntity academia)
 {
     return(await _repository.UpdateAsync(academia));
 }
コード例 #4
0
 public async Task <AcademiaEntity> Post(AcademiaEntity academia)
 {
     return(await _repository.InsertAsync(academia));
 }