// See ActivityContext for details on why Seed data is being addressed here. private async Task SeedActivities() { if (!_context.Activity.Any()) { var now = DateTime.Now; _context.Add( new ActivityModel() { Name = "Bingo", Description = "Come join us for an exciting game of Bingo with great prizes.", Date = new DateTime(now.Year, now.Month, now.AddDays(2).Day, 12, 00, 00) } ); _context.Add( new ActivityModel() { Name = "Shuffleboard Competition", Description = "Meet us at the Shuffleboard court!", Date = new DateTime(now.Year, now.Month, now.AddDays(5).Day, 18, 00, 00) } ); await _context.SaveChangesAsync(); } }
public IActionResult ValidateRegistration(User newUser) { if (ModelState.IsValid) { if (dbContext.Users.Any(u => u.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email already in use"); return(View("Index")); } else { dbContext.Add(newUser); // newUser.Created_at = DateTime.Now; // newUser.Updated_at = DateTime.Now; PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.Password = Hasher.HashPassword(newUser, newUser.Password); dbContext.SaveChanges(); HttpContext.Session.SetInt32("LoggedInUserId", newUser.UserId); HttpContext.Session.SetString("LoggedInUserName", newUser.First_Name); return(RedirectToAction("Home")); } } else { return(View("Index")); } }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (DbContext.Users.Any(u => u.Email == newUser.Email)) { ModelState.AddModelError("Email", "Email is already in use! Please log in or use a different email address."); return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.Password = Hasher.HashPassword(newUser, newUser.Password); DbContext.Add(newUser); DbContext.SaveChanges(); HttpContext.Session.SetString("User", newUser.FirstName); HttpContext.Session.SetInt32("UserId", newUser.UserId); System.Console.WriteLine("************* Session User:"******"***************"); return(RedirectToAction("Home")); } } else { return(View("Index")); } }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { if (_context.users.SingleOrDefault(user => user.Email == model.Email) == null) { User NewUser = new User { FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Password = model.Password }; _context.Add(NewUser); _context.SaveChanges(); User CurrentUser = _context.users.SingleOrDefault(user => user.Email == NewUser.Email); return(RedirectToAction("Home", CurrentUser)); } else { ViewBag.error = "Email Already in use"; return(View("Index")); } } else { return(View("Index")); } }
public IActionResult Create(Person person, string ConfirmPass) { ViewBag.error = ""; if (ModelState.IsValid && person.Password == ConfirmPass) { PasswordHasher <Person> Hasher = new PasswordHasher <Person>(); person.Password = Hasher.HashPassword(person, person.Password); //Save your user object to the database _context.Add(person); _context.SaveChanges(); Person ReturnedValue = _context.Users.SingleOrDefault(u => u.Email == person.Email); HttpContext.Session.SetInt32("LogedUserID", ReturnedValue.UserID); return(RedirectToAction("Activities")); } else { if (person.Password != ConfirmPass) { ViewBag.error = "Password did not match"; } return(View("Index")); } }
public IActionResult CreateActivity(ViewActivity newActivity) { if (!isLoggedIn()) { return(Redirect("/")); } if (ModelState.IsValid) { Activity activity = new Activity { Title = newActivity.Title, TimeAndDate = new DateTime(newActivity.Date.Year, newActivity.Date.Month, newActivity.Date.Day, newActivity.Time.Hour, newActivity.Time.Minute, 0), Duration = newActivity.Duration, Description = newActivity.Description, Creator = _context.Users.Single(user => user.UserId == (int)HttpContext.Session.GetInt32("currUser")), CreatorId = (int)HttpContext.Session.GetInt32("currUser") }; _context.Add(activity); _context.SaveChanges(); activity.created_at = DateTime.Now; activity.updated_at = DateTime.Now; _context.SaveChanges(); return(Redirect("/show/" + activity.ActivityId)); } return(View("NewActivity", newActivity)); }
public IActionResult Register(UserViewModels model) { if (ModelState.IsValid) { List <User> users = _context.Users.Where(u => u.Email == model.Register.Email).ToList(); if (users.Count > 0) { ModelState.AddModelError("Email", "Email already exists. Please select a unique email"); return(View("Index", model)); } PasswordHasher <UserViewModels> hasher = new PasswordHasher <UserViewModels>(); string hashedPassword = hasher.HashPassword(model, model.Register.Password); User newUser = new User { FirstName = model.Register.FirstName, LastName = model.Register.LastName, Email = model.Register.Email, Password = hashedPassword }; _context.Add(newUser); _context.SaveChanges(); HttpContext.Session.SetInt32("id", newUser.ID); return(RedirectToAction("Index", "Home")); } return(View("Index", model)); }
public IActionResult ProcessReg(User CurrentUser, string ConfirmPassword) { System.Console.WriteLine("****************************"); System.Console.WriteLine("MADE IT TO PROCESSREG"); System.Console.WriteLine("****************************"); // if(ModelState.IsValid) // { // PasswordHasher<User> Hasher = new Password // } _context.Add(CurrentUser); _context.SaveChanges(); HttpContext.Session.SetInt32("user_id", CurrentUser.UserId); HttpContext.Session.SetString("user_email", CurrentUser.Email); return(RedirectToAction("Home")); }
public IActionResult Join(int id) { // TempData["busy"] = ""; int?UserID = HttpContext.Session.GetInt32("LogedUserID"); if (UserID != null) { Person user = _context.Users.SingleOrDefault(u => u.UserID == UserID); MyActivity activity = _context.Activities.SingleOrDefault(act => act.ActivityID == id); UserActivity userActivity = new UserActivity() { User = user, Activity = activity }; List <UserActivity> otherActivities = _context.UsersActivities .Include(uAct => uAct.User) .Include(uAct => uAct.Activity) .Where(uAct => uAct.User == user) .ToList(); bool busy = false; foreach (var act in otherActivities) { if (act.Activity.ActivityDate == activity.ActivityDate) { busy = true; } } if (busy) { // TempData["busy"] = ":Looks like you already have something scheduled for this date"; return(RedirectToAction("Activities", "Home")); } user.UserActivity.Add(userActivity); activity.UserActivity.Add(userActivity); _context.Add(userActivity); _context.SaveChanges(); } return(RedirectToAction("Activities", "Home")); }
public async Task <ActionResult <ActivityLog> > PostAsync([FromBody] ActivityLog activity) { var user = await _userManager.FindByIdAsync(User.Identity.Name); activity.User = user; db.Add(activity); db.SaveChanges(); return(CreatedAtAction(nameof(Get), new { id = activity.Id }, activity)); }
public IActionResult Create(ActivityModel model, string stringDuration) { if (ModelState.IsValid) { ActivityModel newActivity = new ActivityModel { UserID = (int)HttpContext.Session.GetInt32("id"), Title = model.Title, Time = model.Time, Date = model.Date, Duration = model.Duration + " " + stringDuration, Description = model.Description, }; _context.Add(newActivity); _context.SaveChanges(); return(RedirectToAction("Activity", new{ id = newActivity.ID })); } return(View("New", model)); }
public async Task <IActionResult> Create([Bind("Id,Description,Date,Category")] ActivityLog activityLog) { if (ModelState.IsValid) { _context.Add(activityLog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(activityLog)); }
public IActionResult Create(User user) { if (ModelState.IsValid) { bool accept = true; var exists = dbContext.Users.FirstOrDefault(e => e.Email == user.Email); if (exists != null) { System.Console.WriteLine("Email Exists"); ModelState.AddModelError("Email", "Email already exists"); accept = false; } if (user.Password != user.Confirm) { ModelState.AddModelError("Confirm", "Passwords do not match"); accept = false; } if (accept == false) { System.Console.WriteLine("Bad Password"); return(View("index")); } PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); dbContext.Add(user); dbContext.SaveChanges(); HttpContext.Session.SetInt32("User", user.UserId); System.Console.WriteLine(user.UserId); HttpContext.Session.SetString("Name", user.Name); return(RedirectToAction("home")); } else { System.Console.WriteLine("Return to Create"); return(View("index")); } }
public async Task <IActionResult> Create([Bind(SPECIAL_ACTIVITY_PARAMETERS)] SpecialActivity specialActivity) { if (!ModelState.IsValid) { return(View(specialActivity)); } _context.Add(specialActivity); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Create(Event activity) { if (!UserLoggedIn()) { return(RedirectToAction("Index", "User")); } ViewBag.UserId = HttpContext.Session.GetInt32("UserId"); if (ModelState.IsValid) { _context.Add(activity); _context.SaveChanges(); return(RedirectToRoute("View Event", new { EventId = activity.EventId })); } return(View("New")); }
//validate the submission and add the activity to the db public IActionResult CreateActivity(Activity act) { //check whether user is logged in, and if so get session variables (user id and name) int?userId = HttpContext.Session.GetInt32("UserId"); if (userId == null) { return(RedirectToAction("Index", "User")); } if (ModelState.IsValid) { //set current user as activity creator and add to db act.UserId = (int)userId; _context.Add(act); _context.SaveChanges(); return(RedirectToAction("Dashboard")); } //show add page with errors return(View("Add")); }