コード例 #1
0
        public IActionResult Profile()
        {
            int?Uid = HttpContext.Session.GetInt32("UserId");

            if (Uid != null)
            {
                int  userid = (int)Uid;
                User user   = _context.users
                              .SingleOrDefault(u => u.UserId == userid);
                List <Connection> connections = _context.connections
                                                .Include(c => c.Friend)
                                                .Include(c => c.Self)
                                                .Where(c => c.SelfId == userid || c.FriendId == userid).ToList();
                List <Invitation> invitations = _context.invitations
                                                .Include(i => i.Sender)
                                                .Where(i => i.ReceiverId == userid)
                                                .ToList();
                ModelBundle bundle = new ModelBundle();
                bundle.user        = user;
                bundle.connections = connections;
                bundle.invitations = invitations;
                return(View("Profile", bundle));
            }
            else
            {
                return(View("Index"));
            }
        }
コード例 #2
0
        public IActionResult Login(LoginViewModel model2)
        {
            if (ModelState.IsValid)
            {
                List <User> user = _context.users.Where(u => u.Email == model2.EmailLog).ToList(); // can use SingleDefault instead of Where
                if (user.Count > 0)
                {
                    if (user[0].Password == model2.PasswordLog)
                    {
                        int id = user[0].UserId;
                        HttpContext.Session.SetInt32("id", id);
                        return(RedirectToAction("Index", "Dashboard"));
                    }
                    ViewBag.passwordError = "Password is wrong";
                }
                else
                {
                    ViewBag.emailError = "Email doesn't exist";
                }
            }
            ModelBundle Bundle = new ModelBundle {
                model1 = new RegistrationViewModel(), model2 = model2
            };

            return(View("Index", Bundle));
        }
コード例 #3
0
        public IActionResult Index()
        {
            ModelBundle Bundle = new ModelBundle {
                model1 = new RegistrationViewModel(), model2 = new LoginViewModel()
            };

            return(View("Index", Bundle));
        }
コード例 #4
0
        public IActionResult Register(RegistrationViewModel model1)
        {
            if (ModelState.IsValid)
            {
                User NewUser = new User
                {
                    FirstName = model1.FirstName,
                    LastName  = model1.LastName,
                    Email     = model1.Email,
                    Password  = model1.Password
                };
                _context.users.Add(NewUser);
                _context.SaveChanges();
                User last = _context.users.Last();
                int  id   = last.UserId;
                HttpContext.Session.SetInt32("id", id);
                return(RedirectToAction("Index", "Dashboard"));
            }
            ModelBundle Bundle = new ModelBundle {
                model1 = model1, model2 = new LoginViewModel()
            };

            return(View("Index", Bundle));
        }