Ejemplo n.º 1
0
 public override void Validate(ValidationMessages messages)
 {
     var service = new TaxaService(PluginManager.Instance.User);
     if (!service.SafeToDeleteTaxon(Taxon.TaxaID.Value)) {
         messages.Warn("There are material and or associations that will be orphaned if you delete this taxon.");
     }
 }
Ejemplo n.º 2
0
        public bool ValidatePost(ValidationMessages messages)
        {
            if (string.IsNullOrEmpty(title))
            {
                messages.Add("WebProfile title missing. Use the title property to set the title of this WebProfile.");
                return(false);
            }

            if (string.IsNullOrEmpty(url))
            {
                messages.Add("WebProfile url missing. Use the url property to set the url of this WebProfile.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool ValidateUpdate(ValidationMessages messages)
        {
            if (id < 1)
            {
                messages.Add("GroupId missing. Use the id property to set the id of this group.");
                return(false);
            }

            if (string.IsNullOrEmpty(name))
            {
                messages.Add("Name missing. Use the name property to set your group name.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public bool ValidateClientCredentials(ValidationMessages messages)
        {
            if (string.IsNullOrEmpty(client_id))
            {
                messages.Add("ClientId missing. Use the client_id property to set the ClientId.");
                return(false);
            }

            if (string.IsNullOrEmpty(client_secret))
            {
                messages.Add("ClientSecret missing. Use the client_secret property to set the ClientSecret.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public Dictionary <string, string> Validate(UserAccount model)
        {
            var modelErrors = new Dictionary <string, string>();

            if (!ValidateUserName(model))
            {
                modelErrors.Add(nameof(UserAccount.UserName), ValidationMessages.ExistsValidation("User Name"));
            }

            if (!ValidateFullName(model))
            {
                modelErrors.Add(nameof(UserAccount.FullName), ValidationMessages.ExistsValidation("Full Name"));
            }

            return(modelErrors);
        }
Ejemplo n.º 6
0
        public override void Validate(TrsReductionRule validationInput)
        {
            if (validationInput.Head is TrsVariable)
            {
                ValidationMessages.Add(new InterpreterResultMessage
                {
                    Message     = "A reduction rule head may not only be a variable.",
                    MessageType = InterpreterMessageType.Error,
                    InputEntity = validationInput
                });
            }

            // All variables in tail must appear on head
            HashSet <TrsVariable> headVariables = new HashSet <TrsVariable>(validationInput.Head.GetVariables());
            HashSet <TrsVariable> tailVariables = new HashSet <TrsVariable>(validationInput.Tail.GetVariables());

            tailVariables.UnionWith(headVariables);
            if (tailVariables.Count != headVariables.Count)
            {
                ValidationMessages.Add(new InterpreterResultMessage
                {
                    Message     = "A reduction rule head must contain all variables that is in the reduction rule tail.",
                    MessageType = InterpreterMessageType.Error,
                    InputEntity = validationInput
                });
            }

            // Head validation
            if (validationInput.Head is TrsTermProduct)
            {
                foreach (var term in ((TrsTermProduct)validationInput.Head).TermList)
                {
                    termValidator.Validate(term);
                }
            }
            else
            {
                termValidator.Validate(validationInput.Head);
            }

            // The tail validation must take the case into account where the "native" keywork have been used
            if (validationInput.Tail.GetType() != typeof(TrsNativeKeyword))
            {
                termValidator.Validate(validationInput.Tail);
            }
            ValidationMessages.AddRange(termValidator.ValidationMessages);
        }
Ejemplo n.º 7
0
        public UpdateIngredientCommandValidator()
        {
            RuleFor(x => x.Id)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Id)));

            RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Name)));

            RuleFor(x => x.Shares)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(UpdateIngredientCommand.Shares)));

            RuleForEach(x => x.Shares).
            SetValidator(new MacroNutrientsSharesValidator());
        }
 private void UpdateValidationMessages(IEnumerable <ValidationResult> result)
 {
     if (result != null && result.Any())
     {
         result.ToList().ForEach(r =>
         {
             if (!ValidationMessages.ContainsKey(r.MemberNames.First()))
             {
                 ValidationMessages.Add(r.MemberNames.First(), r.ErrorMessage);
             }
             else
             {
                 ValidationMessages[r.MemberNames.First()] += Environment.NewLine + r.ErrorMessage;
             }
         });
     }
 }
        public ActionResult EditAuthor(Author author)
        {
            AuthorizeAndRedirect();
            Tuple <Author, AuthorValidation> authorTuple = _Manager.EditAuthor(author);

            if (authorTuple.Item1 != null)
            {
                ModelState.Clear();
                return(RedirectToAction("ListAuthorDetails", "Author", new { id = Convert.ToInt32(authorTuple.Item1.Aid) }));
            }
            ValidationMessages.ConvertCodeToMsg(ModelState, authorTuple.Item2.ErrorDict);
            if (author != null)
            {
                return(RedirectToAction("EditAuthor", "Author", new { id = Convert.ToInt32(author.Aid) }));
            }
            return(RedirectToAction("BrowseAllAuthors", "Author"));
        }
Ejemplo n.º 10
0
        private void parseSSN(string ssn)
        {
            if (string.IsNullOrEmpty(ssn.Trim()))
            {
                return;
            }

            if (!Regex.IsMatch(ssn, SSN_Pattern))
            {
                ValidationMessages.Add(InvalidFormat);
                return;
            }

            int start = ssn.Length - 4;

            SSN = ssn.Substring(start);
        }
        public RecipeDetailsValidator()
        {
            RuleFor(x => x.PreparationTime)
            .GreaterThanOrEqualTo(0)
            .WithMessage(ValidationMessages.GreaterThanOrEqualTo(nameof(RecipeInfo.PreparationTime), 0));

            RuleFor(x => x.ApproximateCost)
            .GreaterThanOrEqualTo(0)
            .WithMessage(ValidationMessages.GreaterThanOrEqualTo(nameof(RecipeInfo.PreparationTime), 0));

            RuleFor(x => x.DifficultyLevel)
            .GreaterThanOrEqualTo(0)
            .WithMessage(ValidationMessages.GreaterThanOrEqualTo(nameof(RecipeInfo.PreparationTime), 0));

            RuleFor(x => x.DifficultyLevel)
            .LessThanOrEqualTo(5)
            .WithMessage(ValidationMessages.LowerThanOrEqualTo(nameof(RecipeInfo.PreparationTime), 5));
        }
Ejemplo n.º 12
0
        public bool Validate()
        {
            bool ret = false;

            Entity.IsLoggedIn = false;
            ValidationMessages.Clear();
            if (string.IsNullOrEmpty(Entity.UserName))
            {
                AddValidationMessage("UserName", "User name must be filled in");
            }
            if (string.IsNullOrEmpty(Entity.Password))
            {
                AddValidationMessage("Password", "Password must be filled in");
            }

            ret = (ValidationMessages.Count == 0);
            return(ret);
        }
Ejemplo n.º 13
0
        public void Execute(RoutedEventArgs eventArgs)
        {
            ValidationMessages.Clear();
            var executeButton = eventArgs.Source as Button;

            if (executeButton != null)
            {
                _dispatcher = executeButton.Dispatcher;
                var client = BrightstarService.GetClient(Store.Source.ConnectionString);
                // Instead of blocking, start the job and a background thread to monitor it
                var expandedAddTriples    = GetExpandedTriples(AddTriples);
                var expandedDeleteTriples = GetExpandedDeletePatterns();
                _transactionJob = client.ExecuteTransaction(Store.Location, null, expandedDeleteTriples, expandedAddTriples, waitForCompletion: false);
                ValidationMessages.Add("Executing transaction. Please wait...");
                _dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                        new JobMonitorDelegate(this.CheckJobStatus));
            }
        }
