public IHttpActionResult GetContentByFauxUrlSlug(string fauxUrlSlug) { try { var pcs = _fauxUrlSlugSvc.FindContentByFauxUrlSlug(fauxUrlSlug); var ids = pcs.Select(x => x.Id); var result = new FauxUrlSlugApiMultiResult { Result = ids.ToArray() }; return(JsonProto(result)); } catch (HttpException hexc) { throw RestfulApiError(hexc); } }
public ActionResult DisplayContent(string fauxUrlSlug) { var matchedContents = _fauxUrlSvc.FindContentByFauxUrlSlug(fauxUrlSlug); if (matchedContents.Length == 0) { return(HttpNotFound()); } if (matchedContents.Length > 1) { var warnMultiMatch = string.Join(", ", matchedContents.Select(x => $"{x.Id} | {x.ContentTypeId}").ToArray()); _logger.Warn($"Found multiple proto content that match url slug '{fauxUrlSlug}' ({warnMultiMatch})."); } var firstProtoContent = matchedContents[0]; var contentType = ContentType.DefinedTypes.FirstOrDefault(x => x.Id == firstProtoContent.ContentTypeId); if (contentType == null) { _logger.Error($"Found proto content that match url slug '{fauxUrlSlug}' with id " + $"'{firstProtoContent.Id}' but its content type '{firstProtoContent.ContentTypeId}' " + $"has not been defined in the system."); return(HttpNotFound()); } var rctx = ProtoCmsRuntimeContext.Current; if (!rctx.UserHasPermission(ViewContentPermission.GetIdFor(contentType.Id))) { return(HttpNotFound()); } dynamic contentAsDynamic = contentType.Finder().AsDynamic(firstProtoContent); var isPublished = (bool)contentAsDynamic.PublishStatus.IsPublished; var isTrashed = (bool)contentAsDynamic.TrashStatus.IsTrashed; if (!(isPublished && !isTrashed)) { return(HttpNotFound()); } var mdl = new FauxUrlSlugContentModel(contentType, firstProtoContent, contentAsDynamic); var viewName = $"_ContentTypeViews/{contentType.Id}/_View"; return(View(viewName, mdl)); }