public ActionResult Reserve(int id) { bool isCurrentlyReserved = false; foreach (var reservation in db.Reservations.ToList()) { if (reservation.StartDate < DateTime.Now && reservation.EndDate > DateTime.Now) { foreach (var bookInstance in reservation.Books) { if (bookInstance.BookId == id) { isCurrentlyReserved = true; } } } } if (!isCurrentlyReserved) { Reservation res = new Reservation(); var book = db.Books.Find(id); res.Books.Add(book); res.StartDate = DateTime.Now; res.EndDate = DateTime.Now.AddMonths(1); res.UserId = Auth.GetUserId(); db.Reservations.Add(res); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index() { var offers = from o in db.Offers select o; if (Auth.GetRole() == (int)Auth.Roles.Publisher) { int id = Auth.GetUserId(); offers = offers.Where(o => o.PublisherId == id); } return(View(offers.ToList())); }
public ActionResult Reserve(int id, string d) { Reservation res = new Reservation(); var computer = db.Computers.Find(id); res.Computers.Add(computer); res.StartDate = DateTime.Now; res.EndDate = DateTime.Now.AddDays(1); res.UserId = Auth.GetUserId(); db.Reservations.Add(res); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(Offer offer) { if (ModelState.IsValid) { offer.PublisherId = Auth.GetUserId(); offer.StatusId = 1; offer.StartDate = DateTime.Now; db.Offers.Add(offer); db.SaveChanges(); return(RedirectToAction("Index")); } PopulateOfferDropdowns(offer); return(View()); }