Ejemplo n.º 14
0
        public override bool IsValid()
        {
            ValidationMessages.Clear();

            if (String.IsNullOrEmpty(FirstName))
            {
                ValidationMessages.Add("First Name should be provided.");
            }
            else
            {
                if (FirstName.Length < 2)
                {
                    ValidationMessages.Add("First Name should be more then 1 characters.");
                }
            }

            if (String.IsNullOrEmpty(LastName))
            {
                ValidationMessages.Add("Last Name should be provided.");
            }
            else
            {
                if (LastName.Length < 2)
                {
                    ValidationMessages.Add("Last Name should be more then 1 characters");
                }
            }

            if (!String.IsNullOrEmpty(MobileNumber) && (MobileNumber.Length != 10 || !Regex.IsMatch(MobileNumber, "[0-9]")))
            {
                ValidationMessages.Add("Mobile number should be of 10 digits.");
            }
            var validMemberships = (from membership in Memberships
                                    let currentTime = DateTime.UtcNow
                                                      where currentTime >= membership.MemberFrom && currentTime <= membership.MemberExpiry
                                                      select membership).Count();

            if (validMemberships > 1)
            {
                ValidationMessages.Add("Too many valid memberships found for the user.");
            }

            return(ValidationMessages.Count == 0);
        }
