public ActionResult ChangePassword(AccountRoomModel model) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather than return false in certain failure scenarios. try { if (WebSecurity.ChangePassword(User.Identity.Name, model.PasswordModel.OldPassword, model.PasswordModel.NewPassword)) { ViewBag.StatusMessage = "Your password has been changed."; return PartialView("_ChangePasswordPartial"); } } catch { } } ViewBag.StatusMessage = "Your password has not been changed."; return PartialView("_ChangePasswordPartial"); //return Json(new { changeMessage = "Password was not changed" }, JsonRequestBehavior.AllowGet); }
public ActionResult AddBook(AccountRoomModel model) { using (var con = new LibraryContext()) { con.Books.Add(new Book { Author = model.EditBook.Author, Name = model.EditBook.Name, Description = model.EditBook.Description, ISBN = model.EditBook.Isbn }); con.SaveChanges(); model.AllBooks = con.Books.Take(10).ToList(); } return PartialView("Librarian/_EditBooksDatabasePartial", model); }
public bool ReserveTheBook(AccountRoomModel model) { var selectedBook = db.Books.SingleOrDefault(book => book.BookId == model.BorrowLend.BookId); DateTime fromDateTime; DateTime toDateTime; if (!DateTime.TryParseExact(model.BorrowLend.FromDate, "dd-MM-yyyy", null, DateTimeStyles.None, out fromDateTime)) { if (!DateTime.TryParseExact(model.BorrowLend.FromDate, "dd/MM/yyyy", null, DateTimeStyles.None, out fromDateTime)) { if (!DateTime.TryParseExact(model.BorrowLend.FromDate, "dd.MM.yyyy", null, DateTimeStyles.None, out fromDateTime)) { return false; } } } if (!DateTime.TryParseExact(model.BorrowLend.ToDate, "dd-MM-yyyy", null, DateTimeStyles.None, out toDateTime)) { if (!DateTime.TryParseExact(model.BorrowLend.ToDate, "dd/MM/yyyy", null, DateTimeStyles.None, out toDateTime)) { if (!DateTime.TryParseExact(model.BorrowLend.ToDate, "dd.MM.yyyy", null, DateTimeStyles.None, out toDateTime)) { return false; } } } if (toDateTime < fromDateTime) { return false; } if (selectedBook != null) { db.UsersToBooks.Add(new UserBook { Book = selectedBook, BookId = selectedBook.BookId, EndDate = toDateTime, LibraryUser = db.LibraryUsers.Single(usr => usr.UserName == User.Identity.Name), LibraryUserId = db.LibraryUsers.Single(usr => usr.UserName == User.Identity.Name).LibraryUserId, StartDate = fromDateTime, Status = (int)ReserveStatus.WaitForPickup }); } db.SaveChanges(); return true; }
public ActionResult SearchBooks(AccountRoomModel model) { return null; }
//ManageMessageId? message // // GET: /Account/Manage public ActionResult Manage() { ViewBag.IsLibrarian = User.IsInRole("Librarian"); var model = new AccountRoomModel(); using (var con = new LibraryContext()) { model.LibraryUser = con.LibraryUsers.Include("UserBookCollection") .SingleOrDefault(la => la.LibraryUserId == WebSecurity.CurrentUserId); model.AllBooks = con.Books.Take(10).ToList(); model.PasswordModel = new LocalPasswordModel(); model.EditBook = new CrudBookModel(); } return View(model); }
public void SaveUser(AccountRoomModel model) { var password = Membership.GeneratePassword(10, 4); WebSecurity.CreateUserAndAccount(model.AddUser.UserName, password, new { Email = model.AddUser.Email }); Roles.AddUsersToRoles(new[] { model.AddUser.UserName }, new[] { "Reader" }); //SendMail(model.AddUser.Email, password); }