示例#1
0
        public async Task <IActionResult> Post([FromBody] Container container)
        {
            try
            {
                _container.Add(container);

                if (await _container.SaveChangesAsync())
                {
                    return(Created($"/api/container/{container.Id}", container));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou"));
            }

            return(BadRequest());
        }
示例#2
0
        public async Task <IActionResult> PutContainer(int id, ContainerPutModel container)
        {
            if (id != container.Id)
            {
                return(BadRequest());
            }

            var model = new Container
            {
                Id          = container.Id,
                Code        = container.Code,
                Description = container.Description,
                SectorId    = container.SectorId,
                Type        = container.Type,
                Volume      = container.Volume
            };

            _repo.Update(model);

            try
            {
                await _repo.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ContainerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }