private void btnRegister_Click_1(object sender, EventArgs e) { try { material = new Material(); materialBLL = new MaterialBLL(); // ------------------------------ // material.Title = txtTitle.Text; material._Author.AuthorName = txtAuthor.Text; Genre gen = getGenre(); material._Genre = gen; material.GenreId = gen.GenreId; Language lang = getLanguange(); material._Language = lang; material.LanguageId = lang.LanguageId; material.ISBN = txtISBN.Text; material._PublishHouse._PublishHouse = txtPublishHouse.Text; Shelf shelf = getShelf(); material._Shelf = shelf; material.ShelfId = shelf.ShelfId; MaterialType materialtype = getMaterialType(); material._MaterialType = materialtype; material.MaterialTypeId = materialtype.MaterialTypeId; int n; bool isNumeric = int.TryParse(txtPublishDate.Text, out n); if (isNumeric) { //d = new DateTime(int.Parse(txtPublishDate.Text), 1, 1); //material.PublishYear = Convert.ToDateTime(d.Year); //string gg = material.PublishYear.ToShortDateString(); material.PublishYear = new DateTime(int.Parse(txtPublishDate.Text), 1, 1); } material.Quantity = Convert.ToInt32(txtQuantity.Text); material.NumberOfPages = Convert.ToInt32(txtPages.Text); material.IsActive = true; material.InsBy = FormLoggedUser.Id; MaterialValidation materialValidator = new MaterialValidation(); materialValidator.material = material; materialValidator.ValidateMaterial(); ValidationResult results = materialValidator.Validate(material); if (results.IsValid == false) { foreach (ValidationFailure failure in results.Errors) { MessageBox.Show($"{failure.ErrorMessage}", "Error Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { if (materialBLL.Add(material) == 0) { MessageBox.Show("The material is registered successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { throw new Exception(); } } } catch (Exception ex) { MessageBox.Show("Material is not inserted please contact your adminsitrator"); } }