Exemple #1
0
        public ActionResult AddBook(tbl_Book model)
        {
            tbl_Book obj = new tbl_Book();

            if (ModelState.IsValid)
            {
                obj.idBook   = model.idBook;
                obj.bookName = model.bookName;
                obj.Author   = model.Author;
                obj.Year     = model.Year;



                if (model.idBook == 0)
                {
                    dbObj.tbl_Book.Add(obj);
                    dbObj.SaveChanges();
                }
                else

                {
                    dbObj.Entry(obj).State = System.Data.Entity.EntityState.Modified;
                    dbObj.SaveChanges();
                }
            }

            ModelState.Clear();
            return(View("Book"));
        }
        public void Delete_Book()
        {
            LibraryDBDataContext db = new LibraryDBDataContext();

            tbl_Borrow temp = (from T in db.tbl_Borrows
                               where T.BookID == this.ID
                               select T
                               ).FirstOrDefault();

            if (temp != null)
            {
                MessageBox.Show("Someone has this Book!");
                return;
            }
            else
            {
                tbl_Book B = (from T in db.tbl_Books
                              where T.ID == this.ID
                              select T).FirstOrDefault();
                tbl_Edition e = (from E in db.tbl_Editions
                                 where E.BookID == this.ID
                                 select E).FirstOrDefault();

                if (e != null)
                {
                    db.tbl_Editions.DeleteOnSubmit(e);
                }
                db.tbl_Books.DeleteOnSubmit(B);
                db.SubmitChanges();
            }
        }
 public Book(tbl_Book b)
 {
     this.ID        = b.ID;
     this.ISBN      = b.ISBN;
     this.Publisher = Publisher.LoadById(b.PublisherID);
     this.Author    = Author.LoadById(b.AuthorID);
     this.Name      = b.Name;
     this.Genre     = b.Genre;
     this.Copies    = b.Copies;
 }
        public void add()
        {
            LibraryDBDataContext db = new LibraryDBDataContext();
            tbl_Book             b  = new tbl_Book();

            b.ISBN        = this.ISBN;
            b.Name        = this.Name;
            b.PublisherID = this.Publisher.ID;
            b.AuthorID    = this.Author.ID;
            b.Copies      = this.Copies;
            b.Genre       = this.Genre;

            db.tbl_Books.InsertOnSubmit(b);
            db.SubmitChanges();
        }
 public Book(tbl_Book b, tbl_Edition e)
 {
     this.ID        = b.ID;
     this.ISBN      = b.ISBN;
     this.Publisher = Publisher.LoadById(b.PublisherID);
     this.Author    = Author.LoadById(b.AuthorID);
     this.Name      = b.Name;
     this.Genre     = b.Genre;
     this.Copies    = b.Copies;
     if (e != null)
     {
         this.Pages   = e.Pages;
         this.Version = e.Version;
     }
 }
Exemple #6
0
        public string SaveBook(BookModel model)
        {
            string msg = "";
            eSankalpMVCDemoEntities db = new eSankalpMVCDemoEntities();
            var saveBook = new tbl_Book()
            {
                BookName = model.BookName,
                ISBN     = model.ISBN,
                Author   = model.Author,
            };

            db.tbl_Book.Add(saveBook);
            db.SaveChanges();
            msg = "Book saved successfullly";
            return(msg);
        }
Exemple #7
0
        public int UpdateBook(ModelBook modelBook, ModelUser user)
        {
            tbl_Book _book = dbEntities.tbl_Book.FirstOrDefault(a => a.Id == modelBook.Id);

            if (_book != null)
            {
                _book.Book_Title             = modelBook.Book_Title;
                _book.EditionId              = modelBook.EditionId;
                _book.ProgramId              = modelBook.ProgramId;
                _book.SubjectArea_CategoryId = Convert.ToString(modelBook.SubjectArea_CategoryId);
                _book.Author      = modelBook.Author;
                _book.Description = modelBook.Description;
                _book.UserId      = user.Id.ToString();
                _book.UserType    = user.Type;
                _book.Published   = modelBook.Published;

                return(dbEntities.SaveChanges());
            }
            return(0);
        }
Exemple #8
0
        public ActionResult UploadData(ModelBook FileData)
        {
            string    FileName = "";
            ModelUser user     = (ModelUser)Session["User"];

            if (user == null)
            {
                FileName = "Please login first";
                return(Json(FileName, JsonRequestBehavior.AllowGet));
            }

            try
            {
                ModelState["Id"].Errors.Clear();
                if (ModelState.IsValid)
                {
                    int splitsubjectArea = Convert.ToInt32(FileData.SubjectArea_CategoryId.Split(',')[0]);

                    if (FileData.Id > 0)
                    {
                        UpdateBook(FileData, user);

                        FileName = "Successfully updated";
                    }
                    else
                    {
                        if (dbEntities.tbl_Book.Count(a => a.Book_Title == FileData.Book_Title) > 0)
                        {
                            FileName = "Book name is already added.";
                        }
                        else
                        {
                            var maxId = dbEntities.tbl_Book.Max(a => a.Id);

                            var categoryname = dbEntities.tbl_SubjectArea.FirstOrDefault(a => a.Id == splitsubjectArea);
                            foreach (HttpPostedFileBase file in FileData.BookdocumBase)
                            {
                                string fname;

                                Int64 id = Convert.ToInt64(maxId) + 1;
                                if (file.ContentType.Contains("image"))
                                {
                                    var coverfname = Path.Combine(Server.MapPath("~/Content/assets/img/avatars/cover/"), id + ".png");
                                    file.SaveAs(coverfname);
                                }
                                else
                                {
                                    fname = id + ".pdf";
                                    fname = Path.Combine(Server.MapPath("~/App_Data/" + categoryname.SubectArea_Name), fname);
                                    file.SaveAs(fname);
                                }
                            }


                            tbl_Book _book = new tbl_Book();
                            _book.Book_Title             = FileData.Book_Title;
                            _book.EditionId              = FileData.EditionId;
                            _book.ProgramId              = FileData.ProgramId;
                            _book.SubjectArea_CategoryId = FileData.SubjectArea_CategoryId;
                            _book.Author      = FileData.Author;
                            _book.Description = FileData.Description;
                            _book.UserId      = user.Id.ToString();
                            _book.UserType    = user.Type;
                            _book.Published   = FileData.Published;
                            dbEntities.tbl_Book.Add(_book);
                            dbEntities.SaveChanges();
                            FileName = "Success";
                        }
                    }
                }
                else
                {
                    FileName = "Required all input data fill up ";
                }
            }
            catch (Exception e)
            {
                FileName = e.GetBaseException().ToString();
            }


            return(Json(FileName, JsonRequestBehavior.AllowGet));
            //return View();
        }