Beispiel #1
0
        public void SaveBook(BOOKVM model)
        {
            bool Isvalid = ValidateModel(model);

            if (Isvalid)
            {
                if (model.book_id == 0)
                {
                    TBL_BOOK book = new TBL_BOOK();

                    book.photo       = model.photo;
                    book.title       = model.title;
                    book.numofcopies = model.numofcopies;
                    book.isbn        = model.isbn;

                    context.TBL_BOOK.Add(book);
                }
                else
                {
                    var res = context.TBL_BOOK.SingleOrDefault(s => s.book_id == model.book_id);
                    res.photo       = model.photo;
                    res.title       = model.title;
                    res.numofcopies = model.numofcopies;
                    res.isbn        = model.isbn;
                }
                context.SaveChanges();
            }
        }
Beispiel #2
0
 public ActionResult Create([Bind(Include = "BookID,Title,ISBN,Availability,AuthorID,PublisherID,CategoryID")] Books books)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Books.Add(books);
             db.AuthorsBooks.Add(new AuthorsBooks {
                 BookID = books.BookID, AuthorID = books.AuthorID
             });
             db.BooksPublishers.Add(new BooksPublishers {
                 BookID = books.BookID, PublisherID = books.PublisherID
             });
             db.BooksCategories.Add(new BooksCategories {
                 BookID = books.BookID, CategoryID = books.CategoryID
             });
             books.Availability = true;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes.");
     }
     PopulateAuthorsDropDownList(books.AuthorID);
     PopulatePublishersDropDownList(books.PublisherID);
     PopulateCategoriesDropDownList(books.CategoryID);
     return(View(books));
 }
        public IHttpActionResult Put(string id, string user, Rent_Details rent_Details)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != rent_Details.callNumber && user != rent_Details.stu_userName)
            {
                return(BadRequest());
            }
            db.Entry(rent_Details).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Rent_DetailsExists(user))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
        public string SaveReservatin(RESERVATIONVM model)
        {
            if (model.reservation_id == 0)
            {
                TBL_RESRVATION resrvation = new TBL_RESRVATION();
                var            book       = context.TBL_BOOK.SingleOrDefault(s => s.book_id == model.book_id);
                int            NumOFBook  = context.TBL_RESRVATION.Where(s => s.user_id == model.user_id).Count();



                if (NumOFBook < 5)
                {
                    resrvation.user_id = model.user_id;
                    resrvation.book_id = model.book_id;
                    context.TBL_RESRVATION.Add(resrvation);

                    book.numofcopies--;

                    context.SaveChanges();
                    return("scusses");
                    // context.TBL_RESRVATION.Remove(resrvation);
                }
                else
                {
                    return("the max number of for you is 5 ");
                }
            }

            return("");
        }
Beispiel #5
0
        /// <summary>
        /// Uses the cardholderbuilder to create a cardholder, and possibly a new person as well.
        /// </summary>
        /// <param name="builder"></param>
        public void AddCardholderToDatabase(CardholderBuilder builder)
        {
            using (LibraryDBEntities context = new LibraryDBEntities())
            {
                //If this is a new person we will need to add them to the People table
                if (builder.IsNewPerson)
                {
                    Person p = new Person()
                    {
                        FirstName = builder.Cardholder.FirstName,
                        LastName  = builder.Cardholder.LastName
                    };
                    context.People.Add(p);
                    context.SaveChanges();

                    //To add the cardholder we need the foreign key
                    Person person = (from x in context.People
                                     where x.FirstName == builder.Cardholder.FirstName && x.LastName == builder.Cardholder.LastName
                                     select x).FirstOrDefault();
                    builder.SetID(person.PersonID);
                }
                //Now the cardholder object is created and added to the Cardholders table
                Cardholder c = new Cardholder()
                {
                    ID            = builder.Cardholder.ID,
                    Phone         = builder.Cardholder.Phone,
                    LibraryCardID = builder.Cardholder.LibraryCardID
                };
                context.Cardholders.Add(c);
                context.SaveChanges();
            }
            PopulatePeople();
        }
