Ejemplo n.º 1
0
 public IActionResult Create(WedFormViewModel model)
 {
     if (HttpContext.Session.GetInt32("current_userid") == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     if (ModelState.IsValid)
     {
         if (model.date <= DateTime.Now)
         {
             TempData["date_error"] = "Date must be in the future";
             return(View("NewWedding"));
         }
         var     userId     = HttpContext.Session.GetInt32("current_userid");
         Wedding newWedding = new Wedding {
             wedder_one = model.wedder_one,
             wedder_two = model.wedder_two,
             date       = model.date,
             address    = model.address,
             userid     = (int)userId
         };
         _context.weddings.Add(newWedding);
         _context.SaveChanges();
         return(RedirectToAction("Show", new{ id = newWedding.weddingid }));
     }
     return(View("NewWedding"));
 }
Ejemplo n.º 2
0
        public int Add(PresentList presentList)
        {
            var newPresentList = weddingContext.PresentLists.Add(presentList);

            weddingContext.SaveChanges();
            return(newPresentList.PresentListID);
        }
Ejemplo n.º 3
0
        public IActionResult register(IndexViewModel user)
        {
            User regUser = user.NewRegUser;

            // Check initial ModelState
            if (ModelState.IsValid)
            {
                // If a User exists with provided email
                if (dbContext.Users.Any(u => u.Email == regUser.Email))
                {
                    ModelState.AddModelError("NewRegUser.Email", "Email already registered!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    regUser.Password = Hasher.HashPassword(regUser, regUser.Password);
                    // Add the user to database here
                    dbContext.Add(regUser);
                    dbContext.SaveChanges();
                    HttpContext.Session.SetString("UserEmail", regUser.Email);

                    return(RedirectToAction("Dashboard"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 4
0
 public IActionResult PostWedding(PostWedding wed)
 {
     if (ActiveUser == null)
     {
         return(RedirectToAction("Login", "Home"));
     }
     if (ModelState.IsValid)
     {
         if (wed.event_date < DateTime.Now)
         {
             ModelState.AddModelError("event_date", "I am sorry you cannot add something that was in the past");
             return(RedirectToAction("Dashboard", "Wedding"));
         }
         Wedding wedding = new Wedding
         {
             user_id    = ActiveUser.user_id,
             wedding_id = wed.wedding_id,
             wedder_one = wed.wedder_one,
             wedder_two = wed.wedder_two,
             address    = wed.address,
             event_date = wed.event_date
         };
         _wContext.weddings.Add(wedding);
         _wContext.SaveChanges();
         return(RedirectToAction("Dashboard", "Wedding"));
     }
     return(View("AddWedding"));
 }
Ejemplo n.º 5
0
        public IActionResult Register(User user, string PasswordConfirm)
        {
            if (user.Password != PasswordConfirm)
            {
                ViewBag.PasswordError = "Passwords don't match";
                return(View("Index"));
            }
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);
                User ExistingEmail = _context.users.SingleOrDefault(u => u.Email == user.Email);

                if (ExistingEmail != null)
                {
                    ViewBag.RegError = "Email already registered";
                    return(View("Index"));
                }
                else
                {
                    _context.Add(user);
                    _context.SaveChanges();

                    int?UserId = user.UserId;
                    HttpContext.Session.SetInt32("UserId", (int)UserId);
                    return(RedirectToAction("Dashboard"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 6
0
        public IActionResult Register(RegisterViewModel model)
        {
            User CheckUser = _context.Users.SingleOrDefault(user => user.Email == model.Email);

            if (CheckUser != null)
            {
                ViewBag.UserExists = "Email is already registered";
            }
            else
            {
                if (ModelState.IsValid)
                {
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    User NewUser = new User();
                    NewUser.FirstName = model.FirstName;
                    NewUser.LastName  = model.LastName;
                    NewUser.Email     = model.Email;
                    NewUser.Password  = Hasher.HashPassword(NewUser, model.Password);
                    _context.Users.Add(NewUser);
                    _context.SaveChanges();
                    User loggedUser = _context.Users.SingleOrDefault(user => user.Email == model.Email);
                    HttpContext.Session.SetInt32("UserId", loggedUser.UserId);
                    return(RedirectToAction("Index"));
                }
            }
            return(View("Index"));
        }
Ejemplo n.º 7
0
 public IActionResult NewWeeding(NewWedding newweeding)
 {
     // Console.WriteLine("into newWedding controller");
     if (!ModelState.IsValid)
     {
         return(View("NewWedding"));
     }
     else
     {
         DateTime now = DateTime.Today;
         if (DateTime.Compare(newweeding.DateofWeeding, now) < 0)
         {
             ModelState.AddModelError("DateofWeeding", "The Wedding Date must be in the future!");
             return(View("NewWedding"));
         }
         else
         {
             newweeding.UserId = Loginuser.GetUserID(HttpContext);
             Wedding addWeeding = newweeding.GetNewWedding();
             dbContext.Weddings.Add(addWeeding);
             dbContext.SaveChanges();
             return(Redirect("ViewWedding/" + addWeeding.WeddingId));
         }
     }
 }
 public IActionResult Add(Wedding Wed)
 {
     if (Wed.date < DateTime.Now.Date)
     {
         TempData["message"] = "Date cant be in the past";
         System.Console.WriteLine("Date cant be in the past");
         System.Console.WriteLine("Date cant be in the past");
         System.Console.WriteLine("Date cant be in the past");
         System.Console.WriteLine("Date cant be in the past");
         System.Console.WriteLine("Date cant be in the past");
         return(RedirectToAction("AddPage"));
     }
     if (ModelState.IsValid)
     {
         Wed.created_at = DateTime.Now;
         Wed.updated_at = DateTime.Now;
         Wed.userId     = (int)HttpContext.Session.GetInt32("UserId");
         _context.Add(Wed);
         _context.SaveChanges();
         TempData["message"] = "Sucessfully added a new wedding";
     }
     else
     {
         TempData["message"] = "Unsucessful in adding a new wedding";
     }
     return(RedirectToAction("Wedding"));
 }
Ejemplo n.º 9
0
        public IActionResult Create(string wedderone, string weddertwo, string address, DateTime date)
        {
            Wedding wedding = new Wedding()
            {
                name    = $"{wedderone} + {weddertwo}",
                address = address,
                date    = date
            };

            _context.Add(wedding);
            _context.SaveChanges();
            List <User> users = _context.Users.ToList();
            Wedding     added = _context.Weddings.Where(id => id.name == wedding.name).SingleOrDefault();

            foreach (User user in users)
            {
                Schedule schedule = new Schedule()
                {
                    userid    = user.id,
                    weddingid = added.id,
                    status    = "Not attending"
                };
                _context.Add(schedule);
            }
            _context.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }
Ejemplo n.º 10
0
 public IActionResult Register(UserViewModel UserInput)
 {
     if (ModelState.IsValid)
     {
         List <User> CheckEmail = _context.users.Where(user => user.Email == UserInput.Email).ToList();
         if (CheckEmail.Count == 0)
         {
             PasswordHasher <UserViewModel> Hasher = new PasswordHasher <UserViewModel>();
             UserInput.Password = Hasher.HashPassword(UserInput, UserInput.Password);
             User NewUser = new User
             {
                 FirstName = UserInput.FirstName,
                 LastName  = UserInput.LastName,
                 Email     = UserInput.Email,
                 Password  = UserInput.Password
             };
             _context.Add(NewUser);
             _context.SaveChanges();
             User SaveUser = _context.users.SingleOrDefault(user => user.Email == NewUser.Email);
             HttpContext.Session.SetInt32("CurId", NewUser.UserId);
             HttpContext.Session.SetString("CurUser", NewUser.FirstName);
             HttpContext.Session.SetString("CurEmail", NewUser.Email);
             return(RedirectToAction("Dashboard"));
         }
         ViewBag.error = "Email already exisits in database";
         return(View("LoginPage"));
     }
     return(View("LoginPage", UserInput));
 }
Ejemplo n.º 11
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetInt32("user_id") == null)
            {
                return(RedirectToAction("Index", "Home"));
            }


            var model = _context.weddings.Include(s => s.rsvpGuests)
                        .ThenInclude(a => a.rsvpGuest).ToList();

            Wedding deleteWedding = _context.weddings.Include(d => d.rsvpGuests)
                                    .ThenInclude(e => e.rsvpGuest)
                                    .SingleOrDefault(c => c.wed_date <= DateTime.Today);

            if (deleteWedding != null)
            {
                _context.weddings.Remove(deleteWedding);
                _context.SaveChanges();
            }

            ViewBag.id = HttpContext.Session.GetInt32("user_id");

            return(View(model));
        }
Ejemplo n.º 12
0
 public IActionResult RegisterUser(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("Dashboard"));
         }
     }
     else
     {
         return(View("Index"));
     }
 }
        public IActionResult Register(Users user)
        {
            // Check initial ModelState
            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"));
                    // You may consider returning to the View at this point
                }

                // Initializing a PasswordHasher object, providing our User class as its
                PasswordHasher <Users> Hasher = new PasswordHasher <Users>();
                user.Password = Hasher.HashPassword(user, user.Password);
                //Save your user object to the database
                dbContext.Add(user);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("id", user.UserId);
                Console.WriteLine(HttpContext.Session.GetInt32("id"));
                return(RedirectToAction("Success"));
            }
            // other code
            return(View("Index"));
        }
Ejemplo n.º 14
0
 public IActionResult AddWedding(Wedding model)
 {
     model.CreatorId = (int?)HttpContext.Session.GetInt32("UserId");
     _context.weddings.Add(model);
     _context.SaveChanges();
     return(RedirectToAction("Details", new { WeddingId = model.WeddingId }));
 }
Ejemplo n.º 15
0
        public IActionResult register(RegisterUser userFromForm)
        {
            System.Console.WriteLine("Reached Register route!!!!!!!!! *****************************");
            // Check initial ModelState
            if (ModelState.IsValid)
            {
                System.Console.WriteLine("Model state is valid");
                if (dbContext.Logged_In_User.Any(u => u.Email == userFromForm.Email))
                {
                    System.Console.WriteLine("Email is not unique");
                    ModelState.AddModelError("Email", "Email already in use!");
                    return(View("Index"));
                }
                else
                {
                    System.Console.WriteLine("Everything is valid!");
                    PasswordHasher <RegisterUser> Hasher = new PasswordHasher <RegisterUser>();
                    userFromForm.Password = Hasher.HashPassword(userFromForm, userFromForm.Password);
                    System.Console.WriteLine("Password hashed!***************************");
                    dbContext.Logged_In_User.Add(userFromForm);
                    System.Console.WriteLine("New User Added!**************************");
                    dbContext.SaveChanges();
                    System.Console.WriteLine("New User Saved!**************************");

                    HttpContext.Session.SetInt32("LoggedID", userFromForm.UserId);
                    return(RedirectToAction("dashboard"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 16
0
 public IActionResult SaveWedding(WeddingViewModel newWedding)
 {
     if (ModelState.IsValid)
     {
         WeddingCreator NewWedding = new WeddingCreator
         {
             WeddingOne     = newWedding.WeddingOne,
             WeddingTwo     = newWedding.WeddingTwo,
             Date           = newWedding.Date,
             WeddingAddress = newWedding.WeddingAddress,
             Created_at     = DateTime.Now,
             Updated_at     = DateTime.Now,
             UserId         = (int)HttpContext.Session.GetInt32("UserId")
         };
         List <Guest> Guests = _context.Guests
                               .Include(user => user.User)
                               .Include(wedding => wedding.Wedding)
                               .ToList();
         _context.Weddings.Add(NewWedding);
         ViewBag.allweddings = new List <string>();
         _context.SaveChanges();
         return(RedirectToAction("AllWeddings"));
     }
     else
     {
         ViewBag.Errors = ModelState.Values;
         return(View("CreateWedding"));
     }
 }
Ejemplo n.º 17
0
        public IActionResult RegisterProcess(User user)
        {
            if (ModelState.IsValid)
            {
                var dbuser = dbContext.UserTable.FirstOrDefault(u => u.Email == user.Email);
                if (dbContext.UserTable.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use!");
                    return(View("RegisterView"));
                }
                // password hasher
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);
                // saving in db

                dbContext.Add(user);
                dbContext.SaveChanges();
                // setting stuff in session
                HttpContext.Session.SetInt32("UserID", user.UserId);
                //
                HttpContext.Session.SetString("Firstname", user.FirstName);
                HttpContext.Session.SetString("Lastname", user.LastName);

                return(RedirectToAction("Dashboard"));
            }
            return(View("RegisterView"));
        }
Ejemplo n.º 18
0
        public IActionResult Create(Wedding wedding)
        {
            int?UserID = HttpContext.Session.GetInt32("LogedUserID");

            if (UserID != null)
            {
                Person dbUser = _context.Users.SingleOrDefault(u => u.UserID == UserID);

                if (ModelState.IsValid)
                {
                    wedding.User = dbUser;
                    dbUser.Wedding.Add(wedding);
                    _context.Add(wedding);
                    _context.SaveChanges();
                    return(RedirectToAction("Weddings", "Home"));
                }
                else
                {
                    return(View("AddNewWedding"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 19
0
 public IActionResult AddWeddingProcess(Wedding NewWedding)
 {
     if (HttpContext.Session.GetInt32("CurrentUser") == null)
     {
         return(RedirectToAction("index", "Home"));
     }
     dbContext.weddings.Add(NewWedding);
     dbContext.SaveChanges();
     ViewBag.CurrentUser = HttpContext.Session.GetInt32("CurrentUser");
     return(Redirect($"ShowWeddingDetail/{NewWedding.WeddingId}"));
 }
Ejemplo n.º 20
0
 public IActionResult CreateWedding(Wedding newWedding)
 {
     newWedding.UserId = (int)HttpContext.Session.GetInt32("curUser");
     if (ModelState.IsValid)
     {
         dbContext.Add(newWedding);
         dbContext.SaveChanges();
         return(RedirectToAction("Dashboard"));
     }
     return(View("Plan"));
 }
Ejemplo n.º 21
0
        private void AddRSVP(int weddingId)
        {
            Response newResponse = new Response()
            {
                WeddingId = weddingId,
                UserId    = loggedInUser.UserId
            };

            dbContext.Responses.Add(newResponse);
            dbContext.SaveChanges();
        }
Ejemplo n.º 22
0
 public IActionResult Create(Wedding newWedding)
 {
     if (ModelState.IsValid)
     {
         newWedding.UserId = loggedInUser.UserId;
         dbContext.Weddings.Add(newWedding);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = loggedInUser.UserId;
     return(View("New"));
 }
 public IActionResult Add(Wedding NewWedding)
 {
     if (ModelState.IsValid)
     {
         _context.Add(NewWedding);
         int?userid = HttpContext.Session.GetInt32("userid");
         NewWedding.UserId = (int)userid;
         _context.SaveChanges();
         return(Redirect($"/wedding/{NewWedding.WeddingId}"));
     }
     return(View("Plan"));
 }
Ejemplo n.º 24
0
        public IActionResult NewProcess(Wedding wed)
        {
            wed.UserId = (int)HttpContext.Session.GetInt32("id");
            if (ModelState.IsValid)
            {
                dbContext.Add(wed);
                dbContext.SaveChanges();
                return(RedirectToAction("DisplayWed", new{ wedId = wed.WeddingId }));
            }

            return(View("WeddingNew"));
        }
Ejemplo n.º 25
0
        public IActionResult Delete(int WeddingId)
        {
            Wedding deleteTarget = _context.Weddings.SingleOrDefault(
                w => w.UserId == (int)HttpContext.Session.GetInt32("UserId") &&
                w.WeddingId == WeddingId);

            if (deleteTarget != null)
            {
                _context.Weddings.Remove(deleteTarget);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 26
0
 public IActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         User CheckUser = _context.Users.SingleOrDefault(u => u.Email == model.Email);
         Console.WriteLine(CheckUser);
         if (CheckUser != null)
         {
             TempData["EmailInUseError"] = "Email Aleady in use";
             return(RedirectToAction("Index"));
         }
         User newUser = new User
         {
             Username   = model.Username,
             Email      = model.Email,
             Wins       = 0,
             Losses     = 0,
             Created_At = DateTime.Now,
             Updated_At = DateTime.Now
         };
         PasswordHasher <User> hasher = new PasswordHasher <User>();
         newUser.Password = hasher.HashPassword(newUser, model.Password);
         _context.Add(newUser);
         _context.SaveChanges();
         HttpContext.Session.SetInt32("currentUserId", newUser.UserId);
         HttpContext.Session.SetString("currentFirstName", newUser.Username);
         return(RedirectToAction("Dashboard"));
     }
     else
     {
         return(View("Index"));
     }
 }
        public IActionResult Delete(int weddingId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            Wedding weddingForDeletion = dbContext.Weddings.FirstOrDefault(w => w.WeddingId == weddingId);

            dbContext.Weddings.Remove(weddingForDeletion);
            dbContext.SaveChanges();

            return(RedirectToAction("Dashboard"));
        }
        public IActionResult Wedform(Wedding NewWedding)
        {
            System.Console.WriteLine("adding newwedding");

            int?loggedUserId = HttpContext.Session.GetInt32("UserId");


            NewWedding.UserId = (int)loggedUserId;

            _context.Add(NewWedding);
            _context.SaveChanges();

            return(RedirectToAction("show"));
        }
        public IActionResult Register(User model)
        {
            if (ModelState.IsValid)
            {
                User CurrentUser = new User()
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Password    = model.Password,
                    Email       = model.Email,
                    ConPassword = model.ConPassword,
                };
                _context.Add(CurrentUser);
                _context.SaveChanges();
                HttpContext.Session.SetObjectAsJson("cur_user", CurrentUser);
                return(RedirectToAction("Dashboard"));
            }
            else
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                Console.WriteLine(messages);
                HttpContext.Session.SetObjectAsJson("reg_errors", ModelState.Values);
                return(RedirectToAction("Index"));
            }

            //List<Dictionary<string, object>> Allq = _dbConnector.Query("SELECT * FROM quotes ORDER BY created_at Desc");
        }
Ejemplo n.º 30
0
 public IActionResult RSVP(int wedding_id)
 {
     if (_loggedinuser != null)
     {
         Join join = new Join()
         {
             wedding_id = wedding_id,
             joiner_id  = _loggedinuser.user_id
         };
         _wcontext.Add(join);
         _wcontext.SaveChanges();
         return(RedirectToAction("Dashboard", new{ id = _loggedinuser.user_id }));
     }
     return(RedirectToAction("Home", "LogReg"));
 }