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


C# IUserService.GetById方法代码示例

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


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

示例1: SetUp

        private AutoResetEvent SetUp(string method, IUserService svc = null)
        {
#if DEBUG
            if (Debugger.IsAttached)
            {
                _waitTime = int.MaxValue;
            }
#endif
            Global.Init();
            if (svc == null)
            {
                svc = Substitute.For<IUserService>();
                if (method == nameof(IUserService.GetById))
                {
                    svc.GetById(Arg.Any<Guid>()).Returns(cx => cx.Arg<Guid>());
                }

                if (method == nameof(IUserService.GetByIdAsync))
                {
                    svc.GetByIdAsync(Arg.Any<Guid>()).Returns(cx => Task.FromResult((object)cx.Arg<Guid>()));
                }
            }

            var builder = new ContainerBuilder();
            builder.RegisterModule(new FlatwhiteCoreModule());

            builder
                .RegisterInstance(svc)
                .As<IUserService>()
                .EnableInterceptors();
            
            var container = builder.Build();
            var proxy = container.Resolve<IUserService>();

            _invocation = Substitute.For<_IInvocation>();
            _invocation.Arguments.Returns(new object[] { _id });
            _invocation.Method.Returns(typeof(IUserService).GetMethod(method, BindingFlags.Instance | BindingFlags.Public));
            _invocation.Proxy.Returns(proxy);

            
            var cacheStore = Substitute.For<IAsyncCacheStore>();
            var autoResetEvent = new AutoResetEvent(false);
            cacheStore.When(x => x.SetAsync(CacheInfo.Key, Arg.Is<object>(obj => _id.Equals(((CacheItem)obj).Data)), Arg.Any<DateTimeOffset>()))
                .Do(c => autoResetEvent.Set());

            cacheStore.When(x => x.RemoveAsync(CacheInfo.Key))
                .Do(c => autoResetEvent.Set());


            cacheStore.StoreId.Returns(StoreId);
            Global.CacheStoreProvider.RegisterAsyncStore(cacheStore);

            return autoResetEvent;
        }
开发者ID:vanthoainguyen,项目名称:Flatwhite,代码行数:54,代码来源:PhoenixTests.cs

示例2: MiniPrincipal

        public MiniPrincipal(IUserService userService, IIdentity identity)
        {
            Ensure.That(() => userService).IsNotNull();
            Ensure.That(() => identity).IsNotNull();

            this.userService = userService;
            long? id = userService.GetUserId(identity);

            if (id.HasValue)
            {
                User = userService.GetById(id.Value);
            }
            Identity = new MiniIdentity(User, identity.AuthenticationType);
        }
开发者ID:bevacqua,项目名称:bruttissimo,代码行数:14,代码来源:MiniPrincipal.cs

示例3: UserModule

        public UserModule(IUserService _userService,
            ISiteService _siteService,
            IRoleService _roleService,
            IUserRoleMappingService _userRoleMappingService)
            : base("/user")
        {
            UserValidator uservalidator = new UserValidator();
            Get["/list"] = x =>
            {
                return View["User/List",_userService.GetAllUser()];
            };

            Get["/add"] = x =>
            {
                ViewBag.Errored = false;
                return View["User/Add", new User()];
            };

            Post["/add"] = x =>
            {
                User user = this.Bind<User>();
                ValidationResult results = uservalidator.Validate(user);
                if (!results.IsValid)
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error,"错误信息", results.Errors);
                    ViewBag.Errored = true;
                    return View["User/Add", user];
                }
                if (_userService.CreateUser(user))
                {
                    ViewBag.ErrorMsg = "<strong>OK~</strong>";
                    ViewBag.Errored = true;
                    return View["User/Add", user];
                }

                ViewBag.ErrorMsg = "<strong>出错啦~</strong>";
                ViewBag.Errored = true;
                return View["User/Add", user];
                //return this.Context.GetRedirect("~/user/add?error=true");
                //return View["User/Add"];
            };

            Get["/edit/{id}"] = x =>
            {
                return View["User/Edit", _userService.GetByAutoId((int)x.id)];
            };

            Post["/edit/{id}"] = x =>
            {
                ViewBag.Errored = true;
                var user = this.Bind<User>();
                var model = _userService.GetById(user.ID);
                if (!String.IsNullOrEmpty(user.Password))
                {
                    model.PasswordSalt = PasswordUtil.GenerateSalt();
                    model.Password = PasswordUtil.EncodePassword(user.Password, model.PasswordFormat, model.PasswordSalt);
                    model.passwordConfirm = PasswordUtil.EncodePassword(user.passwordConfirm, model.PasswordFormat, model.PasswordSalt);
                }
                else
                {
                    model.passwordConfirm = model.Password;
                }
                model.PrivateEmail = user.PrivateEmail;
                model.Nickname = user.Nickname;
                model.Gender = user.Gender;
                model.Status = user.Status;
                ValidationResult results = uservalidator.Validate(model);
                if (!results.IsValid)
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", results.Errors);
                    return View["User/Edit", user];
                }
                if (user.ID == Guid.Empty)
                {
                    return Response.AsRedirect("/user/list");
                }
                if (_userService.ModifyUser(model))
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.success, "成功信息", "修改用户信息成功");
                }
                else
                {
                    ViewBag.ErrorMsg = HtmlUtils.GetCharisma_Alert(Charisma_AlertType.error, "错误信息", "未知错误,请联系管理员");
                }
                return View["User/Edit", user];
            };

            Get["/delete/{id}"] = x =>
            {
                var model = _userService.GetByAutoId((int)x.id);
                _userService.DeleteUser(model.ID);
                return Response.AsRedirect("/user/list");
            };

            Get["/editrole"] = x =>
            {
                Guid userId = new Guid(Request.Query.userId);
                dynamic SiteId = null;
                SiteId = !String.IsNullOrEmpty(Request.Query.siteId.ToString()) && Request.Query.siteId != null ? new Guid(Request.Query.siteId) : Guid.Empty;
                var usermodel = _userService.GetById(userId);
//.........这里部分代码省略.........
开发者ID:vvvsrx,项目名称:AUserCenter,代码行数:101,代码来源:UserModule.cs

示例4: ToViewModel

 //TODO: service as field
 public static CommentViewModel ToViewModel(this BllComment source, IUserService userService)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (userService == null)
     {
         throw new ArgumentNullException("userService");
     }
     return new CommentViewModel()
     {
         Id = source.Id,
         ArticleId = source.ArticleId,
         Text = source.Text,
         UserId = source.UserId,
         UserName = userService.GetById(source.UserId).Name,
     };
 }
开发者ID:f-acepalm,项目名称:Blog,代码行数:20,代码来源:CommentMapper.cs


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