private async Task createrole(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.CreateScope()) { var services = serviceScope.ServiceProvider; var db = services.GetService <ApplicationDbContext>(); if (db.Database.GetPendingMigrations().Any()) { await db.Database.MigrateAsync(); var _rolemanager = serviceScope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); if (!await _rolemanager.RoleExistsAsync("Admin")) { await _rolemanager.CreateAsync(new IdentityRole("Admin")); } if (!await _rolemanager.RoleExistsAsync("Student")) { await _rolemanager.CreateAsync(new IdentityRole("Student")); } } // await ScheduleEmail(db); // await SendEm(); ScheduleEmail send = new ScheduleEmail(db); send.getEvent(); } }
// [HttpPost] public async Task <IActionResult> ChooseEventB(EventModel model) { // var Event = from crs in db.Events where crs.EventId == model.EventId select crs; // EventModel crs = Event[0]; var evt = db.Events.SingleOrDefault(e => e.EventId == model.EventId); if (evt.OccupiedSeats >= evt.NumberOfSeats) { TempData["Message"] = "The event is full!"; // return View(); return(RedirectToAction("ChooseEvent", "Event")); } evt.OccupiedSeats += 1; var us = await GetCurrentUserAsync(); var check = db.StudentEvents.SingleOrDefault(l => l.EventId == model.EventId && l.ApplicationUser == us); if (check != null) { TempData["Message"] = "Duplicated Enrollment!"; // return View("ChooseEvent"); return(RedirectToAction("ChooseEvent", "Event")); } StudentEvent scs = new StudentEvent(); scs.EventId = model.EventId; scs.ApplicationUser = us; db.StudentEvents.Add(scs); db.SaveChanges(); ScheduleEmail send = new ScheduleEmail(db); send.getEvent(); // return PartialView("part",_model); return(RedirectToAction("ChooseEvent", "Event")); // return View(db.Events.ToList()); }
public IActionResult GroupEvent(GEvent model, string returnUrl = null) { if (ModelState.IsValid) { var GroupList = (from us in db.Users join sc in db.StudentCourses on us.Id equals sc.ApplicationUser.Id where sc.GroupNumber == model.GroupNumber && sc.CourseId == model.CourseId select us).ToList(); EventModel EM = new EventModel { Date = model.Date, Time = model.Time, Location = model.Location, NumberOfSeats = GroupList.Count, OccupiedSeats = GroupList.Count, Title = model.Title, Description = model.Description }; db.Events.Add(EM); foreach (var item in GroupList) { StudentEvent scs = new StudentEvent(); scs.EventId = EM.EventId; scs.ApplicationUser = item; db.StudentEvents.Add(scs); } db.SaveChanges(); ScheduleEmail send = new ScheduleEmail(db); send.getEvent(); TempData["Message"] = "Group created successfully!"; } else { TempData["Message"] = "Group created failed!"; } return(RedirectToAction("ChooseEvent", "Event")); }