//[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookingVM staffAttendance)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Staffing staff = await _context.Staffing.FindAsync(staffAttendance.StaffId, staffAttendance.EventId);

                    if (staff != null && staffAttendance.Attended == false)
                    {
                        _context.Remove(staff);
                        await _context.SaveChangesAsync();

                        return(Ok());
                    }
                    if (staff == null && staffAttendance.Attended == true)
                    {
                        _context.Add(new Staffing(staffAttendance.EventId, staffAttendance.StaffId));
                        await _context.SaveChangesAsync();

                        return(Ok());
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(NotFound());
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Firstname, Lastname, Email, Streetadress, City, Country, Ice ,Qtypersons, RoomTypeId, Startdate,Enddate,Eta,Timearrival,Timedeparture,Specialneeds,Extrabed, StaffId")] StaffBookingVM booking)
        {
            if (ModelState.IsValid)
            {
                var customerId = _customerService.CheckIfCustomerExists(booking.Email);
                if (customerId == 0)
                {
                    customerId = _customerService.CreateCustomer(1, booking.Firstname, booking.Lastname, booking.Email, booking.Streetadress, booking.City, booking.Country, booking.Ice, DateTime.Now);
                }
                try
                {
                    var freeRoomId = _roomService.GetIdOfFreeRoomOfType(booking.RoomTypeId, booking.Startdate, booking.Enddate);
                    if (freeRoomId != 0)
                    {
                        var newBooking = new Booking()
                        {
                            Customersid  = customerId,
                            Qtypersons   = booking.Qtypersons,
                            Startdate    = booking.Startdate,
                            Enddate      = booking.Enddate,
                            Eta          = booking.Eta,
                            Specialneeds = booking.Specialneeds,
                            Extrabed     = booking.Extrabed,
                            Staffid      = booking.StaffId
                        };
                        _context.Bookings.Add(newBooking);
                        await _context.SaveChangesAsync();

                        var bookingsroom = new Bookingsroom()
                        {
                            Bookingsid = newBooking.Id,
                            Roomsid    = freeRoomId
                        };
                        _context.Bookingsrooms.Add(bookingsroom);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                catch (InvalidOperationException e)
                {
                    ViewBag.ErrorMsg = "No room of this type available for the specific dates you've entered";
                    return(View(booking));
                }
            }
            ViewData["Staffid"]    = new SelectList(_context.staff, "Id", "Firstname");
            ViewData["RoomTypeId"] = new SelectList(_context.Roomtypes, "Id", "Name");
            var bookedRooms = _bookingService.GetBookedDates();

            ViewBag.SingleFullyBookedDates = bookedRooms.Where(x => x.BookedSingleRooms >= _roomService.GetAmountOfRooms(1)).Select(d => d.Date).ToList();
            ViewBag.DoubleFullyBookedDates = bookedRooms.Where(x => x.BookedDoubleRooms >= _roomService.GetAmountOfRooms(2)).Select(d => d.Date).ToList();
            ViewBag.TripleFullyBookedDates = bookedRooms.Where(x => x.BookedTripleRooms >= _roomService.GetAmountOfRooms(3)).Select(d => d.Date).ToList();
            ViewBag.QuadFullyBookedDates   = bookedRooms.Where(x => x.BookedQuadRooms >= _roomService.GetAmountOfRooms(4)).Select(d => d.Date).ToList();

            return(View(booking));
        }