Beispiel #6
0
 // POST: api/Departmen
 public void Post(Departmen sub)
 {
     if (ModelState.IsValid)
     {
         db.Departmens.Add(sub);
         db.SaveChanges();
     }
 }
        public ActionResult Create([Bind(Include = "ID,Name,City")] Departmen departmen)
        {
            if (ModelState.IsValid)
            {
                db.Departmens.Add(departmen);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(departmen));
        }
        public ActionResult Create([Bind(Include = "ISBN,Title,Author,Year")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Book.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
        public ActionResult Create([Bind(Include = "Id,BookName,Price,Category,AuthorName,Edition,BookCondition,Available")] BookDetails bookDetails)
        {
            if (ModelState.IsValid)
            {
                db.BookDetails.Add(bookDetails);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bookDetails));
        }
Beispiel #10
0
 public ActionResult Edit([Bind(Include = "Id,BookId,StudentId,BorrowDate,ReturnDate")] BorrowHistory borrowHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(borrowHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BookId    = new SelectList(db.Books, "Id", "Code", borrowHistory.BookId);
     ViewBag.StudentId = new SelectList(db.Students, "Id", "FirstName", borrowHistory.StudentId);
     return(View(borrowHistory));
 }
Beispiel #11
0
        public ActionResult Create([Bind(Include = "ID,Name,Author,Year,Department")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Department = new SelectList(db.Departmens, "ID", "Name", book.Department);
            return(View(book));
        }
Beispiel #12
0
        public HttpResponseMessage Put(int id, [FromBody] Book book)
        {
            try
            {
                using (LibraryDBEntities entities = new LibraryDBEntities())
                {
                    var entity = entities.Books.FirstOrDefault(e => e.ID == id);

                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Book with id = " + id.ToString() + " not found to update"));
                    }
                    else
                    {
                        entity.Title   = book.Title;
                        entity.Author  = book.Author;
                        entity.Edition = book.Edition;
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        // method to assigne books
        public HttpResponseMessage Post([FromBody] BooksAssigned assignedBooks)
        {
            try
            {
                using (LibraryDBEntities entities = new LibraryDBEntities())
                {
                    foreach (var book in assignedBooks.Books)
                    {
                        var entity = entities.AssignedBooks.ToList().Where(e => e.UserID == assignedBooks.UserId && e.BookID == book);

                        //var bookQty = entities.AssignedBooks.ToList().Where(e => e.UserID == assignedBooks.UserId && e.BookID.Value == book);
                        //if(bookQty.Count() < 3)

                        if (entity.Count() == 0)
                        {
                            entities.AssignedBooks.Add(new AssignedBook {
                                UserID = assignedBooks.UserId, BookID = book
                            });
                        }
                    }
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, "true");
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
        public ActionResult Lend(int?selectedBook, int?selectedUser)
        {
            try
            {
                if (selectedBook.HasValue && selectedUser.HasValue)
                {
                    db.BooksUsers.Add(new BooksUsers {
                        BookID = selectedBook, LibraryUserID = selectedUser, LendDate = DateTime.Now
                    });
                    var books = db.Books.SingleOrDefault(b => b.BookID == selectedBook);
                    books.Availability = false;
                    db.SaveChanges();

                    System.Windows.Forms.MessageBox.Show("Book lended!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Please select Library User and Book to be lended!");
                    return(new HttpStatusCodeResult(204));
                }
            }

            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes.");
                return(new HttpStatusCodeResult(204));
            }
        }
Beispiel #15
0
        /// <summary>
        /// Adds a given author to the database, if there isn't a person entry already it will be created.
        /// </summary>
        /// <param name="author"></param>
        public void AddAuthorToDatabase(AuthorBLL author)
        {
            using (LibraryDBEntities context = new LibraryDBEntities())
            {
                Person person = (from p in context.People
                                 where p.PersonID == author.ID
                                 select p).FirstOrDefault();
                if (person == null)
                {
                    person = new Person()
                    {
                        PersonID  = author.ID,
                        FirstName = author.FirstName,
                        LastName  = author.LastName
                    };
                    context.People.Add(person);
                }

                Author newAuthor = new Author()
                {
                    ID  = author.ID,
                    Bio = author.Bio
                };
                context.Authors.Add(newAuthor);
                context.SaveChanges();
            }
            PopulatePeople();
        }
Beispiel #16
0
        public ActionResult Return(int?selectedBook)
        {
            try
            {
                if (selectedBook.HasValue)
                {
                    var booksUsers = db.BooksUsers.SingleOrDefault(bu => bu.BookID == selectedBook && bu.ReturnDate == null);
                    booksUsers.ReturnDate = DateTime.Now;
                    var books = db.Books.SingleOrDefault(b => b.BookID == selectedBook);
                    books.Availability = true;
                    db.SaveChanges();

                    System.Windows.Forms.MessageBox.Show("Book returned!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Please select book to be returned!");
                    return(new HttpStatusCodeResult(204));
                }
            }

            catch (DataException)
            {
                ModelState.AddModelError("", "Unable to save changes.");
                return(new HttpStatusCodeResult(204));
            }
        }
        /// <summary>
        /// Adds the book to the database, if the author is new they will be added first.
        /// </summary>
        /// <param name="builder"></param>
        public void AddBookToDatabase(BookBuilder builder)
        {
            if (builder.AuthorBuilder != null)//A new author needs to be added
            {
                AddAuthorToDatabase(builder);
            }
            //Adding the book to the database
            using (LibraryDBEntities context = new LibraryDBEntities())
            {
                //Create the book and add to database
                Book newBook = new Book()
                {
                    ISBN           = builder.Book.ISBN,
                    Title          = builder.Book.Title,
                    AuthorID       = builder.Book.AuthorID,
                    Subject        = builder.Book.Subject,
                    Description    = builder.Book.Description,
                    NumberOfCopies = builder.Book.NumberOfCopies,
                    NumPages       = builder.Book.NumPages,
                    YearPublished  = builder.Book.YearPublished,
                    Language       = builder.Book.Language,
                    Publisher      = builder.Book.Publisher
                };
                context.Books.Add(newBook);

                context.SaveChanges();
                //Get the book id
                builder.Book.BookID = newBook.BookID;
                //Add the BookBLL to the customcollection
                books.Add(builder.Book);
            }
            Sort();
        }
Beispiel #18
0
 public static void Add(IssueBooks ib)
 {
     using (var db = new LibraryDBEntities())
     {
         db.IssueBooks.Add(ib);
         db.SaveChanges();
     }
 }
 public static void Add(Users u)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Users.Add(u);
         db.SaveChanges();
     }
 }
Beispiel #20
0
 public static void Add(Books b)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Books.Add(b);
         db.SaveChanges();
     }
 }
 public static void Add(BookCategories bc)
 {
     using (var db = new LibraryDBEntities())
     {
         db.BookCategories.Add(bc);
         db.SaveChanges();
     }
 }
Beispiel #22
0
 public static void Update(UserPrivileges up)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Entry(up).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #23
0
 public static void Add(UserPrivileges up)
 {
     using (var db = new LibraryDBEntities())
     {
         db.UserPrivileges.Add(up);
         db.SaveChanges();
     }
 }
Beispiel #24
0
        public ActionResult DeleteConfirmed(int id)
        {
            Student student = db.Students.Find(id);

            db.Students.Remove(student);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #25
0
 public static void Add(Departments d)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Departments.Add(d);
         db.SaveChanges();
     }
 }
Beispiel #26
0
 public static void Update(Departments d)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Entry(d).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #27
0
        public bool Commit()
        {
            transaction = db.Database.BeginTransaction(); //trabssac a başla
            int affected = db.SaveChanges();              //değişiklikleri kaydetsn

            transaction.Commit();                         //uygulasın
            return(affected > 0);
        }
Beispiel #28
0
 public static void Update(IssueBooks ib)
 {
     using (var db = new LibraryDBEntities())
     {
         db.Entry(ib).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Beispiel #29
0
        public bool Commit()
        {
            transaction = db.Database.BeginTransaction();
            int affected = db.SaveChanges();

            transaction.Commit();
            return(affected > 0);
        }
 public static void Add(ReturnBooks rb)
 {
     using (var db = new LibraryDBEntities())
     {
         db.ReturnBooks.Add(rb);
         db.SaveChanges();
     }
 }