Exemple #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Publisher p = new Publisher();
                p.Name = txtName.Text;
                p.Address = txtAddress.Text;
                p.CreatedDate = DateTime.Now;
                p.PhoneNumber = txtPhoneNumber.Text;


                using (var db = new BookEntities())
                {

                    if (Request.QueryString["Id"] != null)
                    {
                        p.Id = Convert.ToInt32(Request.QueryString["Id"]);
                        db.Entry(p).State = EntityState.Modified;
                    }
                    else db.Entry(p).State = EntityState.Added;

                    db.SaveChanges();
                }

                Response.Redirect("PublisherDetail.aspx");

            }
            catch (Exception)
            {

                throw;
            }
        }
Exemple #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Author a = new Author();
                a.Name        = txtName.Text;
                a.Surname     = txtSurname.Text;
                a.CreatedDate = DateTime.Now;
                a.Description = txtDescription.Text;


                using (var db = new BookEntities())
                {
                    if (Request.QueryString["Id"] != null)
                    {
                        a.Id = Convert.ToInt32(Request.QueryString["Id"]);
                        db.Entry(a).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(a).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }

                Response.Redirect("AuthorDetail.aspx");
            }catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string fileName = string.Empty;
                if (flUpload.HasFile)
                {
                    flUpload.SaveAs(Server.MapPath("~/BookCover/") + flUpload.FileName);
                    fileName = flUpload.FileName;
                }

                using (var db = new BookEntities())
                {
                    Book b = new Book();
                    b.Title         = txtTitle.Text;
                    b.Isbn          = txtIsbn.Text;
                    b.PublisId      = Convert.ToInt32(ddlPublisher.SelectedValue);
                    b.PublishedDate = clDate.SelectedDate;
                    b.NumberOfPages = Convert.ToInt32(txtNumberOfPages.Text);
                    b.Edition       = txtEdition.Text;
                    b.FormatId      = Convert.ToInt32(ddlFormat.SelectedValue);
                    b.Description   = txtDescription.Text;
                    b.ContentId     = Convert.ToInt32(ddlContent.SelectedValue);
                    b.AuthorId_     = Convert.ToInt32(ddlAuthor.SelectedValue);
                    if (!String.IsNullOrEmpty(fileName))
                    {
                        b.BookCoverPath = "~/BookCover/" + fileName;
                    }

                    if (Request.QueryString["Id"] != null)
                    {
                        b.Id = Convert.ToInt64(Request.QueryString["Id"]);
                        db.Entry(b).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Entry(b).State = EntityState.Added;
                    }

                    db.SaveChanges();
                }

                Response.Redirect("BookDetail.aspx");
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #4
0
        //BOOK SAVE UPDATE START
        private void InsertNewBook_Click(object sender, EventArgs e)
        {
            book.BookName            = textBoxBookName.Text.Trim();
            book.BookAuthor          = textBoxAuthor.Text.Trim();
            book.BookPublicationName = textBoxPublication.Text.Trim();
            book.BookReleaseDate     = dateTimePickerBook.Value;
            book.BookQuantity        = textBoxQuantity.Text.Trim();
            book.BookPrice           = textBoxPrice.Text.Trim();
            using (BookEntities db = new BookEntities())
            {
                ////Checks wether if fields empty or not
                if (textBoxBookName.Text == "" || textBoxAuthor.Text == "" || textBoxPublication.Text == "" || textBoxQuantity.Text == "" || textBoxPrice.Text == "")
                {
                    MessageBox.Show("Please fill in all the fields");
                }
                else
                {
                    if (book.BookID == 0)
                    {
                        db.Bookİnfoes.Add(book);                         //Insert
                    }
                    else
                    {
                        db.Entry(book).State = EntityState.Modified;
                    }
                    db.SaveChanges();                     //update
                    MessageBox.Show("Submit Successfull");
                }
            }

            ClearBook();
            FillBookDataGridView();
        }
Exemple #5
0
        //=============================CLİCK-END==============================

        //========================SAVE-UPDATE-BUTTON-START===========================
        private void SaveOrderS_Click_1(object sender, EventArgs e)
        {
            //Make Fields Empty
            order.PersonOrderName = LabelpersonNameS.Text.Trim();
            order.BookOrderName   = LabelBookNames.Text.Trim();
            order.IssueDate       = DateTimePickerIssueDate.Value;
            order.Deadline        = DateTimePickerDeadline.Value;
            //Make Fields Empty
            using (BookEntities db = new BookEntities())
            {
                //Checks wether if fields empty or not
                if (LabelpersonNameS.Text == "Name" ||
                    LabelBookNames.Text == "Name")
                {
                    MessageBox.Show("Please fill fields from List");
                }
                //Checks wether if fields empty or not
                else
                //if fieldboxes are not empty it allows operation
                {
                    if (order.OrderID == 0)
                    {
                        db.OrderBooks.Add(order);                         //Insert Operation
                    }
                    else
                    {
                        db.Entry(order).State = EntityState.Modified;
                    }
                    db.SaveChanges();                     //update Operation
                    MessageBox.Show("Submit Successfull");
                }
            }
            FillOrderListDGV();
            ClearOrderList();
        }
