Exemplo n.º 1
0
        public ActionResult Create(RoomBooking booking)
        {
            if (ModelState.IsValid)
            {
                db.RoomBookings.Add(booking);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(booking));
        }
        public IActionResult PutRoom([FromRoute] int id, [FromBody] Room room)
        {
            if (room == null)
            {
                return(BadRequest("Employee is null."));
            }
            Room roomToupdate = _context.Room
                                .FirstOrDefault(e => e.Id == id);

            if (roomToupdate == null)
            {
                return(NotFound("The Employee record couldn't be found."));
            }

            roomToupdate.RoomNumber       = room.RoomNumber;
            roomToupdate.AdultsCapacity   = room.AdultsCapacity;
            roomToupdate.ChildrenCapacity = room.ChildrenCapacity;
            roomToupdate.Price            = room.Price;
            _context.SaveChanges();
            return(NoContent());

            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            //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();
        }
Exemplo n.º 3
0
        public IActionResult PutAmenity([FromRoute] int id, [FromBody] Amenity amenity)
        {
            if (amenity == null)
            {
                return(BadRequest("Employee is null."));
            }
            Amenity amenitytoupdate = _context.Amenity
                                      .FirstOrDefault(e => e.Id == id);

            if (amenitytoupdate == null)
            {
                return(NotFound("The Employee record couldn't be found."));
            }

            amenitytoupdate.Label        = amenity.Label;
            amenitytoupdate.Amenityorder = amenity.Amenityorder;
            amenitytoupdate.IsActive     = amenity.IsActive;

            _context.SaveChanges();
            return(NoContent());
        }
Exemplo n.º 4
0
        public ActionResult Delete(int id = 0)
        {
            Booking booking = db.Bookings.Find(id);

            if (booking == null)
            {
                return(HttpNotFound());
            }

            var roomBookings = from t in dbRoomBooking.RoomBookings select t;

            roomBookings = roomBookings.Where(r => r.BookingId == id);
            foreach (var rB in roomBookings)
            {
                RoomBooking roomB = dbRoomBooking.RoomBookings.Find(rB.ID);
                dbRoomBooking.RoomBookings.Remove(roomB);
            }
            dbRoomBooking.SaveChanges();

            db.Bookings.Remove(booking);
            db.SaveChanges();
            return(RedirectToAction("BookingList"));
        }
 public void Add(Room entity)
 {
     _roomContext.Room.Add(entity);
     _roomContext.SaveChanges();
 }