Exemplo n.º 1
0
        public void AddUserToGroup(HomeServerContext context, int studentId, int groupId, DateTime date)
        {
            Student student = context.Students.Find(studentId);
            Group group = context.Groups.Find(groupId);

            if (student == null)
                return;

            if (group == null)
                return;

            if(group.Students.Contains(student))
                return;

            student.GroupId = group.Id;

            //get active packs for this group
            var temp = context.Packs.Where(p => p.Course.CourseStateId == 2).ToList();

            List<Pack> packs = new List<Pack>();

            foreach(var t in temp)
            {
                foreach(var g in t.Groups)
                {
                    if (g.Id == groupId)
                    {
                        packs.Add(t);
                    }
                }
            }

            //add visits and studentProcs for each packs
            foreach(var pack in packs)
            {
                foreach(var lesson in pack.Lessons)
                {
                    if(lesson.Date < date)
                        continue;

                    lesson.Visits.Add(new Visit()
                    {
                        StudentId = student.Id,
                        Values = new List<VisitValue>()
                        {
                            new VisitValue()
                            {
                                Value = VisitValue.DEFAULT_VALUE,
                                Version = 1
                            }
                        }
                    });
                }

                foreach(var workProc in pack.WorkProcs)
                {
                    var work = context.Works.Find(workProc.WorkId);
                    work.WorkStages = context.WorkStages.Where(ws => ws.WorkId == workProc.WorkId).ToList();

                    StudentWorkProc studentProc = new StudentWorkProc()
                    {
                        StudentId = student.Id,
                        Values = new List<StudentWorkProcValue>() { new StudentWorkProcValue() { Version = 1 } },
                        StudentStageProcs = new List<StudentStageProc>()
                    };

                    foreach (var workStage in work.WorkStages)
                    {
                        studentProc.StudentStageProcs.Add(new StudentStageProc()
                        {
                            WorkStageId = workStage.Id,
                            Values = new List<StudentStageProcValue>() { new StudentStageProcValue() { Version = 1 } }
                        });
                    }

                    workProc.StudentWorkProcs.Add(studentProc);
                }
            }

            StudentTransaction studentTransaction = new StudentTransaction()
            {
                Student = student,
                Group = group,
                Date = date
            };

            context.StudentTransaction.Add(studentTransaction);

            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void RemoveUserFromGroup(HomeServerContext context, int studentId)
        {
            Student student = context.Students.Find(studentId);

            if (student == null)
            {
                return;
            }
            else
            {
                student.GroupId = null;

                StudentTransaction studentTransaction = new StudentTransaction()
                {
                    Student = student,
                    GroupId = null,
                    Date = DateTime.Now
                };

                context.StudentTransaction.Add(studentTransaction);

                context.SaveChanges();
            }
        }