Exemple #6
0
        private void InsertNewBook_Click(object sender, EventArgs e)
        {
            book.BookName            = textBoxBookName.Text.Trim();
            book.BookAuthor          = textBoxAuthor.Text.Trim();
            book.BookPublicationName = textBoxPublication.Text.Trim();
            book.BookPurchaseDate    = dateTimePickerBook.Value;
            book.BookQuantity        = textBoxQuantity.Text.Trim();
            book.BookPrice           = textBoxPrice.Text.Trim();
            using (BookEntities db = new BookEntities())

            {
                if (book.BookID == 0)
                {
                    db.Bookİnfos.Add(book); //Insert
                }
                else
                {
                    db.Entry(book).State = EntityState.Modified;
                }
                db.SaveChanges();                 //update
            }

            Clear();
            PopulateDataGridView();
            MessageBox.Show("Submit Successfull");
        }
 public ActionResult Edit([Bind(Include = "id,name,author,press,date,price,summary,sort")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(book));
 }
Exemple #8
0
 public ActionResult Edit([Bind(Include = "Id,Title,Author,ISBN,Website,Description,CategoryId")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", book.CategoryId);
     return(View(book));
 }
Exemple #9
0
 public string EditBook(string book)
 {
     try
     {
         Book bk = XMLHelper.DeSerializer <Book>(book);
         db.Entry(bk).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     return("true");
 }
Exemple #10
0
 private void BTNBookDelete_Click_1(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to Delete this", "EF CRUD Op", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (BookEntities db = new BookEntities())
         {
             var entry = db.Entry(book);
             if (entry.State == EntityState.Detached)
             {
                 db.Bookİnfos.Attach(book);
             }
             db.Bookİnfos.Remove(book);
             db.SaveChanges();
             //PopulateDataGridView
             PopulateDataGridView();
             Clear();
             MessageBox.Show("Deleted Successfully");
         }
     }
 }
Exemple #11
0
 private void DeleteOrderS_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to Return this", "EF CRUD Opp", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         //Confirm for Deletion
         using (BookEntities db = new BookEntities())
         {
             var entry = db.Entry(order);
             if (entry.State == EntityState.Detached)
             {
                 db.OrderBooks.Attach(order);
             }
             db.OrderBooks.Remove(order);
             db.SaveChanges();
             //FillDataGridView
             FillOrderListDGV();
             ClearOrderList();
             MessageBox.Show("Returned Successfully");
         }
     }
 }
Exemple #12
0
 private void BTNPersonDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to Delete this", "EF CRUD Opp", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         //Confirm for Deletion
         using (BookEntities db = new BookEntities())
         {
             var entry = db.Entry(person);
             if (entry.State == EntityState.Detached)
             {
                 db.People.Attach(person);
             }
             db.People.Remove(person);
             db.SaveChanges();
             //FillDataGridView
             FillPersonDataGridView();
             ClearPerson();
             MessageBox.Show("Deleted Successfully");
         }
     }
 }
Exemple #13
0
        //BOOK SAVE UPDATE END

        //PERSON SAVE UPDATE START
        private void BTNPersonSave_Click(object sender, EventArgs e)
        {
            //Make Fields Empty
            person.Name    = TxtBoxPersonName.Text.Trim();
            person.Surname = TxtBoxSurname.Text.Trim();
            person.Email   = TxtBoxEmail.Text.Trim();
            person.Phone   = TxtBoxPhone.Text.Trim();
            //Make Fields Empty
            using (BookEntities db = new BookEntities())
            {
                //Checks wether if fields empty or not
                if (TxtBoxPersonName.Text == "" ||
                    TxtBoxSurname.Text == "" ||
                    TxtBoxPhone.Text == "" ||
                    TxtBoxEmail.Text == "")
                {
                    MessageBox.Show("Please fill in all the fields");
                }
                //Checks wether if fields empty or not
                else
                //if fieldboxes are not empty it allows operation
                {
                    if (person.PersonID == 0)
                    {
                        db.People.Add(person);                         //Insert Operation
                    }
                    else
                    {
                        db.Entry(person).State = EntityState.Modified;
                    }

                    db.SaveChanges();                     //update Operation
                    MessageBox.Show("Submit Successfull");
                }
            }
            ClearPerson();
            FillPersonDataGridView();
            //PERSON SAVE UPDATE START
        }
Exemple #14
0
 public void Update(MyBook myBook)
 {
     db.Entry(myBook).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
 public void Update(Category category)
 {
     db.Entry(category).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Exemple #16
0
 public void Update(AppUser appUser)
 {
     db.Entry(appUser).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }