public IActionResult AddUser(UsersValidate uservalidator) { if (ModelState.IsValid) { var emailvalidation = _context.users.SingleOrDefault(p => p.email == uservalidator.email); if (emailvalidation == null) { PasswordHasher <UsersValidate> Hasher = new PasswordHasher <UsersValidate>(); uservalidator.password = Hasher.HashPassword(uservalidator, uservalidator.password); Users myUser = new Users(); myUser.first_name = uservalidator.first_name; myUser.last_name = uservalidator.last_name; myUser.email = uservalidator.email; myUser.password = uservalidator.password; myUser.created_at = DateTime.Now; myUser.updated_at = DateTime.Now; _context.Add(myUser); _context.SaveChanges(); HttpContext.Session.SetInt32("UserID", myUser.id); int?UserID = HttpContext.Session.GetInt32("UserID"); ViewBag.UserID = UserID; return(RedirectToAction("Dashboard")); } else { TempData["uniqueemail"] = "This email belongs to a registered user. Please use another email address"; return(View("Index")); } } else { return(View("Index")); } }
public IActionResult CreateActivity(ActivityViewModel NewActivityViewModel, string TimeDenomination, TimeSpan StartTime) { if (ModelState.IsValid) { int LoggedID = (int)HttpContext.Session.GetInt32("logged_id"); TimeSpan ActivityDuration = new TimeSpan(0, 0, 0); if (TimeDenomination == "Days") { ActivityDuration += new TimeSpan(24 * NewActivityViewModel.Duration, 0, 0); } else if (TimeDenomination == "Hours") { ActivityDuration += new TimeSpan(1 * NewActivityViewModel.Duration, 0, 0); } else { ActivityDuration += new TimeSpan(0, 1 * NewActivityViewModel.Duration, 0); } Activity NewActivity = new Activity() { Name = NewActivityViewModel.Name, Description = NewActivityViewModel.Description, CreatorID = LoggedID, Duration = (int)ActivityDuration.TotalMinutes, StartTime = NewActivityViewModel.StartDate + StartTime }; _context.Activities.Add(NewActivity); _context.SaveChanges(); Activity SavedActivity = _context.Activities.SingleOrDefault(activity => activity.Name == NewActivityViewModel.Name && activity.CreatorID == LoggedID); return(RedirectToAction("ShowActivity", new { ActivityID = SavedActivity.ActivityID })); } return(View("AddActivityForm")); }
public IActionResult Register(UserViewModel FormUser) { if (ModelState.IsValid) { User NewUser = new User { FirstName = FormUser.FirstName, LastName = FormUser.LastName, Email = FormUser.Email, Password = FormUser.Password }; _context.Add(NewUser); _context.SaveChanges(); User results = _context.Users.SingleOrDefault(user => (user.Email == FormUser.Email && user.Password == FormUser.Password)); int id = results.UserID; HttpContext.Session.SetInt32("logged_id", id); return(RedirectToAction("ShowDashboard", "Activity")); } return(View("LoginReg")); }