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


C# BaseRepository.FirstOrDefault方法代码示例

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


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

示例1: GetAvatarPath

        public static string GetAvatarPath()
        {
            BaseRepository<Person> repository = new BaseRepository<Person>();

            string userName = Membership.GetUserNameByEmail(HttpContext.Current.User.Identity.Name);
            if (!string.IsNullOrWhiteSpace(userName))
            {
                Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey;
                Person person = repository.FirstOrDefault(p => p.UserId == userId);
                return person.AvatarPath;
            }
            return string.Empty;
        }
开发者ID:thesameqad,项目名称:pitchingtube,代码行数:13,代码来源:Util.cs

示例2: OnActionExecuting

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var currentRouteValueDictionary = filterContext.Controller.ControllerContext.RouteData.Values;
            Tube tube = filterContext.HttpContext.Session["currentTube"] as Tube;
            if (tube == null)
            {
                ParticipantRepository participantRepository = new ParticipantRepository();
                string userName = Membership.GetUserNameByEmail(filterContext.HttpContext.User.Identity.Name);
                Guid userId = Guid.Parse(Membership.GetUser(userName).ProviderUserKey.ToString());
                tube = participantRepository.UserIsInTube(userId);
            }
            if (tube != null)
            {

                if (tube.TubeMode == TubeMode.Opened)
                {
                    var newRouteValueDictionary = new RouteValueDictionary
                    {
                        {"controller", "Tube"},
                        {"action", "Index"},
                        {"tubeId", tube.TubeId}
                    };
                    if (currentRouteValueDictionary["controller"].ToString() != newRouteValueDictionary["controller"].ToString() || currentRouteValueDictionary["action"].ToString() != newRouteValueDictionary["action"].ToString())
                        filterContext.Result = new RedirectToRouteResult(newRouteValueDictionary);

                }
                else if (tube.TubeMode == TubeMode.FirstPitch || tube.TubeMode == TubeMode.SecondPitch || tube.TubeMode == TubeMode.ThirdPitch || tube.TubeMode == TubeMode.FourthPitch || tube.TubeMode == TubeMode.FifthPitch)
                {
                    var newRouteValueDictionary = new RouteValueDictionary
                    {
                        {"controller", "Tube"},
                        {"action", "StartPitch"},
                        {"mode", (int)tube.TubeMode}
                    };
                    if (currentRouteValueDictionary["controller"].ToString() != newRouteValueDictionary["controller"].ToString() || currentRouteValueDictionary["action"].ToString() != newRouteValueDictionary["action"].ToString())
                        filterContext.Result = new RedirectToRouteResult(newRouteValueDictionary);

                }
                else if (tube.TubeMode == TubeMode.Nominations)
                {
                    BaseRepository<Nomination> nominationRepository = new BaseRepository<Nomination>();

                    PersonRepository personRepository = new PersonRepository();

                    var user = filterContext.HttpContext.User;

                    Guid userId = (Guid)Membership.GetUser(Membership.GetUserNameByEmail(user.Identity.Name)).ProviderUserKey;

                    var investors = nominationRepository.FirstOrDefault(n => n.InvestorId == userId && n.TubeId == tube.TubeId);

                    var newRouteValueDictionary = new RouteValueDictionary();

                    newRouteValueDictionary.Add("controller", "Tube");

                    string roleName = personRepository.GetRoleName(userId);

                    if(roleName == "Investor" && investors == null)
                        newRouteValueDictionary.Add("action", "Nomination");
                    else
                        newRouteValueDictionary.Add("action", "Results");

                    newRouteValueDictionary.Add("tubeId", tube.TubeId);

                    if (currentRouteValueDictionary["controller"].ToString() != newRouteValueDictionary["controller"].ToString() || currentRouteValueDictionary["action"].ToString() != newRouteValueDictionary["action"].ToString())
                        filterContext.Result = new RedirectToRouteResult(newRouteValueDictionary);
                }

                filterContext.HttpContext.Session["currentTube"] = tube;
            }
            base.OnActionExecuting(filterContext);
        }
开发者ID:thesameqad,项目名称:pitchingtube,代码行数:71,代码来源:Attributes.cs


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