protected override void Validate(IValidationContext validationContext, TaskCompleteViewModel model)
        {
            var lecture = validationContext.GetRequiredService <ILectureService>()
                          .FirstOrDefault(x => x.Id == model.LectureId);

            validationContext.Validate(model, m => m.LectureId)
            .If(() => lecture == null)
            .Add <TaskViewModelValidationComponent>(c => c.InvalidLecture);

            validationContext.Validate(model, m => m.LectureId)
            .When(() => !lecture.IsPractice)
            .Add <TaskViewModelValidationComponent>(c => c.LectureIsNotAPractice);
        }
Exemplo n.º 2
0
 private void RunContext(IValidationContext context)
 {
     for (var i = 0; i < N; ++i)
     {
         _results[i] = context.Validate(_models[i]);
     }
 }
Exemplo n.º 3
0
        public IActionResult SignUp(SignUpModel signUpModel)
        {
            var validationResult = _signUpValidationContext.Validate(signUpModel);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.ToModelReport()));
            }

            return(Ok());
        }
Exemplo n.º 4
0
        public IActionResult Login(LoginModel loginModel)
        {
            var validationResult = _loginModelValidationContext.Validate(loginModel);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.ToModelReport()));
            }

            return(Ok());
        }
Exemplo n.º 5
0
        protected override void Validate(IValidationContext validationContext, CreateProfileRequestViewModel model)
        {
            validationContext.Validate(model, m => m.Name)
            .If(() => string.IsNullOrWhiteSpace(model.Name))
            .Add <CreateProfileRequestValidationSection>(x => x.NameMustBeSet);

            validationContext.Validate(model, m => m.Name)
            .When(() => model.Name.Length < 2)
            .Add <CreateProfileRequestValidationSection>(x => x.TooShortName);

            validationContext.Validate(model, m => m.Name)
            .When(() => model.Name.Length > 30)
            .Add <CreateProfileRequestValidationSection>(x => x.TooLongName);

            validationContext.Validate(model, m => m.Group)
            .If(() => string.IsNullOrWhiteSpace(model.Group))
            .Add <CreateProfileRequestValidationSection>(x => x.GroupMustBeSet);

            model.Group = model.Group?.ToUpper();

            validationContext.Validate(model, m => m.Group)
            .When(() => !Regex.IsMatch(model.Group ?? "", @"^[аисбоАИСБО]{4}-\d\d-\d\d"))
            .Add <CreateProfileRequestValidationSection>(x => x.GroupPattern);
        }