当前位置: 首页>>代码示例>>C#>>正文


C# UserService.Add方法代码示例

本文整理汇总了C#中UserService.Add方法的典型用法代码示例。如果您正苦于以下问题:C# UserService.Add方法的具体用法?C# UserService.Add怎么用?C# UserService.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserService的用法示例。


在下文中一共展示了UserService.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddUser

        TestResult AddUser()
        {
            using (var unitOfWork = new UnitOfWork(new AuthorizationModuleFactory(true)))
            {
                var RoleService = new RoleService(unitOfWork);
                var UserService = new UserService(unitOfWork);

                var testUser = new User
                {
                    Login = "ivan_test",
                    Password = "ivan_test_pass",
                    //Password = "f5DBIwnAMS",
                    Email = "[email protected]",
                    CreatedDate = DateTime.Now,
                    //FirstName = "Ivan",
                    //MiddleName = "Semenovich",
                    //LastName = "Peresvetov",
                    FirstName = "Иван",
                    MiddleName = "Семенович",
                    LastName = "Пересветов",
                    Roles = new List<Role>(new Role[] { RoleService.Get().First() }),
                };

                UserService.Add(testUser);
                try
                {
                    var result = unitOfWork.Commit();
                    if (result.Count > 0)
                        return new TestResult(TestResultType.Failure, MethodBase.GetCurrentMethod().Name, result.First().ErrorMessage);
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                        ex = ex.InnerException;
                    return new TestResult(TestResultType.Failure, MethodBase.GetCurrentMethod().Name, ex.Message);
                }
            }

            using (var unitOfWork = new UnitOfWork(new AuthorizationModuleFactory(false)))
            {
                var UserService = new UserService(unitOfWork);
                User testUser = UserService.Get(user => user.Login == "ivan_test").FirstOrDefault();
                if(testUser == null)
                    return new TestResult(TestResultType.Failure, MethodBase.GetCurrentMethod().Name, "Can't find added user.");
                else
                    return new TestResult(TestResultType.Success, MethodBase.GetCurrentMethod().Name, "User added successfully.");
            }
        }
开发者ID:vano-lukashuk,项目名称:StudentBank,代码行数:48,代码来源:UserTest.cs

示例2: Register

 public ActionResult Register(RegisterViewModel register)
 {
     InterfaceUserService userService = new UserService();
     if (TempData["VerficationCode"] == null || TempData["VerficationCode"].ToString() != register.VerificationCode.ToUpper())
     {
         ModelState.AddModelError("VerficationCode", "验证码不正确");
         return View(register);
     }
     if (ModelState.IsValid)
     {
         if (userService.Exist(register.UserName)) ModelState.AddModelError("UserName", "用户名已存在");
         else
         {
             User _user = new User()
             {
                 UserName = register.UserName,
                 //默认用户组代码写这里
                 DisplayName = register.DisplayName,
                 Password = Security.Sha256(register.Password),
                 //邮箱验证与邮箱唯一性问题
                 Email = register.Email,
                 //用户状态问题
                 Status = 0,
                 LoginIP = "",
                 LoginTime = DateTime.Now,
                 RegistrationTime = DateTime.Now
             };
             _user = userService.Add(_user);
             if (_user.UserID > 0)
             {
                 var _identity = userService.CreateIdentity(_user, DefaultAuthenticationTypes.ApplicationCookie);
                 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                 AuthenticationManager.SignIn(_identity);
                 return RedirectToAction("Index", "Home");
             }
             else { ModelState.AddModelError("", "注册失败!"); }
         }
     }
     return View(register);
 }
开发者ID:chenxygx,项目名称:CSharpHelper,代码行数:40,代码来源:UserController.cs


注:本文中的UserService.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。