private void InsertBook(string imgPath)
        {
            Validator validator = new Validator();
            
            string title = this.TitleTextBox.Text;
            validator.ValidateTitleLength(title,3);



            int pagesCount = validator.TryParsePageCountInput(this.PageCountTextBox.Text);
            validator.ValidatePageCount(pagesCount, 0, 5000);

            string genreName = this.GenreDownList.SelectedValue;
            Genre genre = this.GenreServices.GetGenre(genreName);

            var book = new Book()
            {
                Title = title,
                PageCount = pagesCount,
                Genre = genre,
                CreationDate = DateTime.Now,
                Url = imgPath
            };

            this.BooksServices.AddBook(book);
            this.ErrorTextBox.Visible = false;
        }
示例#2
0
 public Concrete()
 {
     Validator = new Validator(this)
     {
         { "Count", () => Count < 0 ? "Count should be positive." : null }
     };
     Validator.ValidateAll();
 }
示例#3
0
 public SubModel()
 {
     Validator = new Validator(this)
     {
         {this.GetPropertyName(x => StringSetting), () => string.IsNullOrEmpty(StringSetting) ? "Should be non empty." : null},
         {this.GetPropertyName(x => NumberSetting), () => NumberSetting < 0 ? "Should be 0 or greater." : null}
     };
 }
示例#4
0
        public RootModel()
        {
            SubModel = new SubModel();

            Validator = new Validator(this);
            Validator.ValidateAll(); // call it for initial validation if required
        }