Пример #1
0
 public ActionResult FormGroup(int id)
 {
     using (var db = new ATinformContainer())
     {
         var    groups  = db.GroupSet.Where(elm => elm.Course.Id == id && elm.Started == false).ToList();
         string curUser = User.Identity.GetUserId();
         if (groups.Count == 0)
         {
             var newGroup = new Group {
                 Course = db.CourseSet.Find(id), Started = false, Finished = false
             };
             db.GroupSet.Add(newGroup);
             var newGroupStudent = new GroupStudent {
                 Group = newGroup, Student = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First()
             };
             db.GroupStudentSet.Add(newGroupStudent);
         }
         else
         {
             var newGroupStudent = new GroupStudent {
                 Group = groups.First(), Student = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First()
             };
             db.GroupStudentSet.Add(newGroupStudent);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Пример #2
0
 public ActionResult Edit(GroupStudent gs)
 {
     if (ModelState.IsValid)
     {
         gs = gbs.EditGroupStudentVM(gs);
     }
     return(View(gs));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            GroupStudent groupStudent = db.Groups.Find(id);

            db.Groups.Remove(groupStudent);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public ActionResult DeleteConfirmed(GroupStudent group)
        {
            repository.Delete(group.Id);

            TempData["message"] = "Группа успешно удалена";

            return(RedirectToAction("Index"));
        }
        public void Delete(int id)
        {
            GroupStudent group = context.Groups.Find(id);

            context.Groups.Remove(group);

            Save();
        }
Пример #6
0
        public bool Delete(int groupId)
        {
            GroupStudent groupStudentToDelete = _groupStudentList.Find
                                                (
                groupStundent => groupStundent.GroupId == groupId
                                                );
            bool wasRemoved = _groupStudentList.Remove(groupStudentToDelete);

            SaveChanges();
            return(wasRemoved);
        }
Пример #7
0
        public ActionResult Delete(GroupStudent group)
        {
            if (group == null)
            {
                return(HttpNotFound());
            }

            group = db.Groups.Find(group.Id);

            return(View(group));
        }
Пример #8
0
        public GroupStudent EditGroupStudentVM(GroupStudent gs)
        {
            Group g = GetGroupById(gs.Group.GroupId);

            g.GroupName   = gs.Group.GroupName;
            g.Description = gs.Group.Description;

            _groups.UpdateGroup(GetGroupById(gs.Group.GroupId));
            _groups.Save();

            return(gs);
        }
Пример #9
0
        public GroupStudent GetGroupStudentVM(int id)
        {
            Group          g        = GetGroupById(id);
            GroupStudent   gs       = new GroupStudent();
            List <Student> students = g.Students.ToList();

            foreach (Student s in students)
            {
                gs.Students.Add(s);
            }
            return(gs);
        }
 public ActionResult Edit([Bind(Include = "Id,Name,SpecialityId,QualificationId,Course")] GroupStudent groupStudent)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupStudent).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.QualificationId = new SelectList(db.Qualifications, "Id", "Name", groupStudent.QualificationId);
     ViewBag.SpecialityId    = new SelectList(db.Specialities, "Id", "Name", groupStudent.SpecialityId);
     return(View(groupStudent));
 }
Пример #11
0
        public GroupStudent Update(GroupStudent groupStudentToUpdate)
        {
            GroupStudent groupFound = _groupStudentList.Find
                                      (
                groupStundent => groupStundent.GroupId == groupStudentToUpdate.GroupId
                                      );

            groupFound.GroupId  = groupStudentToUpdate.GroupId;
            groupFound.Students = groupStudentToUpdate.Students;
            SaveChanges();
            return(groupFound);
        }
Пример #12
0
        public ActionResult Create(GroupStudent group)
        {
            if (ModelState.IsValid)
            {
                repository.Create(group);

                TempData["message"] = "Группа успешно добавлена";

                return(RedirectToAction("Index"));
            }
            ViewBag.QualificationId = new SelectList(db.Qualifications, "Id", "Name", group.QualificationId);
            ViewBag.SpecialityId    = new SelectList(db.Specialities, "Id", "Name", group.SpecialityId);
            return(View(group));
        }
        // GET: GroupStudents/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupStudent groupStudent = db.Groups.Find(id);

            if (groupStudent == null)
            {
                return(HttpNotFound());
            }
            return(View(groupStudent));
        }
Пример #14
0
        public ActionResult Edit(GroupStudent group)
        {
            if (ModelState.IsValid)
            {
                repository.Edit(group);

                TempData["message"] = "Информация о группе успешно редактирована";

                return(RedirectToAction("Index"));
            }
            ViewBag.QualificationId = new SelectList(db.Qualifications, "Id", "Name", group.QualificationId);
            ViewBag.SpecialityId    = new SelectList(db.Specialities, "Id", "Name", group.SpecialityId);
            return(View(group));
        }
        // GET: GroupStudents/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupStudent groupStudent = db.Groups.Find(id);

            if (groupStudent == null)
            {
                return(HttpNotFound());
            }
            ViewBag.QualificationId = new SelectList(db.Qualifications, "Id", "Name", groupStudent.QualificationId);
            ViewBag.SpecialityId    = new SelectList(db.Specialities, "Id", "Name", groupStudent.SpecialityId);
            return(View(groupStudent));
        }
