コード例 #1
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.Token == id);

            if (token == null)
            {
                return(NotFound());
            }
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                //System.Diagnostics.Debug.WriteLine(UserEmail);
                await CreateRole();

                var user = new IdentityUser {
                    UserName = token.Email, Email = token.Email, EmailConfirmed = true
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    if (token.Role == "Admin")
                    {
                        await _userManager.AddToRoleAsync(user, "Admin");
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, "Lecturer");

                        Lecturer lecturer = new Lecturer {
                            Name = token.Name, Email = token.Email
                        };
                        _context.Lecturer.Add(lecturer);
                        await _context.SaveChangesAsync();
                    }
                    _context.RegistrationToken.Remove(token);
                    await _context.SaveChangesAsync();

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToPage("Login"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            // If we got this far, something failed, redisplay form
            return(Page());
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.ID == id);

            if (Token == null)
            {
                return(NotFound());
            }
            DateTime          d_time   = DateTime.Now;
            RegistrationToken regToken = new RegistrationToken
            {
                GenerateTime   = d_time,
                ExpirationTime = d_time.AddDays(2),
                Email          = Token.Email,
                Role           = "Lecturer"
            };

            _context.RegistrationToken.Add(regToken);
            _context.RegistrationToken.Remove(Token);
            await _context.SaveChangesAsync();

            var callbackUrl = Url.Page(
                "/Account/RegisterAdmin",
                pageHandler: null,
                values: new { area = "Identity", id = regToken.Token },
                protocol: Request.Scheme);

            await _emailSender.SendEmailAsync(regToken.Email, "Create account",
                                              $"Please register your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

            return(RedirectToPage("ManageLecturers"));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Seat = await _context.Seat.ToListAsync();

            Course = await _context.Course.ToListAsync();

            Classroom = await _context.ClassRoom.ToListAsync();

            Students = await _context.Student.ToListAsync();

            if (id == null)
            {
                return(NotFound());
            }

            Session = await _context.Session.FindAsync(id);


            if (Session != null)
            {
                foreach (Seat seat in Session.ClassRoom.Seats)
                {
                    _context.Student.Remove(seat.Student);
                    _context.Seat.Remove(seat);
                }
                _context.ClassRoom.Remove(Session.ClassRoom);
                _context.Course.Remove(Session.Course);
                _context.Session.Remove(Session);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("Sessions"));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var               expirationTime = _context.GlobalVariables.First().TokenExpirationDays;
            DateTime          d_time         = DateTime.Now;
            RegistrationToken regToken       = new RegistrationToken
            {
                GenerateTime   = d_time,
                ExpirationTime = d_time.AddDays(expirationTime),
                Email          = Admin.Email,
                Role           = "Admin"
            };

            _context.RegistrationToken.Add(regToken);
            await _context.SaveChangesAsync();

            var callbackUrl = Url.Page(
                "/Account/RegisterAdmin",
                pageHandler: null,
                values: new { area = "Identity", id = regToken.Token },
                protocol: Request.Scheme);

            await _emailSender.SendEmailAsync(Admin.Email, "Create account",
                                              $"Please register your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");


            return(RedirectToPage("ManageSystem"));
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Seats = await _context.Seat.ToListAsync();

            Students = await _context.Student.ToListAsync();

            Classroom = await _context.ClassRoom.FindAsync(id);

            if (Classroom != null)
            {
                foreach (Seat seat in Classroom.Seats)
                {
                    _context.Student.Remove(seat.Student);
                    _context.Seat.Remove(seat);
                }
                _context.ClassRoom.Remove(Classroom);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("ClassroomList"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            _context.Attach(GlobalVar).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(RedirectToPage("ManageSystem"));
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Token = await _context.RegistrationToken.FirstOrDefaultAsync(m => m.ID == id);

            if (Token == null)
            {
                return(NotFound());
            }
            _context.RegistrationToken.Remove(Token);
            await _context.SaveChangesAsync();

            return(RedirectToPage("ManageSystem"));
        }
コード例 #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (MainText != "")
            {
                Cases covidCase = new Cases {
                    Name = User.Identity.Name, Description = MainText
                };
                _context.Cases.Add(covidCase);
                await _context.SaveChangesAsync();

                StatusMessage = "Message sent.";
            }
            return(RedirectToPage());
        }
コード例 #9
0
        public async Task<IActionResult> OnPostAsync(int? id)
        {
            if (id == null)
            {
                return NotFound();
            }

            Course = await _context.Course.FindAsync(id);

            if (Course != null)
            {
                _context.Course.Remove(Course);
                await _context.SaveChangesAsync();
            }

            return RedirectToPage("CourseList");
        }
コード例 #10
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CovidCase = await _context.Cases.FindAsync(id);

            if (CovidCase != null)
            {
                _context.Cases.Remove(CovidCase);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("Sessions"));
        }
