Beispiel #1
0
        public async Task <ActionResult> Put(int tipoItemId, TipoItemDTO model)
        {
            try
            {
                var tipoItem = await _repo.GetTipoItemByIdAsync(tipoItemId);

                if (tipoItem == null)
                {
                    return(NotFound());
                }

                _mapper.Map(model, tipoItem);

                _repo.Update(tipoItem);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/tipoitem/{tipoItem.Id}", _mapper.Map <TipoItemDTO>(tipoItem)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }

            return(BadRequest());
        }
Beispiel #2
0
        public async Task <ActionResult> Post(TipoItemDTO model)
        {
            try
            {
                var tipoItem = _mapper.Map <TipoItem>(model);
                _repo.Add(tipoItem);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/tipoitem/{tipoItem.Id}", _mapper.Map <TipoItemDTO>(tipoItem)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }

            return(BadRequest());
        }