Ejemplo n.º 1
0
        //
        // GET: /Admin/
        public ActionResult Index()
        {
            librarySystem entity      = new librarySystem();
            var           BookRequest = entity.RecordsTables.Where(t => t.isApproved == false); //display all books that are false

            return(View(BookRequest));
        }
Ejemplo n.º 2
0
        librarySystem entities = new librarySystem();     //Home Controller is the user DashBoard
        //
        // GET: /Home/
        public ActionResult Index()
        {
            int           customerid = Convert.ToInt32(Session["customerId"]);
            librarySystem entities   = new librarySystem();

            var BookRecord = entities.RecordsTables.Where(t => t.customerId == customerid);       //The customer id from the database should match session customer Id.

            //(from records in entities.RecordsTables select records).ToList();
            return(View(BookRecord));
        }
Ejemplo n.º 3
0
        //
        // GET: /ApproveBook/
        public ActionResult Index(int bookid, int customerid)
        {
            librarySystem ent = new librarySystem();

            var approveRequest = ent.RecordsTables.Where(t => t.customerId == customerid && t.BookId == bookid);

            approveRequest.FirstOrDefault().isApproved = true;
            ent.SaveChanges();
            return(RedirectToAction("Index", "Admin"));
        }
Ejemplo n.º 4
0
 public ActionResult Index(LibraryBook details)
 {
     using (librarySystem db = new librarySystem())
     {
         if (ModelState.IsValid)
         {
             db.LibraryBooks.Add(details);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.SuccessMessage = "Book details are added successfully";
         return(View("Index", new LibraryBook()));
     }
     return(View());
 }
Ejemplo n.º 5
0
        private static List <SelectListItem> GetBooks()
        {
            librarySystem         entities = new librarySystem();
            List <SelectListItem> BookList = (from p in entities.LibraryBooks.AsEnumerable()   //Here all the books from the database are taken and put them in the dropdown list.
                                              select new SelectListItem
            {
                Text = p.Title,
                Value = p.BookId.ToString()
            }).ToList();


            //Add Default Item at First Position.
            BookList.Insert(0, new SelectListItem {
                Text = "--Select Here--", Value = ""
            });
            return(BookList);
        }
        [HttpPost]                                   //when the form is filled and button is hit, the data is posted in this post action method.
        public ActionResult Index(Customer customer) //The data is binded to the 'customer'
        {
            using (librarySystem db = new librarySystem())
            {
                if (db.Customers.Any(x => x.customerName == customer.customerName))    //if-else to avoid duplicate registering from the already rgistered name.
                {
                    ViewBag.DuplicateMessage = "This User Name Already Exists. Please try again.";
                    return(View("Index", customer));
                }
                else
                {
                    db.Customers.Add(customer);            //Adding all the information to the database
                    db.SaveChanges();
                }
            }
            ModelState.Clear();             //Rebuild the model to be passed to your view.
            ViewBag.SuccessMessage = "Done! Your Successfully Registered.";

            return(View("Index", new Customer()));
        }
Ejemplo n.º 7
0
        public ActionResult Index(string ddlBooks)
        {
            List <SelectListItem> BookList = GetBooks();

            if (!string.IsNullOrEmpty(ddlBooks))
            {
                SelectListItem selectedItem = BookList.Find(p => p.Value == ddlBooks);
                //ViewBag.Message = "Name: " + selectedItem.Text;
                //ViewBag.Message += "\\nID: " + selectedItem.Value;
                int           BookId   = Convert.ToInt32(ddlBooks);
                librarySystem entities = new librarySystem();
                var           record   = entities.RecordsTables.Where(x => x.BookId == BookId).Count(); //same book assigned to user (if less than 10 goes in if statement)
                if (record < 10)
                {
                    int customerid  = Convert.ToInt32(Session["customerId"]);
                    var avalibility = entities.RecordsTables.Where(x => x.BookId == BookId && x.customerId == customerid).Count();  //not assigning the same book again to the same user(if the book is not assigned goes to the if statement.)
                    if (avalibility == 0)
                    {
                        var recordData = new RecordsTable {
                            BookId = BookId, customerId = customerid, isApproved = false, IssueDate = DateTime.Now, ReturnDate = DateTime.Now.AddDays(7)
                        };
                        entities.RecordsTables.Add(recordData);
                        entities.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.Message = "Book is borrowed already!";
                        return(View(BookList));
                    }
                }
                else
                {
                    ViewBag.Message = "Book is not available";
                    return(View(BookList));
                }
            }
            return(View(BookList));
        }
Ejemplo n.º 8
0
        public ActionResult Authorize(LibrarySystem.Models.Customer customerModel)
        {
            using (librarySystem db = new librarySystem())
            {
                //var customerDetail = db.Customers.Where(x => x.customerName == customerModel.customerName && x.password == customerModel.password).FirstOrDefault();
                //if (customerDetail == null)
                //{
                //    ViewBag.DuplicateMessage = "Wrong Username and Password";
                //    return View("Index", customerModel);
                //}
                //else
                //{
                //    Session["customerName"] = customerDetail.customerName;
                //    Session["customerId"] = customerDetail.customerId;
                //    return RedirectToAction("Index", "Home");
                //}


                var customerDetail = db.Customers.Where(x => x.customerName == customerModel.customerName && x.password == customerModel.password).FirstOrDefault();
                if (customerModel.customerName == "admin" && customerModel.password == "admin")
                {
                    return(RedirectToAction("Index", "Admin"));    //opens admin Dashboard.
                }
                else if (customerDetail == null)
                {
                    ViewBag.DuplicateMessage = "Wrong Username and Password";
                    return(View("Index", customerModel));
                }

                else
                {
                    Session["customerName"] = customerDetail.customerName;
                    Session["customerId"]   = customerDetail.customerId;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
        }