Пример #16
0
        public ViewResult Edit(int?id)
        {
            if (id == null)
            {
                return(View("Index"));
            }
            GroupStudent group = repository.Groups.FirstOrDefault(_ => _.Id == id);

            if (group == null)
            {
                return(View("Index"));
            }
            ViewBag.QualificationId = new SelectList(db.Qualifications, "Id", "Name", group.QualificationId);
            ViewBag.SpecialityId    = new SelectList(db.Specialities, "Id", "Name", group.SpecialityId);
            return(View(group));
        }
Пример #17
0
 public bool EnrollStudent(int groupId, int studentId)
 {
     try
     {
         var newRecord = new GroupStudent()
         {
             GroupId   = groupId,
             StudentId = studentId
         };
         _context.GroupStudents.Add(newRecord);
         _context.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #18
0
        private bool WasInBigGroup(Student studentToReview)
        {
            List <GroupStudent> currentGroupStudentList = _groupStudentDBManager.GetAll();
            List <Group>        allGroups           = _groupDBManager.GetAll();
            GroupStudent        currentGroupStudent = null;

            foreach (GroupStudent groupStudent in currentGroupStudentList)
            {
                if (groupStudent.Students.Find(student => student.Name == studentToReview.Name) != null)
                {
                    currentGroupStudent = groupStudent;
                    break;
                }
            }

            Group currentGroup = allGroups.Find(group => group.GroupId == currentGroupStudent.GroupId);

            return(currentGroup.MaxNumberOfStudents == 5);
        }
Пример #19
0
        private void AssignGroup(int groupNumber, List <GroupStudent> newGroupStudentList, Student studentToAssign)
        {
            List <GroupStudent> currentGroupStudentList = _groupStudentDBManager.GetAll();
            List <Group>        allGroups = _groupDBManager.GetAll();

            Group        targetGroup        = allGroups.Find(group => group.GroupId == groupNumber);
            GroupStudent targetGroupStudent = newGroupStudentList.Find(groupStudent => groupStudent.GroupId == targetGroup.GroupId);

            if (targetGroupStudent == null)
            {
                targetGroupStudent = new GroupStudent()
                {
                    GroupId  = targetGroup.GroupId,
                    Students = new List <Student>()
                };
                newGroupStudentList.Add(targetGroupStudent);
            }

            if
            (
                targetGroup != null &&
                targetGroupStudent.Students.Count < targetGroup.MaxNumberOfStudents
            )
            {
                targetGroupStudent.Students.Add(studentToAssign);
                return;
            }
            else
            {
                int groupNumnber;
                if (WasInBigGroup(studentToAssign))
                {
                    groupNumnber = GetAGroupNumber(1, 3, targetGroup.GroupId);
                }
                else
                {
                    groupNumnber = GetAGroupNumber(1, 5, targetGroup.GroupId);
                }
                AssignGroup(groupNumnber, newGroupStudentList, studentToAssign);
            }
        }
Пример #20
0
        public bool RemoveStudentFromGroup(int studentId, int groupId)
        {
            try
            {
                GroupStudent deleteMe = _context.GroupStudents.Where(e => e.StudentId == studentId && e.GroupId == groupId && e.DeactivateDatetime == null).FirstOrDefault();
                if (deleteMe != null)
                {
                    deleteMe.DeactivateDatetime = DateTime.UtcNow;
                    deleteMe.DeactivateUser = "******";
                }
                _context.SaveChanges();

                return true;

            }
            catch (Exception e)
            {

                return false;
            }
        }
Пример #21
0
        public bool AddStudentToGroup(int studentId, int groupId)
        {
            try
            {
                var newRelationship = new GroupStudent()
                {
                    StudentId = studentId,
                    CreateDatetime = DateTime.UtcNow,
                    CreateUser = "******",
                    GroupId = groupId
                };
                _context.GroupStudents.Add(newRelationship);
                _context.SaveChanges();
                return true;
            }
            catch (Exception e)
            {

                return false;
            }
        }
Пример #22
0
        private void OkClick(object sender, RoutedEventArgs e)
        {
            if (name.Text.Length > 0 && studentList.Items.Count > 0 && subjectList.Items.Count > 0)
            {
                if (this.GroupNameExist() == true)   // jezeli w bazie istnieje juz grupa o takiej nazwie
                {
                    MessageBox.Show("Grupa o takiej nazwie już istnieje!!", "Grupa", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (name.Text.Length > 20)
                {
                    MessageBox.Show("Zbyt długa nazwa", "Grupa", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (Group == null) // gdy tworzymy nową grupę
                {
                    Group      = new Group();
                    Group.Name = name.Text;
                    _context.Group.Add(Group);
                    this.SaveDB();

                    // pobranie dodanej grupy z serwera, aby określić jego ID
                    Group = _context.Group.First(g => g.Name == Group.Name);

                    // przypisanie listy uczniów
                    foreach (Student student in studentList.Items)
                    {
                        GroupStudent gs = new GroupStudent
                        {
                            GroupId   = Group.Id,
                            StudentId = student.Id,
                            Group     = Group,
                            Student   = student
                        };
                        _context.GroupStudent.Add(gs);
                        this.SaveDB();
                    }

                    // przypisanie listy przedmiotów
                    foreach (Subject subject in subjectList.Items)
                    {
                        GroupSubject gs = new GroupSubject
                        {
                            GroupId   = Group.Id,
                            SubjectId = subject.Id,
                            Group     = Group,
                            Subject   = subject
                        };
                        _context.GroupSubject.Add(gs);
                        this.SaveDB();
                    }
                }
                else // gdy edytujemy dane grupy
                {
                    Group.Name = name.Text;
                    _context.Attach(Group).State = EntityState.Modified;
                    this.SaveDB();

                    // pomocnicza zmienna do flagowania znajdowania obiektów
                    bool found = false;

                    /// edycja listy uczniów
                    // iteracja po liście studentów
                    foreach (Student student in studentList.Items)
                    {
                        found = false;
                        // iteracja po rekordach w bazie
                        foreach (GroupStudent gr in GroupStudentList)
                        {
                            if (gr.Student.Id == student.Id)
                            {
                                found = true;
                                break;
                            }
                        }
                        // jeśli jest na liście studentów, ale nie ma go w bazie
                        if (found == false)
                        {
                            GroupStudent gs = new GroupStudent
                            {
                                GroupId   = Group.Id,
                                StudentId = student.Id,
                                Group     = Group,
                                Student   = student
                            };
                            _context.GroupStudent.Add(gs);
                            this.SaveDB();
                        }
                    }

                    // iteracja po rekordach w bazie
                    foreach (GroupStudent gr in GroupStudentList)
                    {
                        // jeśli jest w bazie, a nie ma go na liście studentów
                        if (!studentList.Items.Contains(gr.Student))
                        {
                            _context.GroupStudent.Remove(gr);
                            this.SaveDB();
                        }
                    }

                    /// edycja listy przedmiotów
                    // iteracja po liście przedmiotów
                    foreach (Subject subject in subjectList.Items)
                    {
                        found = false;
                        // iteracja po rekordach w bazie
                        foreach (GroupSubject gr in GroupSubjectList)
                        {
                            if (gr.Subject.Id == subject.Id)
                            {
                                found = true;
                                break;
                            }
                        }
                        // jeśli jest na liście przedmiotów, ale nie ma go w bazie
                        if (found == false)
                        {
                            GroupSubject gs = new GroupSubject
                            {
                                GroupId   = Group.Id,
                                SubjectId = subject.Id,
                                Group     = Group,
                                Subject   = subject
                            };
                            _context.GroupSubject.Add(gs);
                            this.SaveDB();
                        }
                    }

                    // iteracja po rekordach w bazie
                    foreach (GroupSubject gr in GroupSubjectList)
                    {
                        // jeśli jest w bazie, a nie ma go na liście studentów
                        if (!subjectList.Items.Contains(gr.Subject))
                        {
                            _context.GroupSubject.Remove(gr);
                            this.SaveDB();
                        }
                    }
                }

                this.SaveDB();

                DialogResult = true;
            }
            else
            {
                MessageBox.Show("Brak wszystkich danych", "Grupa", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Пример #23
0
        public ActionResult Edit(int id)
        {
            GroupStudent gs = gbs.GetGroupStudentVM(id);

            return(View(gs));
        }
        public void Create(GroupStudent group)
        {
            context.Groups.Add(group);

            Save();
        }
Пример #25
0
 public GroupStudent AddNew(GroupStudent newGroupStudent)
 {
     _groupStudentList.Add(newGroupStudent);
     SaveChanges();
     return(newGroupStudent);
 }
        public void Edit(GroupStudent group)
        {
            context.Entry(group).State = EntityState.Modified;

            Save();
        }