public ActionResult RegisteringInTheCourse(int id) { if (repository.checkRegisteredPhoneNumber(SessionPersister.Login) == false) { return(View("EditPhone")); } if (repository.checkRegisteredEmail(SessionPersister.Login) == false) { return(View("EditEMail")); } var disciplineAcc = repository.GetDiscipline(id); var studInGroup = new StudentsInGroups(); var group = repository.GetGroupByDisciplinesId(disciplineAcc.id); studInGroup.groupID = group.id; studInGroup.studentID = SessionPersister.Login; studInGroup.DateOfRegister = DateTime.Now; if (DateTime.Now.Year == group.year) { using (var context = new CoursesOfChoiceEntities()) { context.StudentsInGroups.Add(studInGroup); context.SaveChanges(); repository.addAmountStudent(group.id); } } return(View("YouAreRegisted", disciplineAcc)); }
/// <summary> /// Delete discipline /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteDiscipline(int id) { using (var context = new CoursesOfChoiceEntities()) { var discipline = context.Disciplines.SingleOrDefault(disc => disc.id == id); if (discipline == null) { return(false); } else { var singleOrDefault = discipline.Group.SingleOrDefault(gr => gr.Deleted == false && gr.Wave == 1); var groups = discipline.Group.ToList(); foreach (var gr in groups) { var sigs = gr.StudentsInGroups; context.Set <StudentsInGroups>().RemoveRange(sigs); context.Set <Group>().Remove(gr); } context.Set <Disciplines>().Remove(discipline); context.SaveChanges(); return(true); } } }
/// <summary> /// Get students list that have the same discipline by discipline id /// </summary> /// <param name="disciplineId"></param> /// <param name="wave"></param> /// <returns></returns> private IEnumerable <Students> GetStudents(int disciplineId, int wave) { using (var context = new CoursesOfChoiceEntities()) { var discipline = context.Disciplines.SingleOrDefault(disc => disc.id == disciplineId); if (discipline != null) { var groupList = discipline.Group; var existingGroups = groupList.SingleOrDefault(gr => gr.Deleted == false && gr.Wave == wave); var stInGroup = existingGroups?.StudentsInGroups; if (stInGroup != null) { var stList = from stInGr in stInGroup join student in context.Students on stInGr.studentID equals student.id where student.Deleted == false select student; return(stList.ToList()); } } return(new List <Students>()); } }
public IEnumerable <Users> GetUsers() { using (var context = new CoursesOfChoiceEntities()) { return(context.Users.ToList()); } }
public List <int> GetDisciplinesForSecondWave() { using (var context = new CoursesOfChoiceEntities()) { var groups = context.Group.Where(gr => gr.StudentsInGroups.Count >= 25 && gr.Wave == 1).ToList(); return(groups.Select(item => item.disciplinesID).ToList()); } }
public void DeleteGroups() { using (var context = new CoursesOfChoiceEntities()) { context.Group.ToList().ForEach(gr => gr.Deleted = true); context.SaveChanges(); } }
public Group GetGroupByDisciplinesId(int id, int wave) { using (var context = new CoursesOfChoiceEntities()) { var group = context.Group.SingleOrDefault(el => el.disciplinesID == id && el.Wave == wave && el.Deleted == false); return(group); } }
public Group GetGroupByDisciplinesId(int id) { using (var context = new CoursesOfChoiceEntities()) { var group = context.Group.Where(el => el.disciplinesID == id && el.Deleted == false).ToList(); return(group.SingleOrDefault()); } }
public IEnumerable <Students> GetStudents() { using (var context = new CoursesOfChoiceEntities()) { var students = context.Students.ToList(); return(students); } }
//public Administrators GetAdmin(string login) //{ // using (var context = new CoursesOfChoiceEntities()) // { // var admin = context.Administrators.SingleOrDefault(el => el.login == login); // return admin; // } //} public IEnumerable <Administrators> GetAdmins() { using (var context = new CoursesOfChoiceEntities()) { var adminList = context.Administrators; return(adminList.ToList()); } }
//!!!!!!!!!!!!!!!!!!!! public void AddStudentInGroups(StudentsInGroups sig) { using (var context = new CoursesOfChoiceEntities()) { context.StudentsInGroups.Add(sig); addAmountStudent(sig.groupID); context.SaveChanges(); } }
public IEnumerable <StudentsInGroups> GetStudentsInGroups() { using (var context = new CoursesOfChoiceEntities()) { var sig = context.StudentsInGroups.Where(el => el.Students.Deleted == false).ToList(); return(sig); } }
public IEnumerable <Disciplines> GetDisciplines() { using (var context = new CoursesOfChoiceEntities()) { var disciplines = context.Disciplines.ToList(); return(disciplines); } }
public Users GetUser(string login) { using (var context = new CoursesOfChoiceEntities()) { var user = context.Users.SingleOrDefault(el => el.login == login); return(user); } }
public IEnumerable <Group> GetGroups() { using (var context = new CoursesOfChoiceEntities()) { var groups = context.Group.Where(el => el.Deleted == false).ToList(); return(groups); } }
public void AddGroup(Group group) { using (var context = new CoursesOfChoiceEntities()) { context.Group.Add(group); context.SaveChanges(); } }
/// <summary> /// Get discipline which has id == id /// </summary> /// <param name="id"></param> /// <returns></returns> public Disciplines GetDiscipline(int id) { using (var context = new CoursesOfChoiceEntities()) { var disciplines = context.Disciplines.Where(d => d.id == id).ToList(); return(disciplines.SingleOrDefault()); } }
public void deleteAmountStudent(int groupID) { using (var context = new CoursesOfChoiceEntities()) { var gr = context.Group.SingleOrDefault(g => g.id == groupID); gr.AmountOfStudent--; context.SaveChanges(); } }
public Users UserLogIn(string login, string password) { //password = _hashProvider.Encrypt(password); using (var context = new CoursesOfChoiceEntities()) { Users user = context.Users.SingleOrDefault(el => el.login == login && el.password == password); return(user); } }
public bool DeleteAdmin(string login) { using (var context = new CoursesOfChoiceEntities()) { var admin = context.Administrators.SingleOrDefault(st => st.login == login); context.Administrators.Remove(admin); context.SaveChanges(); return(true); } }
public void DeleteStudentInGroups(StudentsInGroups sig) { using (var context = new CoursesOfChoiceEntities()) { var elToRemove = context.Set <StudentsInGroups>().SingleOrDefault(el => el.id == sig.id); context.Set <StudentsInGroups>().Remove(elToRemove); deleteAmountStudent(sig.groupID); context.SaveChanges(); } }
public void ChangeStudentEMail(string login, string newEMail) { using (var context = new CoursesOfChoiceEntities()) { var studentAcc = context.Students.SingleOrDefault(acc => acc.id == login); if (studentAcc != null) { studentAcc.eMail = newEMail; } context.SaveChanges(); } }
public void ChangeStudentPhone(string login, string newPhone) { using (var context = new CoursesOfChoiceEntities()) { var studentAcc = context.Students.SingleOrDefault(acc => acc.id == login); if (studentAcc != null) { studentAcc.phoneNumber = newPhone; } context.SaveChanges(); } }
public void ChangeUserPass(string login, string newPass) { using (var context = new CoursesOfChoiceEntities()) { var userAcc = context.Users.SingleOrDefault(acc => acc.login == login); if (userAcc != null) { userAcc.password = _hashProvider.Encrypt(newPass); } context.SaveChanges(); } }
public void ManUpGroupsForSecondWave() { using (var context = new CoursesOfChoiceEntities()) { var notRegisteredStd = (from std in context.Students join sig in context.StudentsInGroups on std.id equals sig.studentID into loj from l in loj.DefaultIfEmpty() where l == null orderby std.AverageMark descending select std).ToList(); // get IQueriable that have groupId and std count // all groups that have less then 25 std var smallSig = (from sig in context.StudentsInGroups group sig by sig.groupID into gSig //where gSig.Count() < 25 // && context.Group.Where(gr => gr.id == gSig.Key && gr.Wave == wave).FirstOrDefault().Deleted == false orderby gSig.Count() descending select new { GroupId = gSig.Key, Count = gSig.Count() }).ToList(); smallSig = smallSig.Where(si => { var firstOrDefault = context.Group.FirstOrDefault(gr => gr.id == si.GroupId); return(firstOrDefault != null && firstOrDefault.Deleted == false); }).ToList(); for (var i = 0; i < smallSig.Count; i++) { if (smallSig[i].Count < 25) { // students that's need to add to fill group int stdAmountToAdd = 25 - smallSig[i].Count; var stdToAdd = notRegisteredStd.GetRange(0, stdAmountToAdd); //fill this group with not registered student for (int j = 0; j < stdAmountToAdd; j++) { notRegisteredStd.Remove(stdToAdd[j]); context.StudentsInGroups.Add(new StudentsInGroups() { studentID = stdToAdd[j].id, groupID = smallSig[i].GroupId, DateOfRegister = DateTime.Now }); } } } context.SaveChanges(); } }
public void UpdateAdmin(Administrators adminAcc) { using (var context = new CoursesOfChoiceEntities()) { var admin = context.Administrators.SingleOrDefault(el => el.login == adminAcc.login); if (admin != null) { admin.roles = adminAcc.roles; } context.SaveChanges(); } }
public void DeleteMyDiscipline(int id, string login) { using (var context = new CoursesOfChoiceEntities()) { var sig = context.StudentsInGroups.Where(st => st.studentID == login).ToList(); foreach (var item in sig) { if (item.Group.Disciplines.id == id) { context.StudentsInGroups.Remove(item); context.SaveChanges(); } } } }
public bool CheckRegisteredStudent(string id) { using (var context = new CoursesOfChoiceEntities()) { var student = context.StudentsInGroups.SingleOrDefault(st => st.studentID == id); if (student == null) { return(false); } else { return(true); } } }
public bool CheckStudentForRegistered(Students st) { using (var context = new CoursesOfChoiceEntities()) { var listSig = context.StudentsInGroups.ToList(); int k = listSig.Count(item => item.studentID == st.id); if (k == 2) { return(true); } else { return(false); } } }
public IEnumerable <Disciplines> GetD(string login) { using (var context = new CoursesOfChoiceEntities()) { var sTinGroup = context.StudentsInGroups.Where(gr => gr.studentID == login); var groups = from gr in context.Group join sig in sTinGroup on gr.id equals sig.groupID select gr; var discplines = (from gr in groups join dic in context.Disciplines on gr.disciplinesID equals dic.id select dic).ToList(); return(discplines); } }