コード例 #1
0
        public ActionResult Create([Bind(Include = "id,name,author,press,date,price,summary,sort")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Book.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
コード例 #2
0
ファイル: BooksController.cs プロジェクト: rt2800/MVCDemo1
        public ActionResult Create([Bind(Include = "Id,Title,Author,ISBN,Website,Description,CategoryId")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", book.CategoryId);
            return(View(book));
        }
コード例 #3
0
 public string AddBook(string book)
 {
     try
     {
         Book bk = XMLHelper.DeSerializer <Book>(book);
         db.Book.Add(bk);
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
     return("true");
 }
コード例 #4
0
ファイル: PublisherSave.aspx.cs プロジェクト: eeh383/ehaksal
        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;
            }
        }
コード例 #5
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");
        }
コード例 #6
0
ファイル: Dashboard.cs プロジェクト: AltayMahmudi/BACKEND-C-
        //=============================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();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            using (var db = new BookEntities())
            {
                var newBook = new Book()
                {
                    Id   = Guid.NewGuid(),
                    Name = $"Test - {DateTime.Now.Ticks}",
                };
                db.Books.Add(newBook);



                Guid id = Guid.Parse("9F754B7A-C8E7-4EFF-9134-FF8B0FB8E2F3");

                var book = db.Books.Where(x => x.Id == id).FirstOrDefault();
                book.Name = "Nazir's book";


                db.SaveChanges();

                Console.WriteLine("Dnone");
                Console.ReadKey();
            }
        }
コード例 #8
0
ファイル: Dashboard.cs プロジェクト: AltayMahmudi/BACKEND-C-
        //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();
        }
コード例 #9
0
ファイル: AuthorSave.aspx.cs プロジェクト: eeh383/ehaksal
        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;
            }
        }
コード例 #10
0
        public void Add(BookViewMoel model)
        {
            using (var dbcontext = new BookEntities())
            {
                var book = new Book {
                    ISBN = model.ISBN, Name = model.Name
                };
                dbcontext.Books.Add(book);

                dbcontext.SaveChanges();
            }
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        static void Main()
        {
            // Получить список всех сущностей
            using (var entities = new BookEntities())
            {
                foreach (var book in entities.Books)
                {
                    Console.WriteLine("{0}, {1} {2}",
                                      book.BookId, book.Title, book.PublishYear);
                }
            }

            // Создать/удалить новую сущность
            using (var entities = new BookEntities())
            {
                var bookEntity = new Books {
                    Title = "Proffesional C# 4.5 And .NET 4.5 platform", PublishYear = 2012
                };
                entities.Books.Add(bookEntity);
                entities.SaveChanges();

                entities.Books.Remove(bookEntity);
                entities.SaveChanges();
            }

            // Создание запросов
            using (var entities = new BookEntities())
            {
                var books = from book in entities.Books
                            where book.BookId == 1
                            select book;
                var firstOrDefault = books.FirstOrDefault();
                if (firstOrDefault != null)
                {
                    Console.WriteLine(firstOrDefault.BookId);
                }
            }

            Console.ReadKey();
        }
コード例 #12
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;
            }
        }
コード例 #13
0
        public ActionResult Edit_Post(int Id)
        {
            var bookmodel = new Book();

            TryUpdateModel(bookmodel);

            using (var r = new BookEntities())
            {
                var m = r.Book.Where(x => x.Id == Id).FirstOrDefault();
                TryUpdateModel(m);
                r.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
コード例 #14
0
        public ActionResult Create_Post()
        {
            var bookmodel = new Book();

            TryUpdateModel(bookmodel);

            using (var r = new BookEntities())
            {
                r.Book.Add(bookmodel);
                r.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
コード例 #15
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");
         }
     }
 }
コード例 #16
0
ファイル: Dashboard.cs プロジェクト: AltayMahmudi/BACKEND-C-
 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");
         }
     }
 }
コード例 #17
0
ファイル: Dashboard.cs プロジェクト: AltayMahmudi/BACKEND-C-
 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");
         }
     }
 }
コード例 #18
0
ファイル: Dashboard.cs プロジェクト: AltayMahmudi/BACKEND-C-
        //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
        }
コード例 #19
0
 public void Insert(MyBook myBook)
 {
     db.MyBook.Add(myBook);
     db.SaveChanges();
 }
コード例 #20
0
 public void Insert(Category category)
 {
     db.Category.Add(category);
     db.SaveChanges();
 }
コード例 #21
0
 public ActionResult Create(BOOK_CODE Books)
 {
     db.BOOK_CODE.Add(Books);
     db.SaveChanges();
     return(RedirectToAction("index"));
 }
コード例 #22
0
 public void Insert(AppUser appUser)
 {
     db.AppUser.Add(appUser);
     db.SaveChanges();
 }