コード例 #11
0
        public async Task <IActionResult> OnPostAsync(string id)
        {
            Courses = await _context.Course.ToListAsync();

            Lecturers = await _context.Lecturer.ToListAsync();

            if (id == null)
            {
                return(NotFound());
            }
            var user = await _userManager.FindByIdAsync(id);

            var lecturer = await _context.Lecturer.FirstOrDefaultAsync(m => m.Email == user.Email);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }
            if (lecturer == null)
            {
                return(NotFound($"Unable to load lecturer."));
            }
            var courses = await _context.Course.ToListAsync();

            var isTeaching = false;

            foreach (Course course in courses)
            {
                if (course.Lecturer.ID == lecturer.ID)
                {
                    isTeaching = true;
                }
            }
            if (!isTeaching)
            {
                _context.Lecturer.Remove(lecturer);
                await _context.SaveChangesAsync();

                var result = await _userManager.DeleteAsync(user);

                return(RedirectToPage("ManageLecturers"));
            }

            return(RedirectToPage("LecturerError"));
        }
コード例 #12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Lecturers = await _context.Lecturer.ToListAsync();

            var selectedLecturer = _context.Lecturer.Find(SelectedLecturerId);

            Course.Lecturer     = selectedLecturer;
            Course.LecturerName = selectedLecturer.Name;
            Course.isModel      = true;
            _context.Course.Add(Course);
            await _context.SaveChangesAsync();

            return(RedirectToPage("CreateSession"));
        }
コード例 #13
0
        public async Task <IActionResult> OnPostAsync()
        {
            Classroom.Coordinates = Coords;
            if (Coords != null)
            {
                Coords             = Coords.Remove(Coords.Length - 1);
                Classroom.FileName = "test2.svg";
                List <string> list  = Coords.Split(',').ToList();
                List <int>    xlist = new List <int>();
                List <int>    ylist = new List <int>();

                foreach (string co in list)
                {
                    if (list.IndexOf(co) % 2 == 0)
                    {
                        xlist.Add(Int32.Parse(co.Trim()));
                    }
                    else
                    {
                        ylist.Add(Int32.Parse(co.Trim()));
                    }
                }

                List <Seat> SeatList = new List <Seat>();
                for (int i = 0; i < xlist.Count; i++)
                {
                    SeatList.Add(new Seat {
                        X = xlist[i], Y = ylist[i], Student = new Models.Student {
                            isModel = true
                        }
                    });
                }
                Classroom.Name    = Classroom.Number + " - " + SeatList.Count + " seats";
                Classroom.Seats   = SeatList;
                Classroom.isModel = true;
                _context.ClassRoom.Add(Classroom);
                await _context.SaveChangesAsync();

                return(RedirectToPage("Admin/CreateSession"));
            }
            return(Page());
        }
コード例 #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Student = await _context.Student.FirstOrDefaultAsync(m => m.ID == id);

            Seat = await _context.Seat.FirstOrDefaultAsync(s => s.Student.ID == id);

            Seat.Student = new Models.Student();
            if (Student != null)
            {
                _context.Attach(Seat).State = EntityState.Modified;
                _context.Student.Remove(Student);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("Sessions"));
        }
