Пример #1
0
        public async Task <bool> DeleteAmentity(int id)
        {
            Amentity amentity = await GetAmentity(id);

            if (amentity == null)
            {
                return(false);
            }
            _context.Entry(amentity).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        public async Task <IActionResult> PutAmentity(int id, Amentity amentity)
        {
            if (id != amentity.Id)
            {
                return(BadRequest());
            }

            if (!await _amentityRepo.PutAmentity(amentity))
            {
                return(NotFound());
            }


            return(NoContent());
        }
Пример #3
0
        public async Task <bool> PutAmentity(Amentity amentity)
        {
            _context.Entry(amentity).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                // Save worked
                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AmentityExists(amentity.Id))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
Пример #4
0
        public async Task <ActionResult <Amentity> > PostAmentity(Amentity amentity)
        {
            await _amentityRepo.CreateAmentity(amentity);

            return(CreatedAtAction("GetAmentity", new { id = amentity.Id }, amentity));
        }
Пример #5
0
 public async Task CreateAmentity(Amentity amentity)
 {
     _context.Amenities.Add(amentity);
     await _context.SaveChangesAsync();
 }