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


C# IUserService.AddUser方法代码示例

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


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

示例1: UserModule

        public UserModule(IUserService userService, IUserRepository userRepository)
            : base("/api/v1/users")
        {
            Before += ctx =>
            {
                return null;
            };

            Get["/", true] = async (_, token) =>
            {
                var users = await userService.GetUsers();
                return users;
            };

            // ?fiter={condition}&limit={limit}&offset={offset}
            Get["/", ctx => ctx.Request.Url.Query != string.Empty, true] = async (_, token) =>
            {
                string filterString = this.Request.Query.filter;
                var filter = JsonConvert.DeserializeObject<dynamic>(filterString);

                int limit = this.Request.Query.limit;
                int offset = this.Request.Query.offset;

                var users = await userRepository.GetAsync(u => true, limit, offset, u => u.Name, true);
                return users;
            };

            Post["/", true] = async (_, token) =>
            {
                //using (var sr = new StreamReader(this.Request.Body))
                //{
                //    var json = sr.ReadToEnd();
                //}
                var user = this.Bind<User>();
                await userService.AddUser(user);
                return HttpStatusCode.Created;
            };

            Put["/{id}", true] = async (_, token) =>
            {
                var user = this.Bind<User>();
                bool success = await userRepository.UpdateAsync(user);
                return success ? HttpStatusCode.OK : HttpStatusCode.BadRequest;
            };

            Delete["/{id}", true] = async (_, token) =>
            {
                string id = _.id;
                bool success = await userRepository.DeleteAsync(_.id);
                return success ? HttpStatusCode.OK : HttpStatusCode.BadRequest;
            };

            Options["/"] = route => new Response();
        }
开发者ID:joeyulivecn,项目名称:NancyDemo,代码行数:54,代码来源:UserModule.cs

示例2: AddUser_adding_an_exist_user_should_return_unsuccess_confirmation

        public void AddUser_adding_an_exist_user_should_return_unsuccess_confirmation()
        {
            // Arrange
            int userId = 5;
            var user = new User { Email = "[email protected]", Password = ""};
            _mockUserRepository.Setup(r => r.GetUserByEmail(user.Email, AccountType.Smoothie)).Returns(user);
            _mockUserRepository.Setup(r => r.Save(user)).Returns(userId);

            _userService = new UserService(_mockUserRepository.Object);

            // Act
            ActionConfirmation<User> confirmation = _userService.AddUser(user, AccountType.Smoothie);

            // Assert
            Assert.False(confirmation.WasSuccessful);
            Assert.IsNull(confirmation.Value);
            Assert.AreEqual(confirmation.Message, "This Email already exists");
        }
开发者ID:john-qin,项目名称:Smoothie,代码行数:18,代码来源:UserServiceTests.cs

示例3: AddUser_adding_a_nonexist_user_should_return_success_confirmation

        public void AddUser_adding_a_nonexist_user_should_return_success_confirmation()
        {
            // Arrange
            int userId = 5;
            var user = new User { Email = "[email protected]", Password = "1234567".Hash() };
            _mockUserRepository.Setup(r => r.GetUserByEmail(user.Email, AccountType.Smoothie)).Returns((User) null);
            _mockUserRepository.Setup(r => r.Save(user)).Returns(userId);

            _userService = new UserService(_mockUserRepository.Object);

            // Act
            ActionConfirmation<User> confirmation = _userService.AddUser(user, AccountType.Smoothie);

            // Assert
            Assert.True(confirmation.WasSuccessful);
            Assert.That(confirmation.Message, Is.EqualTo(""));
            Assert.That(confirmation.Value, Is.EqualTo(user));
            Assert.That(confirmation.Value.Id, Is.EqualTo(userId));
        }
开发者ID:john-qin,项目名称:Smoothie,代码行数:19,代码来源:UserServiceTests.cs

示例4: UsersApiModule

        public UsersApiModule(IUserService userService)
            : base("/api")
        {
            Get["/users"] = parameters =>
                                {
                                    var users = userService.ListUsers(new ListUsersRequest() {RequestUserId = 1}).Users;

                                    return new JsonResponse(users.Select(u => new User() {UserId = u.UserId, Name = u.Name})).
                                        WithNoCache();
                                };

            Post["/users"] = parameters =>
                                 {
                                     var user = this.Bind<UserViewModel>();
                                     var response = userService.AddUser(new AddUserRequest() {Name = user.Name, RequestUserId = 1});

                                     return new JsonResponse(response.UserId);
                                 };
        }
开发者ID:andlju,项目名称:taskmaster,代码行数:19,代码来源:UsersApiModule.cs


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