public Task <bool> Create(SlotModel model) { int?maxSlot = MaximumSlotPerDay(model.StaffId); if (maxSlot == null) { return(Task.FromResult(false)); } if (maxSlot > 3) { return(Task.FromResult(false)); } Slot slot = new Slot { RoomId = model.RoomId, StartTime = model.StartTime, StaffId = model.StaffId }; _context.Slot.Add(slot); _context.SaveChangesAsync(); return(Task.FromResult(true)); }
public async Task <IActionResult> Create([Bind("RoomId,StartTime,StaffId,BookedInStudentId")] Slot slot) { if (ModelState.IsValid) { _context.Add(slot); await _context.SaveChangesAsync(); 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)); }
public Task <bool> AddUser(SignUpModel user) { if (_context.User.Any(x => x.Email == user.Email)) { Task.FromResult(false); } User usr = new User(); if (user.Email.After("@").Contains("student")) { usr.UserId = IDGenerator("2"); usr.Name = user.Name; usr.Email = user.Email; } else { usr.UserId = IDGenerator("e"); usr.Name = user.Name; usr.Email = user.Email; } _context.User.Add(usr); _context.SaveChangesAsync(); return(Task.FromResult(true)); }