public AdminValidation(Admin model, bool PasswordNotEdited = false) //PasswordNotEdited is only true if the user typed in something in the password entry of the form. { //Otherwise password remains unchanged. if (string.IsNullOrWhiteSpace(model.Username)) { ErrorDict.Add(nameof(model.Username), ErrorCodes.IsRequired); } else if (model.Username.Length > MAX_USERNAME_LENGTH) { ErrorDict.Add(nameof(model.Username), ErrorCodes.TooLong); } if (!PasswordNotEdited) { if (string.IsNullOrWhiteSpace(model.Password)) { ErrorDict.Add(nameof(model.Password), ErrorCodes.IsRequired); } else if (!Regex.IsMatch(model.Password, PASSWORD_REQ_REGEX)) { ErrorDict.Add(nameof(model.Password), ErrorCodes.PasswordDoesNotMatch); } } if (ErrorDict.Count == 0) { IsValid = true; } }
public ClassificationValidation(Classification model) { if (String.IsNullOrWhiteSpace(model.Signum)) { ErrorDict.Add(nameof(model.Signum), ErrorCodes.IsRequired); } else if (model.Signum.Length > NAME_MAX_LENGTH) { ErrorDict.Add(nameof(model.Signum), ErrorCodes.MoreThanFiftyChars); } if (string.IsNullOrWhiteSpace(model.Description)) { ErrorDict.Add(nameof(model.Description), ErrorCodes.IsRequired); } else if (model.Description.Length > DESCRIPTION_MAX_LENGTH) { ErrorDict.Add(nameof(model.Description), ErrorCodes.MoreThanFiveHundredChars); } if (ErrorDict.Count == 0) { IsValid = true; } }
public AuthorValidation(Author model) { if (!string.IsNullOrWhiteSpace(model.FirstName)) { if (model.FirstName.Length > MAX_NAME_LENGTH) { ErrorDict.Add(nameof(model.FirstName), ErrorCodes.TooLong); } } if (string.IsNullOrWhiteSpace(model.LastName)) { ErrorDict.Add(nameof(model.LastName), ErrorCodes.IsRequired); } else if (model.LastName.Length > MAX_NAME_LENGTH) { ErrorDict.Add(nameof(model.LastName), ErrorCodes.TooLong); } if (model.BirthYear != null) { if (model.BirthYear < MIN_BIRTH_YEAR || model.BirthYear > DateTime.Now.Year - 5) { ErrorDict.Add(nameof(model.BirthYear), ErrorCodes.InvalidRange); } } if (ErrorDict.Count == 0) { IsValid = true; } }
/// <summary> /// Register a single command /// </summary> /// <param name="cmdName"></param> /// <param name="cmd"></param> internal void RegisterErrorCommand(string cmdName, CommandOperand cmd) { var name = new NameOperand(); name.Value = cmdName; cmd.Name = $"build-in:{cmdName}"; // this name is for debugging purposes only ErrorDict.Add(name, cmd); }
public BookValidation(Book model) { if (String.IsNullOrWhiteSpace(model.ISBN)) { ErrorDict.Add(nameof(model.ISBN), ErrorCodes.IsRequired); } else if (!model.ISBN.All(char.IsDigit)) { ErrorDict.Add(nameof(model.ISBN), ErrorCodes.MustBeOnlyNumbers); } else if (model.ISBN.Length > MAX_ISBN || model.ISBN.Length < MIN_ISBN) { ErrorDict.Add(nameof(model.ISBN), ErrorCodes.InvalidRange); } if (String.IsNullOrWhiteSpace(model.Title)) { ErrorDict.Add(nameof(model.Title), ErrorCodes.IsRequired); } else if (model.Title.Length > TITLE_MAX_LENGTH) { ErrorDict.Add(nameof(model.Title), ErrorCodes.InvalidRange); } if (model.PublicationYear < MIN_PUBLICATION_YEAR || model.PublicationYear > DateTime.Now.Year) { ErrorDict.Add(nameof(model.PublicationYear), ErrorCodes.InvalidRange); } if (model.Publicationinfo != null) { if (model.Publicationinfo.Length > DESCRIPTION_MAX_LENGTH) { ErrorDict.Add(nameof(model.Publicationinfo), ErrorCodes.InvalidRange); } } if (model.Pages > BOOK_MAX_LENGTH || model.Pages < 1) { ErrorDict.Add(nameof(model.Pages), ErrorCodes.InvalidRange); } if (model.Classification == null) { ErrorDict.Add(nameof(model.Classification), ErrorCodes.IsRequired); } if (ErrorDict.Count == 0) { IsValid = true; } }
public void BooksExistInClassification(string type) { IsValid = false; ErrorDict.Add(type, ErrorCodes.BooksExistInClassification); }