コード例 #1
0
        public ActionResult SelectFlow(SelectFlowViewModel viewModel)
        {
            var groupSets = UnitOfWork.Repository <GroupSet>()
                            .Get(x => x.ApplicationUserId == UserProfile.Id)
                            .ToList();

            foreach (var groupSet in groupSets)
            {
                groupSet.IsSelected = false;
                UnitOfWork.Repository <GroupSet>().Update(groupSet);
            }

            var groupSetGroups = viewModel.Groups
                                 .Select(x => new GroupSetGroup
            {
                GroupSetId = viewModel.GroupSetId,
                GroupId    = x.GroupId,
                Order      = x.Order ?? 0
            })
                                 .ToList();

            var currentGroupSet = groupSets.SingleOrDefault(x => x.GroupSetId == viewModel.GroupSetId);

            if (currentGroupSet == null)
            {
                currentGroupSet = new GroupSet
                {
                    ApplicationUserId = UserProfile.Id,
                    GroupSetName      = viewModel.GroupSetName
                };

                UnitOfWork.Repository <GroupSet>().Insert(currentGroupSet);
            }
            else
            {
                UnitOfWork.Repository <GroupSetGroup>().DeleteRange(x => x.GroupSetId == currentGroupSet.GroupSetId);
                UnitOfWork.Repository <GroupSet>().Update(currentGroupSet);
            }

            currentGroupSet.GroupSetGroups = groupSetGroups;
            currentGroupSet.IsSelected     = true;
            UnitOfWork.Save();

            return(Json(new { result = "Redirect", url = Url.Action("Index", "Home") }));
        }
コード例 #2
0
        public ActionResult SelectFlowData(int?groupSetId)
        {
            if (!Request.IsAjaxRequest())
            {
                return(new HttpStatusCodeResult(404));
            }

            var viewModel = new SelectFlowViewModel
            {
                GroupSets = new List <GroupSetViewModel>(),
                Groups    = new List <GroupViewModel>()
            };

            if (groupSetId != null)
            {
                var groupsSet = UserProfile.GroupSets
                                .SingleOrDefault(x => x.GroupSetId == groupSetId);
                if (groupsSet != null)
                {
                    viewModel.GroupSetName = groupsSet.GroupSetName;

                    var firstGroup       = groupsSet.GroupSetGroups.First();
                    var facultyId        = firstGroup.Group.Course.FacultyId;
                    var educationFormId  = firstGroup.Group.ProgramOfEducation.EducationFormId;
                    var educationLevelId = firstGroup.Group.ProgramOfEducation.EducationLevelId;
                    var courseNumber     = firstGroup.Group.Course.CourseNumber;

                    viewModel.FacultyId        = facultyId;
                    viewModel.EducationFormId  = educationFormId;
                    viewModel.EducationLevelId = educationLevelId;
                    viewModel.CourseNumber     = courseNumber;

                    viewModel.CourseNumbers = UnitOfWork.Repository <Course>()
                                              .GetQ(
                        filter: x => x.IsDeleted != true && x.FacultyId == facultyId && x.YearStart != null &&
                        x.Groups.Any(g => g.ProgramOfEducation.EducationFormId == educationFormId &&
                                     g.ProgramOfEducation.EducationLevelId == educationLevelId &&
                                     g.IsDeleted != true) &&
                        x.YearStart + x.CourseNumber == UserProfile.EducationYear.YearEnd,
                        orderBy: o => o.OrderBy(n => n.CourseNumber))
                                              .Select(x => x.CourseNumber)
                                              .Distinct()
                                              .ToList();

                    var groups = UnitOfWork.Repository <Group>()
                                 .GetQ(
                        filter: x => x.IsDeleted != true && x.Course.FacultyId == facultyId &&
                        x.ProgramOfEducation.EducationFormId == educationFormId &&
                        x.ProgramOfEducation.EducationLevelId == educationLevelId &&
                        UserProfile.EducationYear.YearStart - x.Course.YearStart + 1 == courseNumber,
                        orderBy: o => o.OrderBy(n => n.DivisionName));
                    foreach (var group in groups)
                    {
                        var groupViewModel = new GroupViewModel
                        {
                            GroupId   = group.GroupId,
                            GroupName = group.DivisionName
                        };

                        var groupSetGroup = groupsSet.GroupSetGroups.SingleOrDefault(g => g.GroupId == group.GroupId);
                        if (groupSetGroup != null)
                        {
                            groupViewModel.IsSelected = true;
                            groupViewModel.Order      = groupSetGroup.Order;
                        }

                        viewModel.Groups.Add(groupViewModel);
                    }
                }
            }
            else
            {
                viewModel.EducationFormId = (int)EducationForms.FullTime;

                var groupSets = UserProfile.GroupSets
                                .Select(x => new GroupSetViewModel
                {
                    GroupSetId   = x.GroupSetId,
                    GroupSetName = x.GroupSetName,
                    GroupNames   = String.Join(", ", x.GroupSetGroups.OrderBy(o => o.Order).Select(g => g.Group.DivisionName))
                })
                                .ToList();
                viewModel.GroupSets = groupSets;

                if (User.IsInRole("Administrator"))
                {
                    viewModel.Faculties = UnitOfWork.Repository <Faculty>()
                                          .GetQ(f => f.IsDeleted != true, orderBy: o => o.OrderBy(n => n.DivisionName))
                                          .Select(x => new FacultyViewModel {
                        FacultyId = x.FacultyId, FacultyName = x.DivisionName
                    })
                                          .ToList();
                }
                else
                {
                    viewModel.Faculties = UserProfile.Faculties
                                          .Select(x => new FacultyViewModel {
                        FacultyId = x.FacultyId, FacultyName = x.DivisionName
                    })
                                          .OrderBy(n => n.FacultyName)
                                          .ToList();
                }

                viewModel.EducationLevels = UnitOfWork.Repository <EducationLevel>()
                                            .Get(x => x.IsDeleted != true)
                                            .Select(x => new EducationLevelViewModel {
                    EducationLevelId = x.EducationLevelId, EducationLevelName = x.EducationLevelName
                })
                                            .ToList();

                viewModel.EducationForms = UnitOfWork.Repository <EducationForm>()
                                           .GetQ(x => x.IsDeleted != true)
                                           .Select(x => new EducationFormViewModel {
                    EducationFormId = x.EducationFormId, EducationFormName = x.EducationFormName
                })
                                           .ToList();
            }

            return(Json(viewModel));
        }