Ejemplo n.º 15
0
        public bool Validate()
        {
            ValidationMessages validationMessages = new ValidationMessages();

            string existingLocation = modelProperties.GetLocation(existing);

            RequiredLocationValidator <TModel> requiredLocation = new RequiredLocationValidator <TModel>(existingLocation);

            bool isValid = requiredLocation.Validate(modelProperties, update, validationMessages);

            isValid &= modelProperties.ValidateModel(update, validationMessages);

            if (!isValid)
            {
                validationMessages.Throw();
            }

            return(isValid);
        }
Ejemplo n.º 16
0
        public void ValidatePost()
        {
            var messages = new ValidationMessages();

            if (string.IsNullOrEmpty(Title))
            {
                messages.Add("Title missing. Use the title property to set your track title.");
            }

            if (PlaylistType == PlaylistType.Other)
            {
                messages.Add("Playlist type must not be 'other'.");
            }

            if (messages.HasErrors)
            {
                throw new SoundCloudValidationException(messages);
            }
        }
Ejemplo n.º 17
0
        public bool Validate()
        {
            bool ret = false;

            CurrentUser.IsLoggedIn = false;
            ValidationMessages.Clear();
            if (string.IsNullOrEmpty(CurrentUser.UserName))
            {
                AddApplicationExceptionMessage("UserName", "User Name Must Be Filled In");
            }
            if (string.IsNullOrEmpty(CurrentUser.Password))
            {
                AddApplicationExceptionMessage("Password", "Password Must Be Filled In");
            }

            ret = (ValidationMessages.Count == 0);

            return(ret);
        }
Ejemplo n.º 18
0
        public void ValidateUpdate()
        {
            var messages = new ValidationMessages();

            if (Id < 1)
            {
                messages.Add("PlaylistId missing. Use the id property to set the id of this playlist.");
            }

            if (string.IsNullOrEmpty(Title))
            {
                messages.Add("Title missing. Use the title property to set your track title.");
            }

            if (messages.HasErrors)
            {
                throw new SoundCloudValidationException(messages);
            }
        }
Ejemplo n.º 19
0
        public void ValidateClientCredentials()
        {
            var messages = new ValidationMessages();

            if (string.IsNullOrEmpty(ClientId))
            {
                messages.Add("ClientId missing. Use the client_id property to set the ClientId.");
            }

            if (string.IsNullOrEmpty(ClientSecret))
            {
                messages.Add("ClientSecret missing. Use the client_secret property to set the ClientSecret.");
            }

            if (messages.HasErrors)
            {
                throw new SoundCloudValidationException(messages);
            }
        }
Ejemplo n.º 20
0
        public void ValidatePassword()
        {
            var messages = new ValidationMessages();

            if (string.IsNullOrEmpty(UserName))
            {
                messages.Add("UserName не указан. Используй username свойство для установки UserName.");
            }

            if (string.IsNullOrEmpty(Password))
            {
                messages.Add("Password не указан. Используй password свойство для установки Password.");
            }

            if (messages.HasErrors)
            {
                throw new EasyMSValidationException(messages);
            }
        }
Ejemplo n.º 21
0
        public void WhenNameIsNotProvided_ThenThrowException()
        {
            var user = new User {
                Email = "*****@*****.**"
            };

            try
            {
                userValidator.Validate(user);
            }
            catch (Exception ex)
            {
                var fieldIsRequiredMessage = ValidationMessages.GetFieldIsRequiredMessage(nameof(User.Name));
                Assert.AreEqual(fieldIsRequiredMessage, ex.Message);
                return;
            }

            Assert.Fail("Should throw exception when email is not provided.");
        }
Ejemplo n.º 22
0
        internal void ValidatePost()
        {
            var messages = new ValidationMessages();

            if (TrackId < 1)
            {
                messages.Add("TrackId missing. Use the track_id property to set the TrackId of this comment.");
            }

            if (string.IsNullOrEmpty(Body))
            {
                messages.Add("Message missing. Use the body property to set your message.");
            }

            if (messages.HasErrors)
            {
                throw new SoundCloudValidationException(messages);
            }
        }
