Exemplo n.º 1
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            try
            {
                ImageFileUpload.SaveAs(Server.MapPath("~/Librarian/Books/BookImages") + Path.GetFileName(ImageFileUpload.FileName));
                String GetImagePath = "~/Librarian/Books/BookImages" + Path.GetFileName(ImageFileUpload.FileName);

                Book _Book = new Book();
                _Book.Name           = txtBookName.Text;
                _Book.AuthorName     = txtBookAuthorName.Text;
                _Book.AvailableQty   = Convert.ToDecimal(txtBookQty.Text);
                _Book.Images         = GetImagePath;
                _Book.CategoriesCode = CategoryDropDownList.SelectedValue.ToString();

                decimal AlreadyExistBook = _BooksManager.AlreadyExistBook(_Book);
                if (AlreadyExistBook >= 1)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This Book Already Exist!!..');", true);
                }
                else
                {
                    int successAdd = _BooksManager.Add(_Book);
                    if (successAdd > 0)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Saved Book Successefully!!..');", true);
                        Clear();
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Failed saved!!..');", true);
                    }
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + ex.Message + "');", true);
            }
        }