Exemple #1
0
        public async Task <IActionResult> PutOutpost(long id, OutpostDto outpostDto)
        {
            if (id != outpostDto.Id)
            {
                return(BadRequest());
            }

            var outpost = _context.Outposts.First(o => o.Id == outpostDto.Id);

            outpost.Name     = outpostDto.Name;
            outpost.Location = outpostDto.Location;
            _context.Entry(outpost).State = EntityState.Modified;

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

            return(NoContent());
        }
Exemple #2
0
        public async Task <ActionResult <OutpostDto> > PostOutpost(OutpostDto outpostDto)
        {
            _context.Outposts.Add(new Outpost
            {
                Name     = outpostDto.Name,
                Location = outpostDto.Location
            });
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOutpost", new { id = outpostDto.Id }, outpostDto));
        }