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


C# IUserRepository.Edit方法代码示例

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


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

示例1: UserModule

        public UserModule(IUserRepository users, IIdeaRepository ideas, IFeatureRepository features)
        {
            _users = users;
            _ideas = ideas;
            _features = features;

            this.RequiresAuthentication();

            Get["/profile"] = _ =>
                                  {
                                      User user = Context.GetCurrentUser(_users);
                                      if (user == null) return Response.AsRedirect("/");

                                      var i = _ideas.GetAll().Where(u => u.Author.Id == user.Id).ToList();
                                      var f = _features.GetAll().Where(u => u.User.Id == user.Id).ToList();
                                      var v = _users.GetVotes(user.Id).ToList();

                                      return View["Profile/Index",
                                          new
                                          {
                                              Title = "Profile",
                                              Id = user.Id,
                                              UserName = user.UserName,
                                              Email = user.Email,
                                              Github = user.Github,
                                              Ideas = i,
                                              Features = f,
                                              Votes = v,
                                              Claims = user.Claims.ToList(),
                                              IsLoggedIn = Context.IsLoggedIn()
                                          }];
                                  };

            Get["/profile/edit"] = _ =>
                                       {
                                           User user = Context.GetCurrentUser(_users);
                                           if (user == null) return Response.AsRedirect("/");

                                           return View["Profile/Edit", new
                                                                           {
                                                                               Title = "Profile",
                                                                               Id = user.Id,
                                                                               UserName = user.UserName,
                                                                               Email = user.Email,
                                                                               Github = user.Github,
                                                                               Claims = user.Claims.ToList(),
                                                                               IsLoggedIn = Context.IsLoggedIn(),
                                                                           }];
                                       };

            Post["/profile/checkuser"] = _ =>
                                             {
                                                 string username = Request.Form.username;

                                                 var userExists = _users.FindBy(u => u.UserName == username).Any();

                                                 string msg = "";

                                                 if (username == Context.CurrentUser.UserName)
                                                     msg = "";
                                                 else if (string.IsNullOrWhiteSpace(username))
                                                     msg = Strings.UserModule_UsernameNotValid;
                                                 else if (userExists)
                                                     msg = Strings.UserModule_UsernameTaken;
                                                 else msg = Strings.UserModule_UsernameAvailable;

                                                 return Response.AsJson(new
                                                                            {
                                                                                Status = "OK",
                                                                                msg = msg
                                                                            });
                                             };

            Post["/profile/save"] = _ =>
                                        {
                                            var user = Context.GetCurrentUser(_users);
                                            user.UserName = Request.Form.username;
                                            user.Email = Request.Form.email;
                                            user.AvatarUrl = user.Email.ToGravatarUrl(40);
                                            user.Github = Request.Form.github;

                                            _users.Edit(user);

                                            return Response.AsRedirect("/profile");
                                        };
        }
开发者ID:mikoskinen,项目名称:Ideastrike,代码行数:86,代码来源:UserModule.cs


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