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 ); }
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())); }