// // 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")); }
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()); }
[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())); }
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)); }