Created
May 22, 2014 13:44
-
-
Save jonathanread/9771fb22d4b876f4e289 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aptera.Sitefinity.Models; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Http; | |
using System.Web.Http.OData; | |
using Telerik.Sitefinity.DynamicModules; | |
using Telerik.Sitefinity.Utilities.TypeConverters; | |
using Telerik.Sitefinity.Model; | |
using Telerik.Sitefinity.GenericContent.Model; | |
using Telerik.Sitefinity.Model.ContentLinks; | |
using Telerik.OpenAccess; | |
using Telerik.Sitefinity.Taxonomies; | |
using Telerik.Sitefinity.Taxonomies.Model; | |
namespace SitefinityWebApp.Custom.API.Controllers | |
{ | |
public class ProjectsController : EntitySetController<Project, string> | |
{ | |
private readonly DynamicModuleManager _dynamicModuleManager = DynamicModuleManager.GetManager(); | |
private Type _portfolioItemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Portfolio.PortfolioItem"); | |
[Queryable(AllowedQueryOptions = System.Web.Http.OData.Query.AllowedQueryOptions.All)] | |
public override IQueryable<Project> Get() | |
{ | |
List<Project> projects = new List<Project>(); | |
foreach(var p in _dynamicModuleManager.GetDataItems(_portfolioItemType).Where(p => p.Status == ContentLifecycleStatus.Live && p.Visible)) | |
{ | |
Project project = new Project(); | |
project.Title = p.GetValue("Title").ToString(); | |
project.Summary = p.GetValue("Summary").ToString(); | |
project.ImageSrc = (p.GetValue<ContentLink[]>("Thumbnail").FirstOrDefault() != null) ? p.GetValue<ContentLink[]>("Thumbnail").FirstOrDefault().ChildItemAdditionalInfo.ToString().Replace(".tmb-",String.Empty) : ""; | |
project.Url = p.UrlName; | |
project.ProjectType = GetPortfolioTypes(p.GetValue<TrackedList<Guid>>("portfoliotypes")); | |
projects.Add(project); | |
} | |
return projects.AsQueryable(); | |
} | |
private String GetPortfolioTypes(TrackedList<Guid> value) | |
{ | |
TaxonomyManager manager = TaxonomyManager.GetManager(); | |
String list = ""; | |
foreach (Guid g in value) | |
{ | |
list += manager.GetTaxa<FlatTaxon>().Where(t => t.Id == g).FirstOrDefault().Title + " "; | |
} | |
return list; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment