Ejemplo n.º 1
0
        protected string GetPackTitle(Pack pack)
        {
            string packTitle = "";

            if (pack.PackTypeId == 1)
            {
                packTitle = "Лекции - ";

                foreach (var group in pack.Groups)
                {
                    packTitle += group.Name + " ";
                }
            }
            else if (pack.PackTypeId == 2)
            {
                packTitle = "Лаб. работы - " + pack.Groups[0].Name;
            }

            return packTitle;
        }
Ejemplo n.º 2
0
 protected string GetCourseName(Pack pack)
 {
     var course = db.Courses.Find(pack.CourseId);
     return GetCourseName(course);
 }
        private void AppendLabsPackModel(Pack pack, PackViewModel packViewModel)
        {
            var actualWorks = pack.WorkProcs.Where(l => l.CurrentValue.State == 0).ToList();

            foreach (var wp in actualWorks)
            {
                Work work = db.Works.Find(wp.WorkId);

                string workTitle = work.ShortName;

                packViewModel.Header.Items.Add(new Item() { Id = wp.Id, Title = workTitle, Span = work.HasThemes ? 2 : 1, Type = 1 });
            }

            var group = pack.Groups[0];

            var students = group.Students.OrderBy(s => s.Surname).ToList();

            foreach (var student in students)
            {

                var studentRow = packViewModel.Rows.First(r => r.Item.Id == student.Id);

                foreach (var workProc in actualWorks)
                {
                    StudentWorkProc studentWorkProc = workProc.GetStudentWorkProc(student);

                    if(studentWorkProc == null)
                    {
                        studentRow.Items.Add(new Item() { Id = 0, Type = -1 });
                        continue;
                    }

                    Work work = db.Works.Find(studentWorkProc.WorkProc.WorkId);

                    if (work.HasThemes)
                    {
                        string themeName;

                        if (studentWorkProc.CurrentValue.WorkThemeId != null)
                        {
                            themeName = db.WorkThemes.Find(studentWorkProc.CurrentValue.WorkThemeId).Name;
                        }
                        else
                        {
                            themeName = "Нет темы";
                        }

                        studentRow.Items.Add(new Item()
                        {
                            Id = studentWorkProc.Id,
                            Type = 2,
                            Title = themeName
                        });
                    }

                    studentRow.Items.Add(new Item()
                    {
                        Id = studentWorkProc.Id,
                        Type = 1,
                        Title = GetStudentWorkProcTitle(studentWorkProc),
                        Progress = GetStudentWorkProcProgress(studentWorkProc)
                    });

                }
            }
        }
Ejemplo n.º 4
0
        public Course CreateCourse(int userId, NewCourseModel newCourseModel)
        {
            Course course = new Course()
            {
                UserId = userId,
                TermId = newCourseModel.TermId,
                Year = newCourseModel.Year,
                CourseStateId = 1
            };

            db.Courses.Add(course);

            var rand = new Random((int)new DateTime().Ticks);

            for (int i = 0; i < newCourseModel.WorksCount; i++)
            {
                Work work = new Work()
                {
                    Name = RandomString(9),
                    ShortName = RandomString(3),
                    WorkType = db.WorkTypes.Find(1),
                    WorkControlType = db.WorkControlTypes.Find(1),
                    Course = course
                };

                db.Works.Add(work);

                //create stages
                //int stagesCount = rand.Next(5) + 2;
                int stagesCount = 1;

                for (int s = 0; s < stagesCount; s++)
                {
                    WorkStage ws = new WorkStage()
                    {
                        Name = RandomString(10),
                        Work = work
                    };

                    db.WorkStages.Add(ws);

                    //bool addSubStages = rand.Next(10) > 7;
                    bool addSubStages = false;

                    if(addSubStages)
                    {
                        int substages = rand.Next(3) + 2;

                        for(int j = 0; j < substages; j++)
                        {
                            WorkStage subStage = new WorkStage()
                            {
                                Name = RandomString(10),
                                Work = work,
                                ParentStage = ws
                            };

                            db.WorkStages.Add(subStage);

                        }
                    }
                }

                course.Works.Add(work);
            }

            course.Packs = new List<Pack>();

            if (newCourseModel.LessonPackGroupIds != null)
            {
                Pack pack = new Pack()
                {
                    Course = course,
                    PackType = db.PackTypes.Find(1),
                    Groups = db.Groups.Where(g => newCourseModel.LessonPackGroupIds.Contains(g.Id)).ToList()
                };
                course.Packs.Add(pack);
            }

            if (newCourseModel.LabsGroupIds != null)
            {
                foreach (var groupId in newCourseModel.LabsGroupIds)
                {
                    Pack pack = new Pack()
                    {
                        Course = course,
                        PackType = db.PackTypes.Find(2),
                        Groups = db.Groups.Where(g => g.Id == groupId).ToList()
                    };
                    course.Packs.Add(pack);
                }
            }

            db.SaveChanges();

            return course;
        }
        private PackViewModel CreateLessonsPackModel(Pack pack, int groupIndex, string titleString)
        {
            var title = new Item() { Title = titleString };

            PackViewModel packViewModel = null;

            var actualLessons = pack.Lessons.Where(l => l.CurrentValue.State == 0).OrderBy(l => l.Date).ToList();

            var headerItems = actualLessons.Select(l => new Item() { Id = l.Id, Title = GetLessonTitle(l), Type = 0 }).ToList();

            var header = new Header() { Items = headerItems };

            //init rows

            List<Row> rows = new List<Row>();

            var group = pack.Groups[groupIndex];

            var students = group.Students.OrderBy(s => s.Surname).ToList();

            foreach (var student in students)
            {
                string studentTitle = GetStudentTitle(student);
                var studentRow = new Row()
                {
                    Item = new Item() { Id = student.Id, Title = studentTitle },
                    Items = new List<Item>()
                };

                foreach (var lesson in actualLessons)
                {
                    Visit visit = lesson.GetVisitForStudent(student);
                    //todo: предусмотреть возможность отсутствия посещения как такового

                    if (visit != null)
                    {
                        studentRow.Items.Add(new Item() { Id = visit.Id, Title = GetVisitTitle(visit), Value = (int)visit.CurrentValue.Value });
                    }
                    else
                    {
                        studentRow.Items.Add(new Item() { Id = 0, Type = -1 });
                    }

                }

                rows.Add(studentRow);
            }

            packViewModel = new PackViewModel() { Title = title, Header = header, Rows = rows };

            return packViewModel;
        }