public IActionResult CreateUser(RegisterUser u) { if (ModelState.IsValid) { List <User> users = _context.users.Where(nu => nu.Email == u.Email).ToList(); if (users.Count > 0) { ViewBag.InvalidEmail = true; return(View("Index")); } PasswordHasher <User> Hasher = new PasswordHasher <User>(); User nUser = new User(); nUser.Password = Hasher.HashPassword(nUser, u.Password); nUser.FirstName = u.FirstName; nUser.LastName = u.LastName; nUser.Email = u.Email; // nUser.Wallet = 1000.00; _context.Add(nUser); _context.SaveChanges(); HttpContext.Session.SetInt32("UserId", nUser.UserId); return(Redirect("/dashboard")); } return(View("Index")); }
public IActionResult CreateActivity(ViewActivity na) { int?LogId = HttpContext.Session.GetInt32("UserId"); if (LogId == null) { return(Redirect("/")); } User user = _context.users.Where(u => u.UserId == LogId).SingleOrDefault(); ViewBag.LoggedUser = user; if (ModelState.IsValid) { //make a new event Activity addActivity = new Activity { Title = na.Title, Description = na.Description, Duration = na.Duration, DurationType = na.DurationType, CreatorId = (int)LogId }; //fiddle with the date and time to get it into one DateTime addActivity.DateTime = na.Date.Add(na.Time.TimeOfDay); // addActivity.DateTime.AddHours(na.Time.Hour); // addActivity.DateTime.AddMinutes(na.Time.Minute); //add activity to db _context.activities.Add(addActivity); //make a new rsvp for the event creator RSVP creatorRsvp = new RSVP { Attendee = user, Activity = addActivity }; //add rsvp to db _context.rsvps.Add(creatorRsvp); _context.SaveChanges(); return(Redirect("/dashboard")); } return(View("NewActivity")); }