public IActionResult Create(Event newEvent)
        {
            if (ModelState.IsValid)
            {
                if (newEvent.Date < DateTime.Now)
                {
                    ModelState.AddModelError("Date", "Date must be in the future");
                    ViewBag.UserId = HttpContext.Session.GetInt32("UserId");
                    return(View("AddEvent"));
                }

                else
                {
                    dbContext.Add(newEvent);
                    dbContext.SaveChanges();

                    return(RedirectToAction("Details", new { id = newEvent.EventId }));
                }
            }

            else
            {
                System.Console.WriteLine("********Error Count*********");
                System.Console.WriteLine(ModelState.ErrorCount);
                System.Console.WriteLine("*****************");

                ViewBag.UserId = HttpContext.Session.GetInt32("UserId");
                return(View("AddEvent"));
            }
        }
        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)
            {
                Activity addActivity = new Activity {
                    Title = na.Title, Description = na.Description, Duration = na.Duration, DurationType = na.DurationType, CreatorId = (int)LogId
                };
                addActivity.DateTime = na.Date.Add(na.Time.TimeOfDay);
                addActivity.EndTime  = addActivity.DateTime;

                switch (addActivity.DurationType)
                {
                case "Minutes":
                    addActivity.EndTime = addActivity.EndTime.AddMinutes(addActivity.Duration);
                    break;

                case "Hours":
                    addActivity.EndTime = addActivity.EndTime.AddHours(addActivity.Duration);
                    break;

                case "Days":
                    addActivity.EndTime = addActivity.EndTime.AddDays(addActivity.Duration);
                    break;

                default:
                    break;
                }
                _context.activities.Add(addActivity);

                //make a new rsvp for the event creator & add to db
                RSVP creatorRsvp = new RSVP {
                    Attendee = user, Activity = addActivity
                };
                _context.rsvps.Add(creatorRsvp);
                _context.SaveChanges();

                return(Redirect("/dashboard"));
            }
            return(View("NewActivity"));
        }
Esempio n. 3
0
        public IActionResult Register(User user)
        {
            // Check initial ModelState
            if (ModelState.IsValid)
            {
                // If a User exists with provided email
                if (dbContext.Users.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use!");

                    return(View("Index"));
                }
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);

                dbContext.Add(user);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("UserId", user.UserId);
                HttpContext.Session.SetString("UserName", user.FirstName);

                return(RedirectToAction("Home", "AC"));
            }

            else
            {
                return(View("Index"));
            }
        }
Esempio n. 4
0
        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;

                _context.Add(nUser);
                _context.SaveChanges();

                HttpContext.Session.SetInt32("UserId", nUser.UserId);
                return(Redirect("/dashboard"));
            }
            return(View("Index"));
        }
 public IActionResult Create(Plan newPlan)
 {
     if (ModelState.IsValid)
     {
         DateTime planDate = newPlan.Date;
         if ((DateTime.Now - planDate).TotalMinutes > 0)
         {
             ModelState.AddModelError("Date", "The date must be a future date.");
             return(View("New"));
         }
         newPlan.UserId = (int)uid;
         db.Plans.Add(newPlan);
         db.SaveChanges();
         return(RedirectToAction("Details", "Plan", new { planId = newPlan.PlanId }));
     }
     return(View("New"));
 }
        public IActionResult Create(Activity newActivity)
        {
            if (ModelState.IsValid == false)
            {
                return(View("New"));
            }

            if (newActivity.Date < DateTime.Today)
            {
                ModelState.AddModelError("Date", "Date cannot be past");
                return(View("New"));
            }

            newActivity.UserId = (int)uid;
            db.Activities.Add(newActivity);
            db.SaveChanges();
            return(RedirectToAction("Dashboard", "Home"));
        }
        public IActionResult Register(User newUser)
        {
            if (ModelState.IsValid)
            {
                if (db.Users.Any(user => user.Email == newUser.Email))
                {
                    ModelState.AddModelError("Email", "This email is already registered.");

                    return(View("Index"));
                }

                string password = newUser.Password;
                bool IsLetter(char c)
                {
                    return((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
                }

                bool IsDigit(char c)
                {
                    return(c >= '0' && c <= '9');
                }

                bool IsSymbol(char c)
                {
                    return(c > 32 && c < 127 && !IsDigit(c) && !IsLetter(c));
                }

                bool IsValidPassword(string password)
                {
                    return
                        (password.Any(c => IsLetter(c)) &&
                         password.Any(c => IsDigit(c)) &&
                         password.Any(c => IsSymbol(c)));
                }

                if (!IsValidPassword(password))
                {
                    ModelState.AddModelError("Password", "Password must contain at least one letter, one number, and one special character.");

                    return(View("Index"));
                }


                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                newUser.Password = Hasher.HashPassword(newUser, newUser.Password);

                db.Add(newUser);
                db.SaveChanges();

                HttpContext.Session.SetInt32("userId", newUser.UserId);
                return(RedirectToAction("Dashboard", "Plan"));
            }

            return(View("Index"));
        }
        public IActionResult Register(User newUser)
        {
            if (ModelState.IsValid == false)
            {
                return(View("Index"));
            }

            if (ModelState.IsValid)
            {
                if (db.Users.Any(u => u.Email == newUser.Email))
                {
                    ModelState.AddModelError("Email", "Email already Exists");
                    return(View("Index"));
                }
            }

            Regex letters        = new Regex(@"[a-zA-Z]");
            Regex hasNumber      = new Regex(@"[0-9]");
            Regex hasSpecialChar = new Regex(@"[\W]");

            bool isValidated = letters.IsMatch(newUser.Password) && hasNumber.IsMatch(newUser.Password) && hasSpecialChar.IsMatch(newUser.Password);

            if (!isValidated)
            {
                ModelState.AddModelError("Password", "Password must contain at least 1 number, 1 special character and upper and lowercase letters");
                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("UserName", newUser.FirstName);

            return(RedirectToAction("Dashboard"));
        }
Esempio n. 9
0
 public IActionResult Register(User newUser)
 {
     if (ModelState.IsValid)
     {
         var dbUser = context.UserList.FirstOrDefault(u => u.Email == newUser.Email);
         if (dbUser != null)
         {
             ModelState.AddModelError("Email", "This Email is already in use");
             return(View("Index"));
         }
         else
         {
             PasswordHasher <User> PWHasher = new PasswordHasher <User>();
             newUser.Password = PWHasher.HashPassword(newUser, newUser.Password);
             context.UserList.Add(newUser);
             context.SaveChanges();
             HttpContext.Session.SetInt32("UserId", newUser.UserId);
             return(Redirect("home"));
         }
     }
     return(View("Index"));
 }