コード例 #15
0
        public async Task <IActionResult> OnPostAsync()
        {
            Seats = await _context.Seat.ToListAsync();

            Lecturers = await _context.Lecturer.ToListAsync();

            Courses = await _context.Course.Where(s => s.isModel).ToListAsync();

            Course      selectedCourse    = _context.Course.Find(SelectedCourseId);
            ClassRoom   selectedClassroom = _context.ClassRoom.Find(SelectedClassroomId);
            var         copyClassroom     = selectedClassroom.DeepCopy();
            var         copyCourse        = selectedCourse.DeepCopy();
            List <Seat> newSeats          = new List <Seat>();

            foreach (Seat seat in selectedClassroom.Seats)
            {
                Seat newSeat = new Seat
                {
                    Student = new Models.Student(),
                    X       = seat.X,
                    Y       = seat.Y
                };
                newSeats.Add(newSeat);
            }

            ClassRoom newClassroom = new ClassRoom
            {
                Coordinates = copyClassroom.Coordinates,
                Seats       = newSeats,
                Number      = copyClassroom.Number,
                FileName    = copyClassroom.FileName
            };

            Course newCourse = new Course
            {
                Name         = copyCourse.Name,
                Lecturer     = selectedCourse.Lecturer,
                NrOfStudents = copyCourse.NrOfStudents,
                LecturerName = copyCourse.LecturerName,
                CourseCode   = copyCourse.CourseCode
            };
            GlobalVariables globalVariables = _context.GlobalVariables.First();

            var endTime = DateTime.AddMinutes(globalVariables.SessionDuration);
            var month   = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(DateTime.Month);

            SessionName        = DateTime.DayOfWeek.ToString().Substring(0, 3) + ", " + DateTime.ToString("HH:mm") + "-" + endTime.ToString("HH:mm") + ", classroom " + newClassroom.Number;
            CourseName         = newCourse.Name + " " + newCourse.CourseCode;
            Session.Course     = newCourse;
            Session.ClassRoom  = newClassroom;
            Session.Time       = DateTime;
            Session.Name       = SessionName;
            Session.CourseName = CourseName;

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Session.Add(Session);
            await _context.SaveChangesAsync();

            return(RedirectToPage("Sessions"));
        }
コード例 #16
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            Seat = await _context.Seat.ToListAsync();

            Course = await _context.Course.ToListAsync();

            Classroom = await _context.ClassRoom.ToListAsync();

            Students = await _context.Student.ToListAsync();

            Session = await _context.Session.FirstOrDefaultAsync(m => m.ID == id);

            if (Session == null)
            {
                return(NotFound());
            }

            var confirmedSeat = await _context.Seat.FirstOrDefaultAsync(m => m.Student.Name == User.Identity.Name &&
                                                                        Session.ClassRoom.Seats.Contains(m));

            if (confirmedSeat != null)
            {
                ConfirmedSeat = confirmedSeat;
                ConfirmedSeat.Student.Name = "-";
                ConfirmedSeat.BookingTime  = DateTime.MinValue;
                _context.Seat.Attach(ConfirmedSeat).State = EntityState.Modified;
            }
            if (SelectedSeat.ID == -1)
            {
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                StatusMessage = "Your reservation has been cancelled.";
                return(RedirectToPage("PickSeats", new { id = id }));
            }
            else
            {
                ConfirmedSeat = await _context.Seat.FirstOrDefaultAsync(m => m.ID == SelectedSeat.ID &&
                                                                        Session.ClassRoom.Seats.Contains(m));

                ConfirmedSeat.Student.Name = User.Identity.Name;
                ConfirmedSeat.BookingTime  = DateTime.Now;
                _context.Seat.Attach(ConfirmedSeat).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                if (confirmedSeat != null)
                {
                    StatusMessage = "Your booking has been changed.";
                    return(RedirectToPage("PickSeats", new { id = id }));
                }
                StatusMessage = "Your booking has been confirmed.";
                return(RedirectToPage("PickSeats", new { id = id }));
            }
        }