Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var scheduledTests = await _testInstancesRepository.GetAllTestInstancesOfTeacherAsync(_userId);

            if (scheduledTests == null)
            {
                return(NotFound());
            }
            var indexScheduledTestsViewModel = _mapper.Map <List <IndexScheduledTestViewModel> >(scheduledTests);

            foreach (var item in indexScheduledTestsViewModel)
            {
                item.GroupName = _groupsRepository.GetByIdAsync(item.GroupId).Result.Name;
            }
            return(View(indexScheduledTestsViewModel));
        }
        public IActionResult Details(Guid id)
        {
            var group = _groupsRepository.GetByIdAsync(id).Result;

            if (group == null)
            {
                return(NotFound());
            }
            var detailsGroupViewModel = _mapper.Map <DetailsGroupViewModel>(group);
            var userGroupsEnumerator  = new List <UserGroup>(group.UserGroups);
            var userList = new List <User>();

            foreach (var userGroup in userGroupsEnumerator)
            {
                userList.Add(userGroup.User);
            }

            var studentsList = Mapper.Map <List <DetailsStudentInGroup> >(userList);

            detailsGroupViewModel.Students = studentsList;
            return(View(detailsGroupViewModel));
        }
        public AddStudentToGroupValidator(IUsersRepository users, IUserContext user, IGroupsRepository groups)
        {
            _usersRepository = users;
            RuleFor(x => x.StudentName)
            .NotEmpty().WithMessage(string.Format(Consts.FieldEmptyMessage, "Student Name"))
            .MaximumLength(Consts.MaxLength)
            .WithMessage(string.Format(Consts.FieldMaximumLengthMessage, "Student Name", Consts.MaxLength));

            RuleFor(x => x).Custom((x, context) =>
            {
                var student = _usersRepository.GetStudentsByNamePrefixAsync(x.StudentName).Result;
                if (student.Count == 0)
                {
                    context.AddFailure("StudentName", "Student name is not valid");
                    return;
                }
                var group = groups.GetByIdAsync(x.GroupId).Result;
                if (null == group)
                {
                    context.AddFailure("", "Invalid group id");
                    return;
                }
                foreach (var userGroup in group.UserGroups)
                {
                    if (userGroup.User.UserName.Equals(x.StudentName))
                    {
                        context.AddFailure("StudentName", "This user is already in this group");
                        return;
                    }
                }
            });
            RuleFor(x => x.GroupId)
            .NotEmpty().WithMessage(string.Format(Consts.FieldEmptyMessage, "Group Id"))
            .Custom((x, context) =>
            {
                var groupsList = groups.GetAllAsync().Result.Where(a => a.Id == x).ToList();

                if (groupsList.Count == 0)
                {
                    context.AddFailure("Group Id", "Group Id is not valid");
                }
                else
                {
                    if (user.GetLogedInUserId() != groupsList[0].UserId)
                    {
                        context.AddFailure("Group Id", "Unauthorized");
                    }
                }
            });
        }
Ejemplo n.º 4
0
        public EditGroupValidator(IGroupsRepository groupsRepository)

        {
            _groupsRepository = groupsRepository;
            RuleFor(x => x.Name)
            .NotEmpty().WithMessage(string.Format(Consts.FieldEmptyMessage, "Name"))
            .MaximumLength(Consts.MaxLength)
            .WithMessage(string.Format(Consts.FieldMaximumLengthMessage, "Name", Consts.MaxLength));

            RuleFor(x => x.Description)
            .NotEmpty().WithMessage(string.Format(Consts.FieldEmptyMessage, "Description"))
            .MaximumLength(Consts.MaxLength)
            .WithMessage(string.Format(Consts.FieldMaximumLengthMessage, "Description", Consts.MaxLength));
            RuleFor(x => x).Custom((x, context) =>
            {
                var group = _groupsRepository.GetByIdAsync(x.Id).Result;
                if (group == null)
                {
                    context.AddFailure("Id", "Unauthorized");
                }
            });
        }