Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public Concrete()
 {
     Validator = new Validator(this)
     {
         { "Count", () => Count < 0 ? "Count should be positive." : null }
     };
     Validator.ValidateAll();
 }
Ejemplo n.º 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}
     };
 }
Ejemplo n.º 4
0
        public RootModel()
        {
            SubModel = new SubModel();

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