public IEnumerable <GroupDisciplineModel> GetGroupDisciplines(string id) { var group = Repository.Find(SearchFilter <Group> .FilterById(id)).SingleOrDefault(); var disciplines = group.DisciplineSubscriptions.Any() ? _disciplineRepo.Find(SearchFilter <Discipline> .FilterByIds(group.DisciplineSubscriptions)) : new List <Discipline>(); List <User> lecturers = new List <User>(); List <Cathedra> cathedras = new List <Cathedra>(); if (disciplines.Any()) { var userIds = disciplines.Select(el => el.LecturerId); lecturers = _userRepo.Find(SearchFilter <User> .FilterByIds(userIds)); var cathedraIds = disciplines.Select(el => el.ProviderCathedraId); cathedras = _cathedraRepo.Find(SearchFilter <Cathedra> .FilterByIds(cathedraIds)); } return(disciplines.Select(d => new GroupDisciplineModel { Id = d.Id, Name = d.Name, DisciplineType = d.DisciplineType, Semester = d.Semester, Description = d.Description, Lecturer = lecturers.SingleOrDefault(el => el.Id == d.LecturerId)?.UserName, ProviderCathedra = cathedras.SingleOrDefault(el => el.Id == d.ProviderCathedraId)?.Name })); }
public List <GroupDisciplineModel> FindDisciplineResponse(SearchFilter <Discipline> filter) { var disciplines = Repository.Find(filter); List <User> lecturers = new List <User>(); List <Cathedra> cathedras = new List <Cathedra>(); if (disciplines.Any()) { var userIds = disciplines.Select(el => el.LecturerId); lecturers = _userRepo.Find(SearchFilter <User> .FilterByIds(userIds)); var cathedraIds = disciplines.Select(el => el.ProviderCathedraId); cathedras = _cathedraRepo.Find(SearchFilter <Cathedra> .FilterByIds(cathedraIds)); } var disciplinesCount = GetDisciplinesCount(disciplines.Select(el => el.Id)); return(disciplines.Select(d => new GroupDisciplineModel { Id = d.Id, Name = d.Name, DisciplineType = d.DisciplineType, Semester = d.Semester, Description = d.Description, Lecturer = lecturers.SingleOrDefault(el => el.Id == d.LecturerId)?.UserName, ProviderCathedra = cathedras.SingleOrDefault(el => el.Id == d.ProviderCathedraId)?.Name, Count = disciplinesCount.SingleOrDefault(el => el.Id == d.Id)?.Count ?? 0 }).ToList()); }
public ActionResult MyDisciplines() { var user = ServiceFactory.UserService.Find(SearchFilter <User> .FilterById(UserId)).SingleOrDefault(); var disciplines = user.Disciplines.Any() ? Service.FindDisciplineResponse(SearchFilter <Discipline> .FilterByIds(user.Disciplines.Select(el => el.Id))) : new List <GroupDisciplineModel>(); return(View(disciplines)); }
private void SetDataToViewBag(User user) { ViewBag.User = user; ViewBag.UserDisciplines = user.Disciplines != null && user.Disciplines.Any() ? Service.Find(SearchFilter <Discipline> .FilterByIds(user.Disciplines.Select(el => el.Id))) : new List <Discipline>(); //var settings = ServiceFactory.SettingService.Find(SearchFilter<Setting>.Empty); //ViewBag.Start = settings.SingleOrDefault(s => s.Name == Constants.StartDate); //ViewBag.First = settings.SingleOrDefault(s => s.Name == Constants.FirstDeadline); //ViewBag.Second = settings.SingleOrDefault(s => s.Name == Constants.SecondDeadline); }
public IEnumerable <Discipline> GetNotSubscribedDisciplines(string id) { var group = Repository.Find(SearchFilter <Group> .FilterById(id)).SingleOrDefault(); var assignedDisciplines = group.DisciplineSubscriptions.Any() ? _disciplineRepo.Find(SearchFilter <Discipline> .FilterByIds(group.DisciplineSubscriptions)) : new List <Discipline>(); var filter = SearchFilter <Discipline> .Empty; filter.OptionList = FilterHelper.SpecialDisciplines(group.Course.Value); var disciplines = _disciplineRepo .Find(filter) .Where(el => assignedDisciplines.All(ad => ad.Id != el.Id)); return(disciplines); }
public IEnumerable <GroupResponce> FindGroupResponce(SearchFilter <Group> filter) { IEnumerable <GroupResponce> result = new List <GroupResponce>(); List <Cathedra> cathedras = new List <Cathedra>(); var groups = Find(filter); var cathedraIds = groups.Select(g => g.CathedraId).Distinct().ToList(); if (cathedraIds != null && cathedraIds.Any()) { cathedras = _cathedraRepo.Find(SearchFilter <Cathedra> .FilterByIds(cathedraIds)); } result = groups.Select(g => new GroupResponce(g) { Cathedra = cathedras.SingleOrDefault(c => c.Id == g.CathedraId) }); return(result); }
public StudentDisciplines GetDisciplines(DisciplineType type) { var user = ServiceFactory.UserService.Find(SearchFilter <User> .FilterById(UserId)).SingleOrDefault(); var group = _groupService.Find(SearchFilter <Group> .FilterById(user.GroupId)).SingleOrDefault(); var filter = SearchFilter <Discipline> .Empty; filter.OptionList = type == DisciplineType.Socio ? FilterHelper.SocialDisciplines(user.Course.Value, true) : FilterHelper.SpecialDisciplines(user.Course.Value, group.DisciplineSubscriptions, true); var disciplines = Service.FindDisciplineResponse(filter); var userDisciplines = user.Disciplines != null && user.Disciplines.Any() ? Service.Find(SearchFilter <Discipline> .FilterByIds(user.Disciplines.Select(el => el.Id))) : new List <Discipline>(); var deadlines = _settingsSerivice.Find(SearchFilter <Setting> .Empty); var settings = group.DisciplineConfiguration; DisciplineConfiguration firstSemester = settings.SingleOrDefault(el => el.Semester % 2 == 1 && el.DisciplineType == type); DisciplineConfiguration secondSemester = settings.SingleOrDefault(el => el.Semester % 2 == 0 && el.DisciplineType == type); List <Discipline> userSocioDisciplines = userDisciplines.Where(ud => ud.DisciplineType == type).ToList(); var start = deadlines.SingleOrDefault(el => el.Name == Constants.StartDate)?.Value; var first = deadlines.SingleOrDefault(el => el.Name == Constants.FirstDeadline)?.Value; var second = deadlines.SingleOrDefault(el => el.Name == Constants.SecondDeadline)?.Value; bool checkTime = CheckTime(start, first, second); disciplines.ForEach(d => { d.IsLocked = user.Disciplines.Any(di => di.Id == d.Id && di.Locked); d.Registered = user.Disciplines.Any(di => di.Id == d.Id); d.CanRegister = CanRegister(d, firstSemester, secondSemester, userSocioDisciplines) && checkTime; }); return(new StudentDisciplines { Disciplines = disciplines.OrderByDescending(el => el.Count).ToList(), Type = DisciplineType.Socio, }); }
public bool TryRegisterStudent(string studentId, string disciplineId) { var result = false; var student = _userRepo.Find(SearchFilter <User> .FilterById(studentId)).SingleOrDefault(); var group = _groupRepo.Find(SearchFilter <Group> .FilterById(student.GroupId)).SingleOrDefault(); var discipline = Find(SearchFilter <Discipline> .FilterById(disciplineId)).SingleOrDefault(); if (student.Roles.Contains(Role.Student) && discipline != null && discipline.IsAvailable.Value) { var studentDiscIds = student.Disciplines.Select(el => el.Id); var disciplines = studentDiscIds.Any() ? Find(SearchFilter <Discipline> .FilterByIds(studentDiscIds)) : new List <Discipline>(); var registerLimt = group.DisciplineConfiguration .Single(el => el.Semester % 2 == discipline.Semester % 2 && el.DisciplineType == discipline.DisciplineType) .RequiredAmount; var disciplineCount = GetDisciplinesCount(new string[] { disciplineId }) .SingleOrDefault(el => el.Id == disciplineId)?.Count ?? 0; if (disciplines.Count(d => d.DisciplineType == discipline.DisciplineType && discipline.Semester == d.Semester) < registerLimt && student.Disciplines.All(el => el.Id != disciplineId) && disciplineCount < Constants.DisciplineMaxCapacity) { student.Disciplines.Add(new DisciplineModel { Id = disciplineId }); _userRepo.Update(studentId, student); result = true; } } return(result); }