public IActionResult Register(UserViewModels model) { if (ModelState.IsValid) { List <User> users = _context.Users.Where(u => u.Email == model.Registration.Email).ToList(); if (users.Count > 0) { ModelState.AddModelError("Email", "Email already exists"); return(View("Index", model)); } PasswordHasher <UserViewModels> hasher = new PasswordHasher <UserViewModels>(); string hashedPassword = hasher.HashPassword(model, model.Registration.Password); User user = new User { FirstName = model.Registration.FirstName, LastName = model.Registration.LastName, Email = model.Registration.Email, Password = hashedPassword }; _context.Add(user); _context.SaveChanges(); HttpContext.Session.SetInt32("id", user.ID); return(RedirectToAction("Dashboard", "Planner")); } return(View("Index", model)); }
public IActionResult Register(UserViewModels model) { if (ModelState.IsValid) { User exists = _context.Users.SingleOrDefault(u => u.Email == model.Reg.Email); if (exists != null) { ModelState.AddModelError("Reg.Email", "This is email is already registered!"); return(View("Index")); } PasswordHasher <UserViewModels> hasher = new PasswordHasher <UserViewModels>(); string hashed = hasher.HashPassword(model, model.Reg.Password); User newUser = new User { FirstName = model.Reg.FirstName, LastName = model.Reg.LastName, Email = model.Reg.Email, Password = hashed }; _context.Add(newUser); _context.SaveChanges(); int id = _context.Users.Where(u => u.Email == model.Reg.Email).Select(u => u.UserId).SingleOrDefault(); HttpContext.Session.SetInt32("id", id); return(RedirectToAction("Home", "Weddings")); } return(View("Index")); }
public IActionResult Register(RegisterViewModel user) { Console.WriteLine("registering..."); if (ModelState.IsValid) { User check = _context.Users.SingleOrDefault(a => a.Email == user.Email); if (check != null) { ViewBag.Error = "User already exists"; return(View("Index")); } PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>(); user.Password = Hasher.HashPassword(user, user.Password); User u = new User { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = user.Password, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; // HttpContext.Session.SetString("email", u.Email); System.Console.WriteLine("about to save"); _context.Add(u); _context.SaveChanges(); User newUser = _context.Users.SingleOrDefault(a => a.Email == user.Email); HttpContext.Session.SetInt32("id", newUser.UserId); System.Console.WriteLine("about to redirect"); return(RedirectToAction("Wedding", "Wedding")); } return(View("Index")); }
public async Task <IActionResult> Create([Bind("Id,Date,Theme,OpeningSong,OpeningPrayer,Conducting,SacramentHymn,Speaker1,TalkTopic1,Speaker2,TalkTopic2,ClosingSong,ClosingPrayer")] Plan plan) { if (ModelState.IsValid) { _context.Add(plan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(plan)); }
public IActionResult CreateWedding(Wedding wedding) { if (CheckSession() == 0) { return(RedirectToAction("Index", "Users")); } if (ModelState.IsValid) { if (wedding.Date < DateTime.Now) { ModelState.AddModelError("Date", "Date must a future date"); return(View("NewWedding")); } wedding.UserId = CheckSession(); _context.Add(wedding); _context.SaveChanges(); return(RedirectToAction("Home")); } return(View("NewWedding")); }
public async Task <IActionResult> Create([Bind("Name")] Assignment assignment) { if (ModelState.IsValid) { _context.Add(assignment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(assignment)); }
public async Task <IActionResult> Create([Bind("ID,SacramentDate,Conducting,OpeningHymn,Invocation,SacramentHymn,FirstSpeaker,SecondSpeaker,RestHymn,ThirdSpeaker,ClosingHymn,Convocation")] Sacrament sacrament) { if (ModelState.IsValid) { _context.Add(sacrament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sacrament)); }
public async Task <IActionResult> Create([Bind("ID,SacramentDate,Conducting,Hymns,Prayer,Speakers,Subject")] Sacrament sacrament) { if (ModelState.IsValid) { _context.Add(sacrament); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sacrament)); }
public async Task <IActionResult> Create([Bind("HomeworkId,CourseId,AssignmentId,Due,Description")] Homework homework) { if (ModelState.IsValid) { _context.Add(homework); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AssignmentId"] = new SelectList(_context.Assignment, "AssignmentId", "Name", homework.AssignmentId); ViewData["CourseId"] = new SelectList(_context.Course, "CourseId", "Name", homework.CourseId); return(View(homework)); }
public IActionResult NewWedding(PlanViewModel model) { if (ModelState.IsValid) { Wedding NewWed = new Wedding { Wedder1 = model.Wedder1, Wedder2 = model.Wedder2, Date = model.Date, Address = model.Address, UserId = (int)HttpContext.Session.GetInt32("id"), }; _context.Add(NewWed); _context.SaveChanges(); return(Redirect("/dashboard")); } return(View("PlanWedding")); }
public IActionResult Create(WeddingCreation model) { if (ModelState.IsValid) { Wedding wedding = new Wedding { UserID = (int)HttpContext.Session.GetInt32("id"), Groom = model.Groom, Bride = model.Bride, Date = model.Date, Address = model.Address, }; _context.Add(wedding); _context.SaveChanges(); return(RedirectToAction("Dashboard")); } return(View("New", model)); }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { User NewUser = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Password = model.Password }; PasswordHasher <User> Hasher = new PasswordHasher <User>(); NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password); _context.Add(NewUser); _context.SaveChanges(); User thisuser = _context.Users.SingleOrDefault(a => a.Email == model.Email); HttpContext.Session.SetInt32("id", (int)thisuser.UserId); return(Redirect("/dashboard")); } return(View("Index")); }