public ActionResult Create(TakeABookCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } TakeABook takeABook = new TakeABook(); takeABook.BookId = model.BookId; if (UserLogin.IsAdmin()) { takeABook.UserId = model.UserId; } else { takeABook.UserId = UserLogin.GetUserId(); } //takeABook.dateTaken = model.dateTaken.Date; takeABook.DateTaken = System.DateTime.Now; // takeABook.dateForReturn = model.dateForReturn.Date; takeABook.DateForReturn = takeABook.DateTaken.AddMonths(3); //takeABook.dateReturn = model.dateReturn.Date; DateTime now = DateTime.Now; takeABook.DateReturn = new DateTime(2000, 1, 1, 0, 0, 0); var repository = new TakeABookRepository(); repository.Insert(takeABook); return(RedirectToAction("Index")); }
public ActionResult Index() { TakeABookRepository repository = new TakeABookRepository(); List <TakeABook> takeABooks = repository.GetAll(); List <TakeABook> takeABook = new List <TakeABook>(); if (UserLogin.IsAdmin()) { takeABook = takeABooks; } else { foreach (var item in takeABooks) { if (item.UserId == UserLogin.GetUserId()) { takeABook.Add(item); } } } TakeABookListViewModel model = new TakeABookListViewModel(); model.TakeABooks = takeABook; return(View(model)); }
public ActionResult Index() { TakeABookRepository repository = new TakeABookRepository(); List <TakeABook> takeABooks = repository.GetAll(); TakeABookListViewModel model = new TakeABookListViewModel(); model.TakeABooks = takeABooks; return(View(model)); }
public ActionResult Delete(TakeABookDeleteViewModel model) { TakeABookRepository repository = new TakeABookRepository(); if (model.Id.ToString() != String.Empty) { repository.Delete(model.Id); } return(RedirectToAction("Index")); }
public ActionResult Delete(int id) { TakeABookRepository repository = new TakeABookRepository(); TakeABook takeABook = repository.GetById(id); TakeABookDeleteViewModel model = new TakeABookDeleteViewModel(); // model.Id = takeABook.Id; model.BookId = takeABook.BookId; model.UserId = takeABook.UserId; model.dateTaken = takeABook.DateTaken; model.dateForReturn = takeABook.DateForReturn; model.dateReturn = takeABook.DateReturn; return(View(model)); }
public ActionResult Edit(int?id) { TakeABookRepository repository = new TakeABookRepository(); TakeABookEditViewModel model = new TakeABookEditViewModel(); if (id.HasValue) { TakeABook takeABook = repository.GetById(id.Value); model.Id = takeABook.Id; model.Books = PopuateBooksList(); model.Users = PopuateUsersList(); model.dateTaken = takeABook.DateTaken.Date; model.dateForReturn = takeABook.DateForReturn.Date; model.dateReturn = takeABook.DateReturn.Date; } return(View(model)); }
public ActionResult Create(TakeABookCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } TakeABook takeABook = new TakeABook(); takeABook.BookId = model.BookId; takeABook.ReaderId = model.ReaderId; takeABook.dateTaken = model.dateTaken.Date; takeABook.dateForReturn = model.dateForReturn.Date; takeABook.dateReturn = model.dateReturn.Date; var repository = new TakeABookRepository(); repository.Insert(takeABook); return(RedirectToAction("Index")); }
public ActionResult Edit(TakeABookEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } TakeABookRepository repository = new TakeABookRepository(); TakeABook takeABook = new TakeABook(); takeABook.Id = model.Id; takeABook.BookId = model.BookId; takeABook.UserId = model.UserId; takeABook.DateTaken = model.dateTaken.Date; takeABook.DateForReturn = model.dateForReturn.Date; takeABook.DateReturn = model.dateReturn.Date; repository.Save(takeABook); return(RedirectToAction("Index")); }