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 void RemoveDisciplineFromGroup(string groupId, string disciplineId) { var group = Repository.Find(SearchFilter <Group> .FilterById(groupId)).SingleOrDefault(); var discipline = _disciplineRepo.Find(SearchFilter <Discipline> .FilterById(disciplineId)).SingleOrDefault(); group.DisciplineSubscriptions = group.DisciplineSubscriptions.Where(el => el != discipline.Id).ToList(); Repository.Update(group.Id, group); }
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)); }
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 void AddDiscipline(string groupId, string disciplineId) { var group = Repository.Find(SearchFilter <Group> .FilterById(groupId)).SingleOrDefault(); var discipline = _disciplineRepo.Find(SearchFilter <Discipline> .FilterById(disciplineId)).SingleOrDefault(); if (group.DisciplineSubscriptions == null || group.DisciplineSubscriptions.All(el => el != disciplineId) && discipline.DisciplineType == Enums.DisciplineType.Special && (discipline.Semester == group.Course * 2 + 1 || discipline.Semester == group.Course * 2 + 2)) { group.DisciplineSubscriptions = group.DisciplineSubscriptions ?? new List <string>(); group.DisciplineSubscriptions.Add(disciplineId); Repository.Update(group.Id, group); } }
public bool UnregisterStudent(string studentId, string disciplineId) { var student = _userRepo.Find(SearchFilter <User> .FilterById(studentId)).SingleOrDefault(); var discipline = Find(SearchFilter <Discipline> .FilterById(disciplineId)).SingleOrDefault(); //add date validation student.Disciplines.Remove( student.Disciplines.SingleOrDefault(el => el.Id == disciplineId) ); try { _userRepo.Update(studentId, student); Update(disciplineId, discipline); } catch { return(false); } return(true); }
public bool TryAdd(User entity) { var loginExist = Find(new SearchFilter <User> { OptionList = new[] { new User { Login = entity.Login } } }).Any(); if (!loginExist) { if (entity.Roles.Any(el => el == Core.Enums.Enums.Role.Student)) { var group = _groupService.Find(SearchFilter <Group> .FilterById(entity.GroupId)).SingleOrDefault(); entity.Course = group.Course; } Add(entity); } return(!loginExist); }
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); }
// GET: Admin/group/Details/5 public ActionResult Details(string id) { var groups = Service.FindGroupResponce(SearchFilter <Group> .FilterById(id)); return(View(groups.SingleOrDefault())); }
// GET: Admin/Cathedra/Edit/5 public ActionResult Edit(string id) { var disciplines = Service.Find(SearchFilter <Cathedra> .FilterById(id)); return(View(disciplines.SingleOrDefault())); }
public Task <ApplicationUser> FindByIdAsync(string userId) { var user = Service.Find(SearchFilter <User> .FilterById(userId)).SingleOrDefault(); return(Task.FromResult(user != null ? new ApplicationUser(user) : null)); }