Esempio n. 1
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DataGrid dg = dataGridBorrowedBooks as DataGrid;

            if (dg.SelectedItem != null)
            {
                BorrowedBy row = (BorrowedBy)dg.Items[dg.Items.IndexOf(dg.SelectedItem)];
                row.returned = 1;
                if (BorrowedBooksDataAccess.Update(row))
                {
                    MessageBox.Show(AppConstants.BookCollectedMessage, AppConstants.BookCollectedTitle, MessageBoxButton.OK
                                    , MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show(AppConstants.ErrorMessage, AppConstants.ErrorTitle, MessageBoxButton.OK
                                    , MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show(AppConstants.SelectMessage, AppConstants.SelectTitle, MessageBoxButton.OK
                                , MessageBoxImage.Information);
            }
        }
Esempio n. 2
0
        private void dataGridBorrowedBooks_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGrid   dg   = sender as DataGrid;
            BorrowedBy row  = (BorrowedBy)dg.Items[dg.Items.IndexOf(dg.SelectedItem)];
            Book       book = BookDataAccess.FindBook(row.BookId);

            // calculate fine
            DateTime returnDate = DateTime.Parse(row.ReturnDate);
            var      TotalDays  = (DateTime.Parse(DateTime.Now.ToString("d")) - DateTime.Parse(returnDate.ToString("d"))).TotalDays;

            if (TotalDays > 0)
            {
                fineLbl.Content        = "$ " + (double)TotalDays * (double)book.FinePerDay;
                dateLbl.Content        = TotalDays + " days";
                lblNoDelays.Visibility = Visibility.Hidden;
                fineLbl.Visibility     = Visibility.Visible;
                dateLbl.Visibility     = Visibility.Visible;
            }
            else
            {
                fineLbl.Visibility     = Visibility.Hidden;
                dateLbl.Visibility     = Visibility.Hidden;
                lblNoDelays.Visibility = Visibility.Visible;
            }
        }
Esempio n. 3
0
        public void IncreaseBookCountAvailability(BorrowedBy borrowedBy)
        {
            var books = db.Books.Find(borrowedBy.BookId);

            books.AvailableCount += 1;
            books.BorrowedCount  -= 1;
            db.SaveChanges();
        }
Esempio n. 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            BorrowedBy borrowedBy = db.borrowedBies.Find(id);

            db.borrowedBies.Remove(borrowedBy);
            db.SaveChanges();
            var deleteBorrowedBy = new DeleteBorrowedBy();

            deleteBorrowedBy.IncreaseBookCountAvailability(borrowedBy);
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BorrowedBy borrowedBy = db.borrowedBies.Find(id);

            if (borrowedBy == null)
            {
                return(HttpNotFound());
            }
            return(View(borrowedBy));
        }
Esempio n. 6
0
 public static bool Insert(BorrowedBy borrowed)
 {
     try
     {
         library_dbEntities dbContext = new library_dbEntities();
         dbContext.BorrowedBies.Add(borrowed);
         dbContext.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BorrowedBy borrowedBy = db.borrowedBies.Find(id);

            if (borrowedBy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BookId   = new SelectList(db.Books, "Id", "Title", borrowedBy.BookId);
            ViewBag.MemberId = new SelectList(db.Members, "Id", "Id", borrowedBy.MemberId);
            return(View(borrowedBy));
        }
Esempio n. 8
0
        public static bool Update(BorrowedBy borrowed)
        {
            try
            {
                library_dbEntities dbContextBorrowed = new library_dbEntities();
                BorrowedBy         borrowedBy        = (from bb in dbContextBorrowed.BorrowedBies
                                                        where bb.BorrowedId == borrowed.BorrowedId
                                                        select bb).SingleOrDefault();

                borrowedBy.returned = borrowed.returned;
                dbContextBorrowed.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "Id,IssueDate,ReturnDate,IsReturned,MemberId,BookId")] BorrowedBy borrowedBy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(borrowedBy).State = EntityState.Modified;
         db.SaveChanges();
         var editBorrowedBy = new EditBorrowedBy();
         if (!borrowedBy.IsReturned)
         {
             editBorrowedBy.ReduceBookCountAvailability(borrowedBy);
         }
         else
         {
             editBorrowedBy.IncreaseBookCountAvailability(borrowedBy);
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.BookId   = new SelectList(db.Books, "Id", "Title", borrowedBy.BookId);
     ViewBag.MemberId = new SelectList(db.Members, "Id", "Id", borrowedBy.MemberId);
     return(View(borrowedBy));
 }
Esempio n. 10
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     if (selectedBook != null)
     {
         BorrowedBy bb = new BorrowedBy();
         bb.MemberId     = selectedMember.MemberId;
         bb.BookId       = selectedBook.BookId;
         bb.BorrowedDate = DateTime.Today.ToShortDateString();
         bb.ReturnDate   = DateTime.Today.AddDays(10).ToShortDateString();
         bb.CurrentFine  = 0;
         bb.returned     = 0;
         bool flag = false;
         if (selectedBook.NoOfCopies > 0)
         {
             flag = BorrowedBooksDataAccess.Insert(bb);
         }
         else
         {
             MessageBox.Show(AppConstants.BookNotAvailableMessage, AppConstants.ErrorTitle, MessageBoxButton.OK
                             , MessageBoxImage.Error);
         }
         if (flag)
         {
             MessageBox.Show(AppConstants.IssueSuccessMessage, AppConstants.IssueSuccessTitle, MessageBoxButton.OK
                             , MessageBoxImage.Information);
         }
         else
         {
             MessageBox.Show(AppConstants.ErrorMessage, AppConstants.ErrorTitle, MessageBoxButton.OK
                             , MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show(AppConstants.SelectBookMessage, AppConstants.SelectTitle, MessageBoxButton.OK
                         , MessageBoxImage.Error);
     }
 }
Esempio n. 11
0
        public ActionResult Create([Bind(Include = "Id,IssueDate,ReturnDate,IsReturned,MemberId,BookId")] BorrowedBy borrowedBy)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.borrowedBies.Add(borrowedBy);
                    db.SaveChanges();
                    var createBorrowedBy = new CreateBorrowedBy();
                    createBorrowedBy.ReduceBookCountAvailability(borrowedBy);
                    return(RedirectToAction("Index"));
                }


                ViewBag.BookId   = new SelectList(db.Books, "Id", "Title", borrowedBy.BookId);
                ViewBag.MemberId = new SelectList(db.Members, "Id", "Id", borrowedBy.MemberId);
                return(View(borrowedBy));
            }
            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "BorrowedBy", "Create")));
            }
        }