本文整理汇总了C#中UserRepository.GetByUsernameWithAlbums方法的典型用法代码示例。如果您正苦于以下问题:C# UserRepository.GetByUsernameWithAlbums方法的具体用法?C# UserRepository.GetByUsernameWithAlbums怎么用?C# UserRepository.GetByUsernameWithAlbums使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRepository
的用法示例。
在下文中一共展示了UserRepository.GetByUsernameWithAlbums方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Describe
public ActionResult Describe(string userName)
{
UserModel authUser = (User.Identity.IsAuthenticated ?
new UserRepository().GetByUsername( User.Identity.Name ) : null);
userName = HttpUtility.UrlDecode( userName ).Trim();
if ( userName == string.Empty )
throw new Exception( "empty username" );
UserRepository users = new UserRepository();
UserModel user = users.GetByUsernameWithAlbums( userName, withTrustedUsers:true );
if ( user == null )
throw new Exception( "user not found" );
AlbumRepository albumRepository = new AlbumRepository();
List<string> albums = new List<string>();
foreach ( AlbumModel album in user.Albums )
{
if ( albumRepository.IsUserAuthorizedToViewAlbum( album, authUser, false ) )
{
albums.Add( string.Format( "{0}/api/albums/{1}", Helpers.BaseURL(), album.Id ) );
}
}
return Json( new
{
ok = true,
data = new
{
id = user.Id,
username = user.Login,
date_of_birth = (user.DateOfBirth.HasValue ? new
{
day = user.DateOfBirth.Value.Day,
month = user.DateOfBirth.Value.Month,
year = user.DateOfBirth.Value.Year
} : null),
about = user.About,
albums = albums
}
}, JsonRequestBehavior.AllowGet );
}
示例2: Manage
public ActionResult Manage()
{
UserRepository users = new UserRepository();
UserModel user = users.GetByUsernameWithAlbums(HttpContext.User.Identity.Name, false, false, true, true);
ViewBag.Action = new string[] { "Album", "ManageAlbum" };
return View(Helpers.Convert(user.Albums.ToList()));
}