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")); }
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")); }
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(); }
public bool Delete(int groupId) { GroupStudent groupStudentToDelete = _groupStudentList.Find ( groupStundent => groupStundent.GroupId == groupId ); bool wasRemoved = _groupStudentList.Remove(groupStudentToDelete); SaveChanges(); return(wasRemoved); }
public ActionResult Delete(GroupStudent group) { if (group == null) { return(HttpNotFound()); } group = db.Groups.Find(group.Id); return(View(group)); }
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); }
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)); }
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); }
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)); }
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)); }
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)); }
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); } }
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); }
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); } }
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; } }
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; } }
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); } }
public ActionResult Edit(int id) { GroupStudent gs = gbs.GetGroupStudentVM(id); return(View(gs)); }
public void Create(GroupStudent group) { context.Groups.Add(group); Save(); }
public GroupStudent AddNew(GroupStudent newGroupStudent) { _groupStudentList.Add(newGroupStudent); SaveChanges(); return(newGroupStudent); }
public void Edit(GroupStudent group) { context.Entry(group).State = EntityState.Modified; Save(); }