public ActionResult Register(SysUser user)
        {
            var u = sysuserRepository.FindByEmail(user.Email);

            if (u != null)
            {
                ModelState.AddModelError("", user.Email + " already exsits!");
                return(View());
            }

            if (ModelState.IsValid)
            {
                var sysUserRoles = new List <SysUserRole>
                {
                    new SysUserRole {
                        SysRoleId = 2
                    }
                };
                user.SysUserRoles = sysUserRoles;

                sysuserRepository.InsertOrUpdate(user);
                sysuserRepository.Save();

                Session["username"] = user.UserName;
                Session["userId"]   = user.ID;
                Session["user"]     = user;
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View());
            }
        }
예제 #2
0
 public ActionResult Create(SysUser sysuser)
 {
     if (ModelState.IsValid)
     {
         sysuserRepository.InsertOrUpdate(sysuser);
         sysuserRepository.Save();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }