public IActionResult CreateIdea(string newidea, int userId) { if (newidea == null) { ViewBag.NewIdeaError = new List <string>() { "Ideas cannot be blank, please enter a valid text" }; int? CurrentUserId = HttpContext.Session.GetInt32("LoggedInUser"); User CurrentUser = _context.User.SingleOrDefault(user => user.UserId == (int)CurrentUserId); ViewBag.CurrentUser = CurrentUser; return(View("Home")); } Idea newIdea = new Idea() { Content = newidea, UserId = userId, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _context.Idea.Add(newIdea); _context.SaveChanges(); return(RedirectToAction("Home")); }
public IActionResult Create(Event input, string hm) { DateTime test = DateTime.Now; IsLoggedIn(); TimeSpan time = TimeSpan.Parse(input.Time.ToString()); input.Time = string.Format("{0:hh:mm tt}", input.Time); int? uid = HttpContext.Session.GetInt32("userid"); List <User> users = _context.users.ToList(); User account = users.SingleOrDefault(x => (x.UserId == uid)); input.Date = input.Date.Add(time); input.Creator = account.UserId; input.CreatorName = account.FirstName; if (DateTime.Compare(input.Date, test) < 0) { ViewBag.Error = "Date must be after now"; return(View("New")); } _context.events.Add(input); _context.SaveChanges(); return(RedirectToAction("Event", new{ num = input.EventId })); }
public IActionResult addactivity(ActivityViewModel act) { if (act.Date.ToString().Contains("1/1/0001")) { ViewBag.dateErr = "Please specify a valid date"; return(View("new")); } if (ModelState.IsValid) { int? active = HttpContext.Session.GetInt32("ActiveUser"); TimeSpan ts = act.Time; act.Date = act.Date + ts; Activity newact = new Activity { Title = act.Title, Description = act.Description, Date = act.Date, Time = act.Time, Duration = act.Duration, UsersId = (int)active }; _context.Add(newact); _context.SaveChanges(); return(Redirect($"viewevent/{newact.ActivityId}")); } else { return(View("new")); } }
public IActionResult Create(Users user) { //Save your user object to the database _context.Add(user); _context.SaveChanges(); HttpContext.Session.SetInt32("UserID", user.UsersId); return(RedirectToAction("DashBoard")); }
public IActionResult Remove(int id) { Post SelectedPost = dbContext.Posts.FirstOrDefault(p => p.PostId == id); dbContext.Remove(SelectedPost); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult CreateActivity(ValidPlan newplan) { int?Id = HttpContext.Session.GetInt32("LoggedUser"); if (Id != null) { if (ModelState.IsValid) { TimeSpan ts = new TimeSpan(0, 0, 0); if (newplan.Unit == "Hours") { int duration = Int32.Parse(newplan.Duration); ts = new TimeSpan(duration, 0, 0); } else if (newplan.Unit == "Minutes") { int duration = Int32.Parse(newplan.Duration); ts = new TimeSpan(0, duration, 0); } else if (newplan.Unit == "Days") { int duration = Int32.Parse(newplan.Duration); ts = new TimeSpan(duration, 0, 0, 0); } User LoggedUser = _context.Users.SingleOrDefault(user => user.UserId == Id); DateTime end = newplan.Start.Add(ts); Plan plan = new Plan { CreatorId = (int)Id, Title = newplan.Title, Coordinator = LoggedUser.FirstName, Start = newplan.Start, End = end, Duration = newplan.Duration + " " + newplan.Unit, Description = newplan.Description, created_at = DateTime.Now }; _context.Add(plan); _context.SaveChanges(); List <Plan> Plans = _context.Plans.OrderByDescending(w => w.created_at).ToList(); int thisPlan = Plans.First().PlanId; return(Redirect($"activity/{thisPlan}")); } else { return(View("NewActivity")); } } else { return(RedirectToAction("Index")); } }
public IActionResult AddIdea(Idea model) { if (ModelState.IsValid) { Idea i = new Idea { IdeaText = model.IdeaText, CreatorId = (int)HttpContext.Session.GetInt32("id") }; _context.Ideas.Add(i); _context.SaveChanges(); } return(RedirectToAction("Dash")); }
public IActionResult ProcEvent(Event evt, int Duration, string durSpec) { int?SessionUserId = HttpContext.Session.GetInt32("user_id"); if (SessionUserId == null) { return(RedirectToAction("Login", "Login")); } if (ModelState.IsValid) { evt.Date += evt.Time; switch (Int32.Parse(durSpec)) { case 0: evt.Duration = TimeSpan.FromDays(Duration); break; case 1: evt.Duration = TimeSpan.FromHours(Duration); break; case 2: evt.Duration = TimeSpan.FromMinutes(Duration); break; default: ModelState.AddModelError("Duration", "Invalid Duration entry. Please try again"); return(View("New", evt)); } User modelUser = dbContext.users .FirstOrDefault(u => u.UserId == SessionUserId); if (DateTime.Compare(evt.Date, DateTime.Now) < 0) { ModelState.AddModelError("Date", "Date must be held in the future!"); return(View("New", evt)); } evt.UserId = (int)SessionUserId; evt.CreatedBy = modelUser.firstName; dbContext.events.Add(evt); dbContext.SaveChanges(); return(RedirectToAction("Activity", new { evt.EventId })); } return(View("New", evt)); }
public IActionResult AddTheActivity(Models.Activity activity) { activity.UserId = (int)HttpContext.Session.GetInt32("UserId"); if (ModelState.IsValid) { dbContext.Add(activity); dbContext.SaveChanges(); } else { return(View("AddActivity")); } return(RedirectToAction("Success")); }
public IActionResult Join(int activityid) { RSVP rsvp = new RSVP(); var uid = HttpContext.Session.GetInt32("Uid"); Activity aobj = dbContext.Activities.FirstOrDefault(i => i.activityid == activityid); User userobj = dbContext.Users.FirstOrDefault(i => i.userid == uid); rsvp.userid = (int)uid; rsvp.activityid = activityid; rsvp.activity = aobj; rsvp.user = userobj; dbContext.Add(rsvp); dbContext.SaveChanges(); return(RedirectToAction("Allactivities")); }
public IActionResult RemoveAct(int id) { int?userSessionId = HttpContext.Session.GetInt32("user_id"); if (userSessionId == null) { System.Console.WriteLine("session id is null"); return(View("Register")); } Act ActtoRemove = dbContext.activities.FirstOrDefault(c => c.ActId == id); dbContext.Remove(ActtoRemove); dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Create(Idea newIdea) { if (uid == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { newIdea.UserId = (int)uid; db.Add(newIdea); db.SaveChanges(); return(RedirectToAction("Dashboard")); } return(View("New")); }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (db.Users.Any(user => user.Email == newUser.Email)) { ModelState.AddModelError("Email", "is taken"); return(View("Index")); } } else { return(View("Index")); } PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, newUser.Password); db.Users.Add(newUser); db.SaveChanges(); HttpContext.Session.SetInt32("UserId", newUser.UserId); HttpContext.Session.SetString("FirstName", newUser.FirstName); return(RedirectToAction("Dashboard", "Ideas")); }
public IActionResult Register(RegisterUser model) { TryValidateModel(model); if(ModelState.IsValid) { User newUser = new User() { Name = model.Name, Alias = model.Alias, Email = model.Email, Password = model.Password, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _context.User.Add(newUser); _context.SaveChanges(); var ReturnedUser = _context.User.SingleOrDefault(user => user.Email == newUser.Email); System.Console.WriteLine($"Line 80*************************this is the newly registered user {ReturnedUser}"); HttpContext.Session.SetInt32("LoggedInUser", (int)ReturnedUser.UserId); return RedirectToAction("Home", "Ideas"); } // } ViewBag.Errors = ModelState.Values; return View("Index"); }
public IActionResult Register(Users NewUser) { if (ModelState.IsValid) { Users RegisteredUser = _context.Users.SingleOrDefault(i => i.Email == NewUser.Email); if (RegisteredUser != null) { // ViewBag.Message = "This email exists. Please use a different email."; ModelState.AddModelError("Email", "This email exists. Please use a different email."); return(View("Index")); } PasswordHasher <Users> Hasher = new PasswordHasher <Users>(); NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password); _context.Users.Add(NewUser); _context.SaveChanges(); NewUser = _context.Users.SingleOrDefault(i => i.Email == NewUser.Email); HttpContext.Session.SetInt32("CurrentUser", NewUser.UserId); int?AccountId = HttpContext.Session.GetInt32("CurrentUser"); ViewBag.CurrentUser = NewUser; // return RedirectToAction("Account", "Transactions", new{AccountId}); return(RedirectToAction("Dashboard", "Ideas")); //Handle success } // return RedirectToAction("Index"); return(View("Index")); }
public IActionResult Register(User user) { if (ModelState.IsValid) { // If a User exists with provided email if (dbContext.Users.Any(u => u.Email == user.Email)) { // Manually add a ModelState error to the Email field, with provided // error message ModelState.AddModelError("Email", "Email already in use!"); return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); dbContext.Add(user); dbContext.SaveChanges(); HttpContext.Session.SetInt32("UserId", user.UserId); return(RedirectToAction("Success", "Home")); } } else { return(View("Index")); } }
public IActionResult Register(RegisterViewModel user) { if (ModelState.IsValid) { PasswordHasher <RegisterViewModel> Hasher = new PasswordHasher <RegisterViewModel>(); user.Password = Hasher.HashPassword(user, user.Password); User check = _context.Users.SingleOrDefault(a => a.Email == user.Email); if (check != null) { ViewBag.Error = "User already exists"; return(View("Index")); } User u = new User { Name = user.Name, Alias = user.Alias, Email = user.Email, Password = user.Password }; // HttpContext.Session.SetString("email", u.Email); _context.Add(u); _context.SaveChanges(); User newUser = _context.Users.SingleOrDefault(a => a.Email == user.Email); HttpContext.Session.SetInt32("id", newUser.UserId); return(RedirectToAction("Dash", "Idea")); } return(View("Index")); }
public IActionResult ProcRegister(User newUser) { if (ModelState.IsValid) { if (dbContext.users.Any(u => u.email == newUser.email)) { ModelState.AddModelError("Email", "Email already in use!"); return(View("_RegistrationPartial", newUser)); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); newUser.password = Hasher.HashPassword(newUser, newUser.password); dbContext.Add(newUser); dbContext.SaveChanges(); User user = dbContext.users.FirstOrDefault(u => u.email == newUser.email); HttpContext.Session.SetString("logged", "yes"); HttpContext.Session.SetInt32("user_id", user.UserId); return(RedirectToAction("Home", "Activity")); } } else { return(View("_RegistrationPartial", newUser)); } }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { if (db.Users.Any(user => user.Email == newUser.Email)) { ModelState.AddModelError("Email", "is taken"); // display manually added error message return(View("Index")); } } else { // display auto added error messages return(View("Index")); } PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, newUser.Password); db.Users.Add(newUser); db.SaveChanges(); // add session to be logged in HttpContext.Session.SetInt32("UserId", newUser.UserId); HttpContext.Session.SetString("FirstName", newUser.FirstName); // HttpContext.Session.SetInt32(""); return(RedirectToAction("Index")); }
private void BuildActivity(ValidActivitie activity) { Activitie NewActivity = new Activitie { Title = activity.Title, Description = activity.Description, Date = activity.Date, Time = activity.Time, Duration = activity.Duration, DurationMod = activity.DurationMod, CreatorId = activity.CreatorId, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; _context.Activities.Add(NewActivity); _context.SaveChanges(); }
public IActionResult NewActivity(PlanViewModel model) { if (HttpContext.Session.GetInt32("id") == null) { return(Redirect("/")); } if (ModelState.IsValid) { TimeSpan duration; if (model.Unit == "days") { duration = new TimeSpan(model.Duration, 0, 0, 0); } else if (model.Unit == "hours") { duration = new TimeSpan(0, model.Duration, 0, 0); } else { duration = new TimeSpan(0, 0, model.Duration, 0); } DateTime starttime = model.Date + model.Time; if (starttime < DateTime.Now) { ViewBag.TimeError = 2; return(View("New")); } Activity NewAct = new Activity { Title = model.Title, Desc = model.Desc, StartTime = starttime, Duration = duration, // ThisDur = model.Duration, // Unit = model.Unit, CreatedAt = DateTime.Now, UserId = (int)HttpContext.Session.GetInt32("id"), }; _context.Add(NewAct); _context.SaveChanges(); Activity thisactivity = _context.Activities.OrderByDescending(a => a.CreatedAt).FirstOrDefault(); int num = thisactivity.ActivityId; return(Redirect("/activity/" + num)); } return(View("New")); }
public IActionResult New(ActivityView model) { if (ModelState.IsValid) { Activity NewActivity = new Activity(); NewActivity.Title = model.Title; NewActivity.Time = model.Time; NewActivity.Date = model.Date; NewActivity.Duration = model.Duration; NewActivity.Address = model.Address; NewActivity.Description = model.Description; NewActivity.UserId = ActiveUser.UserId; _context.Activities.Add(NewActivity); _context.SaveChanges(); return(RedirectToAction("Show", new { id = NewActivity.ActivityId })); } ViewBag.errors = ModelState.Values; return(View("CreateActivity")); }
public IActionResult Update(User update) { int id = (int)HttpContext.Session.GetInt32("id"); System.Console.WriteLine(id); update.UserId = id; dbContext.Users.Update(update); dbContext.SaveChanges(); return(RedirectToAction("Success")); }
public IActionResult Registration(RegisterViews ruser) { if (ModelState.IsValid) { List <User> isuser = _context.users.Where(useri => useri.Email == ruser.Email).ToList(); if (isuser.Count() > 0) { string message = "There is already another user with this email!Please use other email!"; ViewBag.message = message; return(View("Index")); } User neWuser = new User() { FirstName = ruser.FirstName, LastName = ruser.LastName, Email = ruser.Email, Password = ruser.Password, }; _context.users.Add(neWuser); _context.SaveChanges(); List <User> users = _context.users.ToList(); HttpContext.Session.SetInt32("Session", users[users.Count() - 1].UserId); return(RedirectToAction("Home")); } return(View("Index")); }
public IActionResult Index() { User CurrentUser = GetCurrentUserAsync().Result; List <Meet> Meets = _context.Meets.Include(user => user.User).Include(p => p.Participants).ToList(); foreach (Meet meet in Meets) { if (meet.Date.Add(meet.Duration) < DateTime.Now) { _context.Meets.Remove(meet); _context.SaveChanges(); } } List <Meet> AllMeets = _context.Meets.Include(user => user.User).Include(p => p.Participants).ToList(); ViewBag.Register = new RegisterViewModel(); ViewBag.Login = new LoginViewModel(); ViewBag.AllMeets = AllMeets; ViewBag.User = CurrentUser; ViewBag.JoinError = TempData["JoinError"]; return(View("Index")); }
public IActionResult Activity_Center() { if (HttpContext.Session.GetString("Login") == null || HttpContext.Session.GetString("Login") != "True") { HttpContext.Session.SetString("login", "False"); return(Redirect("/")); } List <Activity> allActivities = dbContext.Activity.ToList(); foreach (var a in allActivities) { if (a.date_time < DateTime.Now.Date) { dbContext.Activity.Remove(a); dbContext.SaveChanges(); } } ViewBag.fname = HttpContext.Session.GetString("fname"); ViewBag.allusers = dbContext.Users; ViewBag.allActivities = dbContext.Activity.Include(a => a.Participate).ThenInclude(u => u.User).ToList(); ViewBag.id = HttpContext.Session.GetInt32("id"); return(View("activity_center")); }
public IActionResult Register(LoginRegViewModel modelData) { User creatingUser = modelData.newUser; if (ModelState.IsValid) { if (dbContext.users.Any(u => u.Email == creatingUser.Email)) { ModelState.AddModelError("Email", "Email is already in use!"); return(View("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); creatingUser.Password = Hasher.HashPassword(creatingUser, creatingUser.Password); dbContext.Add(creatingUser); dbContext.SaveChanges(); if (HttpContext.Session.GetInt32("UserId") == null) { HttpContext.Session.SetInt32("UserId", creatingUser.UserId); } System.Console.WriteLine("******************"); System.Console.WriteLine("reg working"); return(RedirectToAction("Dashboard")); } } else { System.Console.WriteLine("*******************"); System.Console.WriteLine("REGISTRATION NOT WORKING!!!!"); System.Console.WriteLine(creatingUser.FirstName); System.Console.WriteLine(creatingUser.LastName); System.Console.WriteLine(creatingUser.Email); System.Console.WriteLine("*******************"); return(View("Index")); } }
private void BuildUser(ValidRegUser user) { User NewUser = new User { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = user.Password, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }; PasswordHasher <User> Hasher = new PasswordHasher <User>(); string hashed = Hasher.HashPassword(NewUser, user.Password); NewUser.Password = hashed; _context.Users.Add(NewUser); _context.SaveChanges(); }
public IActionResult RegisterProcess(User user) { if (ModelState.IsValid) { if (dbContext.Users.Any(u => u.email == user.email)) { ModelState.AddModelError("email", "Email is already in use"); return(RedirectToAction("Register")); } PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.password = Hasher.HashPassword(user, user.password); dbContext.Add(user); dbContext.SaveChanges(); var UserId = dbContext.Users.FirstOrDefault(u => u.userid == user.userid); HttpContext.Session.SetInt32("Uid", UserId.userid); return(RedirectToAction("Allactivities", "Activity")); } return(View("Register")); }
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("/Home")); } return(View("Index")); }