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


C# IUserRepository.FindBy方法代码示例

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


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

示例1: GetCurrentUser

        public static User GetCurrentUser(this NancyContext context, IUserRepository _users)
        {
            if (context == null || context.CurrentUser == null || string.IsNullOrWhiteSpace(context.CurrentUser.UserName))
                return null;

            return _users.FindBy(u => u.UserName == context.CurrentUser.UserName).FirstOrDefault();
        }
开发者ID:janode,项目名称:Ideastrike,代码行数:7,代码来源:ModuleExtensions.cs

示例2: IdeaSecuredModule

        public IdeaSecuredModule(IIdeaRepository ideas, IUserRepository users, ISettingsRepository settings, IImageRepository imageRepository)
            : base("/idea")
        {
            _ideas = ideas;
            _settings = settings;
            _imageRepository = imageRepository;
            _users = users;

            this.RequiresAuthentication();

            Get["/new"] = _ =>
            {
                var m = Context.Model(string.Format("New Idea - {0}", _settings.Title));
                m.Ideas = _ideas.GetAll();
                m.Errors = false;

                if (Request.Query["validation"] == "failed")
                {
                    m.Errors = true;
                }

                return View["Idea/New", m];
            };

            Get["/{id}/edit"] = parameters =>
            {
                int id = parameters.id;
                var idea = _ideas.Get(id);

                if (idea == null)
                    return View["404"];

                if (idea.Author.UserName != Context.CurrentUser.UserName)
                    return View["404"];

                var m = Context.Model(string.Format(Strings.IdeaSecuredModule_EditIdea, idea.Title, _settings.Title));
                m.PopularIdeas = _ideas.GetAll();
                m.Idea = idea;
                m.StatusChoices = _settings.IdeaStatusChoices.Split(',');
                m.Errors = false;

                if (Request.Query["validation"] == "failed")
                {
                    m.Errors = true;
                }

                return View["Idea/Edit", m];
            };

            // save result of edit to database
            Post["/{id}/edit"] = parameters =>
            {
                int id = parameters.id;

                if (string.IsNullOrEmpty(Request.Form.Title) || string.IsNullOrEmpty(Request.Form.Description))
                {
                    return Response.AsRedirect(string.Format("/idea/{0}/edit?validation=failed", id));
                }

                var idea = _ideas.Get(id);
                if (idea == null)
                    return View["404"];

                idea.Title = Request.Form.Title;
                idea.Description = Request.Form.Description;
                idea.Status = Request.Form.Status;

                //Add any images
                IEnumerable<string> keys = Context.Request.Form;
                var x = keys.Where(c => c.StartsWith("imageId"));
                var ids = x.Select(c => Context.Request.Form[c].ToString()).Cast<string>();
                var images = ids.Select(y => _imageRepository.Get(Convert.ToInt32(y)));
                foreach (var i in images)
                {
                    if (!idea.Images.Contains(i, i))
                    {
                        idea.Images.Add(i);
                    }
                }

                _ideas.Save();

                return Response.AsRedirect(string.Format("/idea/{0}", idea.Id));
            };

            // save result of create to database
            Post["/new"] = _ =>
            {
                if (string.IsNullOrEmpty(Request.Form.Title) || string.IsNullOrEmpty(Request.Form.Description))
                {
                    return Response.AsRedirect("/idea/new?validation=failed");
                }

                var user = _users.FindBy(u => u.UserName == Context.CurrentUser.UserName).FirstOrDefault();

                if (user == null)
                    return Response.AsRedirect("/login");

                var idea = new Idea
                            {
//.........这里部分代码省略.........
开发者ID:mikoskinen,项目名称:Ideastrike,代码行数:101,代码来源:IdeaModule.Secured.cs

示例3: AdminModule

        public AdminModule(IdeastrikeContext dbContext, Settings settings, IUserRepository users, IIdeaRepository ideas, IActivityRepository activities)
            : base("/admin")
        {
            this.RequiresAuthentication();
            this.RequiresValidatedClaims(c => c.Contains("admin"));

            _settings = settings;
            _users = users;
            _ideas = ideas;
            _activities = activities;

            Get["/"] = _ =>
            {
                var m = Context.Model(string.Format("Admin - {0}", (string)_settings.SiteTitle));
                m.Name = _settings.Name;
                m.WelcomeMessage = _settings.WelcomeMessage;
                m.HomePage = _settings.HomePage;
                m.GAnalyticsKey = _settings.GAnalyticsKey;
                return View["Admin/Index", m];
            };

            Get["/users"] = _ =>
            {
                var m = Context.Model(string.Format("Admin - {0}", (string)_settings.SiteTitle));
                m.Name = _settings.Name;
                m.WelcomeMessage = _settings.WelcomeMessage;
                m.HomePage = _settings.HomePage;
                m.GAnalyticsKey = _settings.GAnalyticsKey;
                m.Users = users.GetAll();
                return View["Admin/Users", m];
            };

            Get["/moderation"] = _ =>
            {
                var m = Context.Model(string.Format("Admin - {0}", (string)_settings.SiteTitle));
                m.Name = _settings.Name;
                m.WelcomeMessage = _settings.WelcomeMessage;
                m.HomePage = _settings.HomePage;
                m.GAnalyticsKey = _settings.GAnalyticsKey;
                return View["Admin/Moderation", m];
            };

            Get["/settings"] = _ =>
            {
                var m = Context.Model(string.Format("Admin - {0}", (string)_settings.SiteTitle));
                m.Name = _settings.Name;
                m.SiteTitle = _settings.SiteTitle;
                m.WelcomeMessage = _settings.WelcomeMessage;
                m.HomePage = _settings.HomePage;
                m.GAnalyticsKey = _settings.GAnalyticsKey;
                m.MaxThumbnailWidth = _settings.MaxThumbnailWidth;

                return View["Admin/Settings", m];
            };

            Post["/settings"] = _ =>
            {
                _settings.WelcomeMessage = Request.Form.welcomemessage;
                _settings.SiteTitle = Request.Form.sitetitle;
                _settings.Name = Request.Form.yourname;
                _settings.HomePage = Request.Form.homepage;
                _settings.GAnalyticsKey = Request.Form.analyticskey;
                _settings.MaxThumbnailWidth = Request.Form.maxthumbnailwidth;

                return Response.AsRedirect("/admin/settings");
            };

            Get["/search"] = _ => "";
            Get["/forums"] = _ => "";
            Get["/forum/{forumId}"] = _ => "";

            Get["/uservoice"] = _ => View["Admin/Uservoice", Context.Model("Admin")];
            Post["/uservoice"] = _ =>
            {
                var client = new WebClient();
                var suggestions = GetSuggestions(client, Request.Form.channel, Request.Form.forumid, Request.Form.apikey, Request.Form.trusted);

                foreach (var s in suggestions)
                {
                    string title = s.title;

                    //If the idea exists, skip it
                    if (ideas.FindBy(i => i.Title == title).Any())
                        continue;

                    string date = s.created_at;
                    var idea = new Idea
                    {
                        Title = title,
                        Description = s.text,
                        Time = DateTime.Parse(date.Substring(0, date.Length - 5)),
                    };

                    string status = string.Empty;
                    switch ((string)s.state)
                    {
                        case "approved":
                            status = "Active";
                            break;
                        case "closed" :
//.........这里部分代码省略.........
开发者ID:Code52,项目名称:Ideastrike,代码行数:101,代码来源:AdminModule.cs

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