Пример #1
0
        public ActionResult Edit(Person person)
        {
            var db = new StudentAbsenceEntities();

            ModelState.Remove("Role");
            ModelState.Remove("Password");
            ModelState.Remove("Login");
            if (ModelState.IsValid)
            {
                var dbPerson = db.Person.First(p => p.Id == person.Id);
                if (dbPerson != null)
                {
                    dbPerson.Address     = person.Address;
                    dbPerson.Email       = person.Email;
                    dbPerson.PhoneNumber = person.PhoneNumber;
                    dbPerson.Name        = person.Name;
                    dbPerson.Patronimic  = person.Patronimic;
                    dbPerson.Surname     = person.Surname;
                    dbPerson.Role        = "d";
                    dbPerson.Password    = "******";
                    dbPerson.Login       = "******";
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
        public ActionResult Delete(int id)
        {
            var db     = new StudentAbsenceEntities();
            var lesson = db.Lesson.FirstOrDefault(s => s.Id == id);

            db.Lesson.Remove(lesson);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Delete(int id)
        {
            var db            = new StudentAbsenceEntities();
            var groupToRemove = db.Group.FirstOrDefault(s => s.Id == id);

            db.Group.Remove(groupToRemove);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int lessonId, int studentId)
        {
            var db      = new StudentAbsenceEntities();
            var absence = db.Attendance.FirstOrDefault(s => s.LessonId == lessonId && s.StudentId == studentId);

            db.Attendance.Remove(absence);
            db.SaveChanges();
            return(RedirectToAction("Create", new { id = lessonId }));
        }
        public ActionResult Delete(int id)
        {
            var db      = new StudentAbsenceEntities();
            var faculty = db.Faculty.FirstOrDefault(s => s.Id == id);

            db.Faculty.Remove(faculty);
            db.SaveChanges();
            var result = db.Faculty.Select(s => s).OrderBy(s => s.Name).ToList();

            return(RedirectToAction("Index"));
        }
Пример #6
0
        public ActionResult Delete(int id)
        {
            var authDB   = new ApplicationDbContext();
            var db       = new StudentAbsenceEntities();
            var dbPerson = db.Person.FirstOrDefault(p => p.Id == id);

            if (dbPerson != null)
            {
                var userName = db.User.FirstOrDefault(u => u.PersonId == id).login;
                db.Person.Remove(dbPerson);
                db.SaveChanges();

                var authUser = authDB.Users.FirstOrDefault(u => u.UserName == userName);
                authDB.Users.Remove(authUser);
                authDB.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Create(CreateAndListFacultyModel model)
        {
            var db = new StudentAbsenceEntities();

            if (ModelState.IsValid)
            {
                db.Faculty.Add(model.NewFaculty);
                db.SaveChanges();
                var result = db.Faculty.Select(s => s).OrderBy(s => s.Name).ToList();
                return(RedirectToAction("Index"));
            }

            var list = db.Faculty.Select(s => s).OrderBy(s => s.Name).ToList();

            return(View("Index", new CreateAndListFacultyModel()
            {
                NewFaculty = model.NewFaculty, Faculties = list
            }));
        }
        public ActionResult Edit(Student model)
        {
            var db = new StudentAbsenceEntities();

            if (ModelState.IsValid)
            {
                var student = db.Student.First(c => c.PersonId == model.PersonId);
                if (student != null)
                {
                    student.GroupId          = model.GroupId;
                    student.RecordBookNumber = model.RecordBookNumber;
                    student.BirthDate        = model.BirthDate;
                }
                db.SaveChanges();
                return(RedirectToAction("Edit", new { id = model.PersonId }));
            }
            model.Person   = db.Person.First(p => p.Id == model.PersonId);
            ViewBag.Groups = new SelectList(db.Group, "Id", "Name", model.GroupId);
            return(View(model));
        }
        public ActionResult Create(CreateAndListLessonModel model)
        {
            var db = new StudentAbsenceEntities();

            if (ModelState.IsValid)
            {
                db.Lesson.Add(model.NewLesson);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Subjects = new SelectList(db.Subject, "Id", "Name");
            ViewBag.Teachers = new SelectList(db.Teacher, "PersonId", "FullName");
            ViewBag.Groups   = new SelectList(db.Group, "Id", "Name");
            var list = db.Lesson.Select(c => c).OrderBy(c => c.Group.Name).ThenBy(c => c.Date).ToList();

            return(View("Index", new CreateAndListLessonModel()
            {
                Lessons = list, NewLesson = model.NewLesson
            }));
        }
        public ActionResult Create(CreateAndListAttendanceModel model)
        {
            var db = new StudentAbsenceEntities();

            if (ModelState.IsValid)
            {
                db.Attendance.Add(model.NewAbsence);
                db.SaveChanges();
                return(RedirectToAction("Create", new { id = model.NewAbsence.LessonId }));
            }

            var studentsInGroup = db.Student.Where(s => s.GroupId == model.NewAbsence.LessonId).ToList();

            RemoveAbsentStudents(studentsInGroup, model.NewAbsence.LessonId);
            ViewBag.Students = new SelectList(studentsInGroup, "PersonId", "FullName");
            var list = db.Attendance.Select(c => c).OrderBy(c => c.Student.Person.Surname).ToList();

            return(View(new CreateAndListAttendanceModel()
            {
                Absences = list, NewAbsence = model.NewAbsence
            }));
        }
Пример #11
0
        public ActionResult Create(CreateAndListGroupModel model)
        {
            var db = new StudentAbsenceEntities();

            if (!db.IsGroupUnique(model.NewGroup.Name))
            {
                ModelState.AddModelError(string.Empty, "Группа с таким номером уже существует!");
            }

            if (ModelState.IsValid)
            {
                db.Group.Add(model.NewGroup);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var list = db.Group.Select(c => c).OrderBy(c => c.Name).ToList();

            ViewBag.Faculties = new SelectList(db.Faculty, "Id", "Name");
            return(View("Index", new CreateAndListGroupModel()
            {
                Groups = list, NewGroup = model.NewGroup
            }));
        }
Пример #12
0
        public async Task <ActionResult> Create(Person person)
        {
            var authDB = new ApplicationDbContext();
            var db     = new StudentAbsenceEntities();

            ViewBag.Roles = new SelectList(authDB.Roles, "Name", "Name");

            if (!db.IsLoginUnique(person.Login))
            {
                ModelState.AddModelError(string.Empty, "Пользователь с таким именем уже существует!");
            }

            if (ModelState.IsValid)
            {
                var store    = new UserStore <ApplicationUser>(authDB);
                var manager  = new ApplicationUserManager(store);
                var authUser = new ApplicationUser()
                {
                    UserName = person.Login, Email = person.Email
                };
                await manager.CreateAsync(authUser, person.Password);

                var role          = authDB.Roles.First(r => r.Name == person.Role);
                var savedAuthUser = authDB.Users.First(u => u.UserName == person.Login);
                authUser.Roles.Add(new IdentityUserRole()
                {
                    RoleId = role.Id, UserId = savedAuthUser.Id
                });
                authDB.SaveChanges();

                var savedPerson = db.Person.Add(person);
                var userRole    = db.Role.First(r => r.Role1 == person.Role);
                db.User.Add(new User()
                {
                    login = person.Login, PersonId = savedPerson.Id, Role = userRole
                });
                db.SaveChanges();

                if (person.Role == "Студент")
                {
                    db.Student.Add(new Student()
                    {
                        PersonId = savedPerson.Id, RecordBookNumber = "0000000", BirthDate = DateTime.Today, GroupId = null
                    });
                }
                else
                {
                    if (person.Role == "Преподаватель")
                    {
                        db.Teacher.Add(new Teacher()
                        {
                            PersonId = savedPerson.Id
                        });
                    }
                }
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(person));
        }