Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string id, [Bind("RoomId,StartTime,StaffId,BookedInStudentId")] Slot slot)
        {
            if (id != 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["BookedInStudentId"] = new SelectList(_context.User, "UserId", "UserId", slot.BookedInStudentId);
            ViewData["RoomId"]            = new SelectList(_context.Room, "RoomId", "RoomId", slot.RoomId);
            ViewData["StaffId"]           = new SelectList(_context.User, "UserId", "UserId", slot.StaffId);
            return(View(slot));
        }
Exemplo n.º 2
0
        public Task <bool> Book(string startTime, string studentId, string roomId)
        {
            if (string.IsNullOrEmpty(studentId) || string.IsNullOrEmpty(roomId) || string.IsNullOrEmpty(startTime))
            {
                return(Task.FromResult(false));
            }

            var bookNo = MaximumBookPerDay(studentId);

            if (bookNo == null)
            {
                return(Task.FromResult(false));
            }

            if (bookNo > 0)
            {
                return(Task.FromResult(false));
            }

            DateTime stTime = Convert.ToDateTime(startTime);
            var      slot   = _context.Slot.Where(x => x.StartTime == stTime && x.RoomId == roomId).SingleOrDefault();

            if (slot == null)
            {
                return(Task.FromResult(false));
            }

            if (!string.IsNullOrEmpty(slot.BookedInStudentId))
            {
                return(Task.FromResult(false));
            }

            slot.BookedInStudentId = studentId;
            _context.Update(slot);
            _context.SaveChanges();
            return(Task.FromResult(true));
        }