Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Book_Publisher book_Publisher = db.Book_Publishers.Find(id);

            db.Book_Publishers.Remove(book_Publisher);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        // GET: Admin/Book_Publisher/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Book_Publisher book_Publisher = db.Book_Publishers.Find(id);

            if (book_Publisher == null)
            {
                return(HttpNotFound());
            }
            return(View(book_Publisher));
        }
Exemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "ID,publisherid,Bookid,CreateDate,CreateUserID,UpdateDate,UpdateUserID")] Book_Publisher book_Publisher)
 {
     if (ModelState.IsValid)
     {
         User user = Session["AdminLogin"] as User;
         book_Publisher.UpdateDate      = DateTime.Now;
         book_Publisher.UpdateUserID    = user.ID;
         db.Entry(book_Publisher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Bookid      = new SelectList(db.Books, "ID", "Name", book_Publisher.Bookid);
     ViewBag.publisherid = new SelectList(db.Publishers, "ID", "publisherName", book_Publisher.publisherid);
     return(View(book_Publisher));
 }
Exemplo n.º 4
0
        // GET: Admin/Book_Publisher/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Book_Publisher book_Publisher = db.Book_Publishers.Find(id);

            if (book_Publisher == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Bookid      = new SelectList(db.Books, "ID", "Name", book_Publisher.Bookid);
            ViewBag.publisherid = new SelectList(db.Publishers, "ID", "publisherName", book_Publisher.publisherid);
            return(View(book_Publisher));
        }
        public void BookGive(BookViewModel bookVm, string session)
        {
            TimeSpan?interval;
            DateTime?receivingDate, givingDate;

            receivingDate = null;
            interval      = null;
            BookOperation bkO = null;

            if (bookVm.PublisherName == null)
            {
                bkO = (from bo in bookDC.BookOperations
                       where bo.UserName == session && bo.BookName == bookVm.BookName && bo.ReceivingDate != null
                       select bo).FirstOrDefault();
            }
            else
            {
                bkO = (from bo in bookDC.BookOperations
                       where bo.UserName == session && bo.BookName == bookVm.BookName
                       select bo).FirstOrDefault();
            }

            var authr = (from a in bookDC.Authors
                         where a.AuthorName == bookVm.AuthorName
                         select a).FirstOrDefault();

            Penalty       penalty = new Penalty();
            BookOperation BO      = new BookOperation();

            if (bkO == null)
            {
                BO.UserName      = session;
                BO.CategoryName  = bookVm.CategoryName;
                BO.BookName      = bookVm.BookName;
                BO.PublisherName = bookVm.PublisherName;
                BO.GivingDate    = DateTime.Now;
                if (!string.IsNullOrEmpty(bookVm.AuthorName))
                {
                    BO.AuthorName = bookVm.AuthorName;
                }
                else
                {
                    BO.AuthorName = "-";
                }

                bookDC.BookOperations.Add(BO);
                bookDC.SaveChanges();

                penalty.BookOperationId = BO.Id;
                penalty.PenaltyQuantity = 0;
                bookDC.Penalties.Add(penalty);
            }
            else
            {
                if (bkO.ReceivingDate == null)
                {
                    BO.UserName      = session;
                    BO.CategoryName  = bookVm.CategoryName;
                    BO.BookName      = bookVm.BookName;
                    BO.PublisherName = bookVm.PublisherName;
                    BO.GivingDate    = DateTime.Now;
                    BO.ReceivingDate = null;
                    if (!string.IsNullOrEmpty(bookVm.AuthorName))
                    {
                        BO.AuthorName = bookVm.AuthorName;
                    }
                    else
                    {
                        BO.AuthorName = "-";
                    }

                    bookDC.BookOperations.Add(BO);
                    bookDC.SaveChanges();

                    penalty.BookOperationId = BO.Id;
                    penalty.PenaltyQuantity = 0;
                    bookDC.Penalties.Add(penalty);
                }
                else
                {
                    receivingDate  = bkO.ReceivingDate;
                    bkO.GivingDate = DateTime.Now;
                    givingDate     = bkO.GivingDate;
                    interval       = givingDate - receivingDate;
                    foreach (var item in bookDC.Penalties)
                    {
                        if (item.BookOperationId == bkO.Id)
                        {
                            if (interval.Value.Days <= 7)
                            {
                                item.PenaltyQuantity = 0;
                            }
                            else
                            {
                                item.PenaltyQuantity = (double)interval.Value.Days * 0.50;
                                break;
                            }
                        }
                    }
                }

                var bk = (from b in bookDC.Books
                          where b.BookName == bookVm.BookName
                          select b).FirstOrDefault();
                Book book = new Book();
                if (bk == null)
                {
                    book.BookName   = bookVm.BookName;
                    book.CategoryId = (from item in bookDC.Categories
                                       where item.CategoryName == bookVm.CategoryName
                                       select item.CategoryId).FirstOrDefault();
                    book.BookQuantity = 1;
                    bookDC.Books.Add(book);
                }
                else
                {
                    bk.BookQuantity++;
                }



                Author author = new Author();
                if (authr == null)
                {
                    if (bookVm.AuthorName != null)
                    {
                        author.AuthorName = bookVm.AuthorName;
                        bookDC.Authors.Add(author);
                        Book_Author BA = new Book_Author();
                        BA.AuthorId = author.AuthorId;
                        BA.BookId   = book.BookId;
                        bookDC.Book_Author.Add(BA);
                    }
                    else
                    {
                        if (bkO.GivingDate != null)
                        {
                        }
                        else
                        {
                            author.AuthorName = "-";
                            bookDC.Authors.Add(author);
                            Book_Author BA = new Book_Author();
                            BA.AuthorId = author.AuthorId;
                            BA.BookId   = book.BookId;
                            bookDC.Book_Author.Add(BA);
                        }
                    }
                }


                var publishr = (from p in bookDC.Publishers
                                where p.PublisherName == bookVm.PublisherName
                                select p).FirstOrDefault();
                Publisher publshr = new Publisher();
                if (publishr == null)
                {
                    if (bookVm.PublisherName != null)
                    {
                        publshr.PublisherName = bookVm.PublisherName;
                        bookDC.Publishers.Add(publshr);
                        Book_Publisher BP = new Book_Publisher();
                        BP.PublisherId = publshr.PublisherId;
                        BP.BookId      = book.BookId;
                        bookDC.Book_Publisher.Add(BP);
                    }
                    else
                    {
                        if (bkO.GivingDate != null)
                        {
                        }
                        else
                        {
                            publshr.PublisherName = "-";
                            bookDC.Publishers.Add(publshr);
                            Book_Publisher BP = new Book_Publisher();
                            BP.PublisherId = publshr.PublisherId;
                            BP.BookId      = book.BookId;
                            bookDC.Book_Publisher.Add(BP);
                        }
                    }
                }

                bookDC.SaveChanges();
            }
        }