本文整理汇总了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;
}
示例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);
}