コード例 #1
0
        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));
        }
コード例 #2
0
 /// <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);
         }
     }
 }
コード例 #3
0
        /// <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>());
            }
        }
コード例 #4
0
 public IEnumerable <Users> GetUsers()
 {
     using (var context = new CoursesOfChoiceEntities())
     {
         return(context.Users.ToList());
     }
 }
コード例 #5
0
 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());
     }
 }
コード例 #6
0
 public void DeleteGroups()
 {
     using (var context = new CoursesOfChoiceEntities())
     {
         context.Group.ToList().ForEach(gr => gr.Deleted = true);
         context.SaveChanges();
     }
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 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());
     }
 }
コード例 #9
0
        public IEnumerable <Students> GetStudents()
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                var students = context.Students.ToList();

                return(students);
            }
        }
コード例 #10
0
        //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());
            }
        }
コード例 #11
0
 //!!!!!!!!!!!!!!!!!!!!
 public void AddStudentInGroups(StudentsInGroups sig)
 {
     using (var context = new CoursesOfChoiceEntities())
     {
         context.StudentsInGroups.Add(sig);
         addAmountStudent(sig.groupID);
         context.SaveChanges();
     }
 }
コード例 #12
0
        public IEnumerable <StudentsInGroups> GetStudentsInGroups()
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                var sig = context.StudentsInGroups.Where(el => el.Students.Deleted == false).ToList();

                return(sig);
            }
        }
コード例 #13
0
        public IEnumerable <Disciplines> GetDisciplines()
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                var disciplines = context.Disciplines.ToList();

                return(disciplines);
            }
        }
コード例 #14
0
        public Users GetUser(string login)
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                var user = context.Users.SingleOrDefault(el => el.login == login);

                return(user);
            }
        }
コード例 #15
0
        public IEnumerable <Group> GetGroups()
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                var groups = context.Group.Where(el => el.Deleted == false).ToList();

                return(groups);
            }
        }
コード例 #16
0
        public void AddGroup(Group group)
        {
            using (var context = new CoursesOfChoiceEntities())
            {
                context.Group.Add(group);

                context.SaveChanges();
            }
        }
コード例 #17
0
        /// <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());
            }
        }
コード例 #18
0
 public void deleteAmountStudent(int groupID)
 {
     using (var context = new CoursesOfChoiceEntities())
     {
         var gr = context.Group.SingleOrDefault(g => g.id == groupID);
         gr.AmountOfStudent--;
         context.SaveChanges();
     }
 }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
 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);
     }
 }
コード例 #21
0
        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();
            }
        }
コード例 #22
0
 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();
     }
 }
コード例 #23
0
 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();
     }
 }
コード例 #24
0
 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();
     }
 }
コード例 #25
0
        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();
            }
        }
コード例 #26
0
        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();
            }
        }
コード例 #27
0
 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();
             }
         }
     }
 }
コード例 #28
0
 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);
         }
     }
 }
コード例 #29
0
 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);
         }
     }
 }
コード例 #30
0
        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);
            }
        }