public ActionResult Admin(FormCollection form) { string value = Convert.ToString(form["inputName"]); string lim = Convert.ToString(form["limit"]); DB db = new DB(); //ViewBag.Longlife = "Długość wypożyczenia: " + db.Longlifes.Last(); if (value != null && value != "") { int days = Int32.Parse(value); Longlife l = db.Longlifes.Where(x => x.LonglifeID == 1).FirstOrDefault(); l.longlife = days; db.Entry(l).State = EntityState.Modified; db.SaveChanges(); ViewBag.Longlife = "Długość wypożyczenia została ustawiona na: " + days + " dni!"; } if (lim != null && lim != "") { int limit = Int32.Parse(lim); Longlife l = db.Longlifes.Where(x => x.LonglifeID == 1).FirstOrDefault(); l.limit = limit; db.Entry(l).State = EntityState.Modified; db.SaveChanges(); ViewBag.Limit = "Limit wypożyczeń został ustawiona na: " + limit + " książek!"; } return(View()); }
public ActionResult Borrow() { BorrowingVM borrowingVM = new BorrowingVM(); RepositoryVM repositoryVM = new RepositoryVM(); var repositories = repositoryVM.Get_list(); var list_book = Session["Zamowienie"] as IEnumerable <Biblioteka.Models.Book>; var userId = (Int32)(Session["adminID"]); if (list_book != null) { DB db = new DB(); Longlife l = db.Longlifes.Where(x => x.LonglifeID == 1).FirstOrDefault(); int days = l.longlife; foreach (var item in list_book) { Repository repo_book = repositories.Where(a => a.RepositoryID == item.Repository.RepositoryID).FirstOrDefault(); if (repo_book.Amount != 0) { Borrowing b = new Borrowing { ReaderID = userId, Borrow_date = DateTime.Now, BookID = item.BookID, PenaltyID = 1, Returned = false, QueueID = 0 }; b.Return_date = b.Borrow_date.AddDays(days); borrowingVM.Dodaj(b); repositoryVM.Minus_amount(repo_book); Session["Zamowienie"] = null; } else { return(RedirectToAction("Borrow_failed"));//trzeba zablokować możliwość wypożyczenia gdy nie jest dostępna } } return(View("Borrow_success")); } return(View()); }