Пример #1
0
        public async Task <IActionResult> PutRoom(int id, Room room)
        {
            if (id != room.Id)
            {
                return(BadRequest());
            }

            _context.Entry(room).State = EntityState.Modified;

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

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Length,Width")] Room room)
        {
            if (ModelState.IsValid)
            {
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(room));
        }
Пример #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var room = await _context.Room.FindAsync(id);

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

            try
            {
                _context.Room.Remove(room);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction("./Delete", new { id, saveChangesError = true }));
            }
        }