Exemplo n.º 1
0
        public async Task <IActionResult> PutRoom(int id, Room room)
        {
            if (id != room.Id)
            {
                return(BadRequest());
            }

            RoomValid valid = new RoomValid(_context, room);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Room is already exist"));
            }

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

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

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Room> > PostRoom(Room room)
        {
            RoomValid valid = new RoomValid(_context, room);

            if (valid.Valid() == false)
            {
                return(BadRequest("This room is already exist"));
            }
            _context.Room.Add(room);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetRoom", new { id = room.Id }, room));
        }