Beispiel #1
0
        public async Task <IActionResult> BookConfirmed(string slotID)
        {
            if (SlotExists(Int32.Parse(slotID)))
            {
                var slot = await _context.Slot.FindAsync(Int32.Parse(slotID));

                slot.StudentID = _userManager.GetUserId(User);

                if (_context.Slot.Any(x => x.StudentID == slot.StudentID && x.StartTime.Date == slot.StartTime.Date))
                {
                    Console.WriteLine("Student has already made a booking on this day");
                    return(RedirectToAction(nameof(Index)));
                }

                _context.Update(slot);

                await _context.SaveChangesAsync();
            }
            else
            {
                Console.WriteLine("Slot does not exist");
            }

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #2
0
        public string Update(string RoomID, Room room)
        {
            _context.Update(room);
            _context.SaveChanges();

            return(RoomID);
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(string roomid, DateTime starttime, [Bind("RoomID,StartTime,StaffID,StudentID")] Slot slot)
        {
            if (roomid != slot.RoomID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(slot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SlotExists(slot.RoomID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomID"]    = new SelectList(_context.Room, "RoomID", "RoomID", slot.RoomID);
            ViewData["StaffID"]   = new SelectList(_context.Staff, "StaffID", "StaffID", slot.StaffID);
            ViewData["StudentID"] = new SelectList(_context.Student, "StudentID", "StudentID", slot.StudentID);
            return(View(slot));
        }
        public KeyPair Update(KeyPair pair, Slot slot)
        {
            _context.Update(slot);
            _context.SaveChanges();

            return(pair);
        }
Beispiel #5
0
        public async Task <IActionResult> BookSlot(string roomid, DateTime starttime, [Bind("RoomID,StartTime,StaffID,StudentID")] Slot slot)
        {
            var studentid = HttpContext.User.Identity.Name.Substring(0, 8);

            if (roomid != slot.RoomID)
            {
                return(NotFound());
            }

            if (_context.Slot.Where(x => x.StartTime.Date == starttime.Date && x.StudentID == studentid).Count() == 1)
            {
                ViewData["ErrorMessage"] = new string ("Failed to book slot. You already have a slot booked for this date.");
                return(View(slot));
            }

            slot.StudentID = studentid;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(slot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SlotExists(slot.RoomID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            await _context.SaveChangesAsync();

            return(View(slot));
        }
        public async Task <IActionResult> Edit(string slotID, string RoomName, [Bind("SlotID,RoomID,StartTime,StaffID,StudentID")] Slot slot)
        {
            if (slotID != slot.SlotID.ToString())
            {
                return(NotFound());
            }

            //find the correct room id from the room name.
            slot.RoomID = _context.Room.FirstOrDefault(x => x.RoomName == RoomName).RoomID;

            //set the slot ID to the correct primary keys
            slot.StaffID = FindPrimaryKeyFromSchoolID(slot.StaffID);

            if (slot.StudentID != null)
            {
                slot.StudentID = FindPrimaryKeyFromSchoolID(slot.StudentID);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(slot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SlotExists(slot.SlotID.ToString()))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["RoomName"]  = new SelectList(_context.Room, "RoomName", "RoomName", RoomName);
            ViewData["StaffID"]   = new SelectList(_context.AppUser.Where(x => x.SchoolID.StartsWith('e')), "SchoolID", "SchoolID");
            ViewData["StudentID"] = new SelectList(_context.AppUser.Where(x => x.SchoolID.StartsWith('s')), "SchoolID", "SchoolID");
            return(View(slot));
        }