Ejemplo n.º 23
0
        public bool IsValid()
        {
            var valid = true;

            ValidationMessages.Clear();

            if (string.IsNullOrEmpty(Username))
            {
                valid = false;
                ValidationMessages.Add("Please enter a username!");
            }

            if (string.IsNullOrEmpty(Password))
            {
                valid = false;
                ValidationMessages.Add("Please enter a password!");
            }

            return(valid);
        }
Ejemplo n.º 24
0
        private void BuildErrorMessages()
        {
            try
            {
                this.ValidationMessages    = new List <string>();
                this.AllValidationMessages = string.Empty;

                if (this.HasError)
                {
                    this.ValidationMessages = this.Errors
                                              .Select(q => q.ErrorMessage)
                                              .ToList() ?? new List <string>();

                    this.AllValidationMessages = string.Join(" \r\n", ValidationMessages.ToArray()) ?? string.Empty;
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 25
0
        public void ValidateAllMethods()
        {
            Hierarchy hierarchy = HierarchyHelper.CreateDefaultHierarchy();

            ValidationMessages messages = new ValidationMessages();

            hierarchy.Enterprise.Site.Add(new Site {
                name = "Site X"
            });
            hierarchy.Enterprise.Site.Add(new Site {
                name = "Site X"
            });

            ValidateCommand command = new ValidateCommand(hierarchy, messages);

            command.Execute();
            Assert.That(messages, Is.Not.Empty);
            Assert.That(messages.Count, Is.EqualTo(1));
            Assert.That(messages[0].Message, Is.StringContaining("Site X"));
        }
        public ActionResult EditAdminPost(Admin admin)
        {
            if (!(admin.Username == Session["authentication"].ToString())) //Allow the user to change their own password even if not admin or higher
            {
                AuthorizeAndRedirect(Rank.Admin);
            }
            Admin oldAdmin = _Manager.GetAdmin(admin.Username);

            if ((Rank)Session["Level"] < Rank.SuperAdmin) //Don't allow changing of admin level or classification access if admin who edited is not superadmin
            {
                admin.PermissionLevel        = oldAdmin.PermissionLevel;
                admin.CanEditClassifications = oldAdmin.CanEditClassifications;
            }
            if (admin.Password == null)
            {
                admin.PasswordHash = oldAdmin.PasswordHash;
                admin.Salt         = oldAdmin.Salt;
                AdminValidation validation = _Manager.EditAdmin(admin, true);
                if (validation.IsValid)
                {
                    ViewData.ModelState.Clear();
                    return(RedirectToAction("AdminPanel", "Admin", null));
                }
                ValidationMessages.ConvertCodeToMsg(ModelState, validation.ErrorDict);
            }
            else
            {
                Hashing hashing = new Hashing(admin.Password);
                admin.PasswordHash = hashing.Hash;
                admin.Salt         = hashing.Salt;
                AdminValidation validation = _Manager.EditAdmin(admin);
                if (validation.IsValid)
                {
                    ViewData.ModelState.Clear();
                    return(RedirectToAction("AdminPanel", "Admin", null));
                }
                ValidationMessages.ConvertCodeToMsg(ModelState, validation.ErrorDict);
            }
            return(RedirectToAction("EditAdmin", new { id = admin.Username }));
        }
        public ActionResult Login(Admin admin, string returnBackTo = null)
        {
            Tuple <Admin, AdminValidation> validation = _Manager.Login(admin);

            if (validation.Item2.IsValid)
            {
                ViewData.ModelState.Clear();
                Session["authentication"]       = admin.Username;
                Session["level"]                = _Manager.GetPermissionLevel(admin.Username);
                Session["classificationEditor"] = validation.Item1.CanEditClassifications;
                if (String.IsNullOrEmpty(returnBackTo))
                {
                    return(RedirectToAction("index", "Home"));
                }
                return(Redirect(returnBackTo));
            }
            else
            {
                ValidationMessages.ConvertCodeToMsg(ModelState, validation.Item2.ErrorDict);
                return(RedirectToAction("Login", new { returnBackTo }));
            }
        }
Ejemplo n.º 28
0
        public void ValidateCreate()
        {
            var messages = new ValidationMessages();

            if (string.IsNullOrEmpty(OrganizationId))
            {
                messages.Add("OrganizationId пропущен. Используйте OrganizationId свойство чтобы установить organizationId.");
            }

            if (string.IsNullOrEmpty(OrderId))
            {
                messages.Add("OrderId пропущен. Используйте OrderId свойство чтобы установить orderId.");
            }

            if (string.IsNullOrEmpty(RoomReservationId))
            {
                messages.Add("RoomReservationId пропущен. Используйте RoomReservationId свойство чтобы установить roomReservationId.");
            }

            if (string.IsNullOrEmpty(BookerName))
            {
                messages.Add("BookerName пропущен. Используйте BookerName свойство чтобы установить bookerName.");
            }

            if (Value < 1)
            {
                messages.Add("Value пропущен. Используйте Value свойство чтобы установить value.");
            }

            if (PayMethod == PayMethod.None)
            {
                messages.Add("PayMethod не может быть 'none'.");
            }

            if (messages.HasErrors)
            {
                throw new EasyMSValidationException(messages);
            }
        }
Ejemplo n.º 29
0
        private void ValidateForCycles(Dictionary <TrsTypeDefinitionTypeName, List <TrsTypeDefinitionTypeName> > cycleTestGraph, bool isAcTermGraph = false)
        {
            var visitedNodes = new HashSet <TrsTypeDefinitionTypeName>();
            var childNodes   = new Stack <TrsTypeDefinitionTypeName>();

            foreach (var currentState in cycleTestGraph)
            {
                visitedNodes.Clear();
                childNodes.Clear();
                childNodes.Push(currentState.Key);
                while (childNodes.Count > 0)
                {
                    var currentPosition = childNodes.Pop();
                    if (visitedNodes.Contains(currentPosition))
                    {
                        ValidationMessages.Add(new InterpreterResultMessage
                        {
                            InputEntity = currentPosition,
                            Message     = isAcTermGraph ? "Found cycle in AC Term Type Graph for type name " + currentState.Key.ToSourceCode()
                : "Found cycle in type graph for type name " + currentState.Key.ToSourceCode(),
                            MessageType = InterpreterMessageType.Error
                        });
                        break;
                    }
                    else
                    {
                        visitedNodes.Add(currentPosition);
                        List <TrsTypeDefinitionTypeName> nextNodes = null;
                        if (cycleTestGraph.TryGetValue(currentPosition, out nextNodes))
                        {
                            foreach (var nextNode in nextNodes)
                            {
                                childNodes.Push(nextNode);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public bool ValidateRefreshToken(ValidationMessages messages)
        {
            if (string.IsNullOrEmpty(client_id))
            {
                messages.Add("ClientId missing. Use the client_id property to set the ClientId.");
                return(false);
            }

            if (string.IsNullOrEmpty(client_secret))
            {
                messages.Add("ClientSecret missing. Use the client_secret property to set the ClientSecret.");
                return(false);
            }

            if (string.IsNullOrEmpty(refresh_token))
            {
                messages.Add("RefreshToken missing. Use the refresh_token property to set the RefreshToken.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 31
0
        public bool ValidateAuthorizationCode(ValidationMessages messages)
        {
            if (string.IsNullOrEmpty(client_id))
            {
                messages.Add("ClientId missing. Use the client_id property to set the ClientId.");
                return(false);
            }

            if (string.IsNullOrEmpty(client_secret))
            {
                messages.Add("ClientSecret missing. Use the client_secret property to set the ClientSecret.");
                return(false);
            }

            if (string.IsNullOrEmpty(code))
            {
                messages.Add("Code missing. Use the code property to set the Code.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 32
0
        public override void Validate(ValidationMessages messages)
        {
            var list = new List<string>();

            if (string.IsNullOrEmpty(Taxon.Epithet)) {
                messages.Error("The name must not be blank");
            } else {
                if (Taxon.Epithet.Contains(" ") && !(Taxon.AvailableName.ValueOrFalse() || Taxon.LiteratureName.ValueOrFalse())) {
                    messages.Error("The name must be only one word.");
                }
            }

            if (Taxon.Unverified.ValueOrFalse() || Taxon.LiteratureName.ValueOrFalse()) {
                if (!string.IsNullOrEmpty(Taxon.YearOfPub)) {
                    int year;
                    if (Int32.TryParse(Taxon.YearOfPub, out year)) {
                        if (year < 1700 || year > 4000) {
                            messages.Error("The year must be between the years 1700 and 4000");
                        }
                    }
                }
            }
        }