/// <summary> /// Convert the content data item to dynamic object. /// </summary> /// <returns>An expando object defined in open activity object standard.</returns> public dynamic ToObject() { dynamic activity = new ExpandoObject(); var vals = this.Values; var Url = DNA.Utility.UrlUtility.CreateUrlHelper(); var request = HttpContext.Current.Request; string baseUrl = request.Url.Scheme + "://" + request.Url.Authority; dynamic actor = new ExpandoObject(); #region base properties actor.id = this.Modifier; actor.url = baseUrl + "/profiles/" + this.Modifier; actor.displayName = this.Modifier; activity.id = this.ID; activity.parentId = this.ParentItemID; activity.published = this.Published; activity.updated = this.Modified; activity.version = this.Version; //activity.tags = this.Model.Tags; activity.slug = this.Model.Slug; activity.locale = this.Locale; //activity.categories = !string.IsNullOrEmpty(this.Model.Categories) ? this.Model.Categories.Split(',') : null; activity.tags = !string.IsNullOrEmpty(this.Model.Tags) ? this.Model.Tags.Split(',') : null; activity.pos = this.Pos; activity.reads = this.Reads; activity.actor = actor; activity.annotation = this.Annotation; activity.verb = this.ShareID != Guid.Empty ? "share" : "post"; activity.url = this.UrlComponent; #endregion #region object dynamic _obj = new ExpandoObject(); dynamic owner = new ExpandoObject(); owner.id = this.Owner; owner.url = baseUrl + "/profiles/" + this.Owner; owner.displayName = this.Owner; _obj.actor = owner; var j = 0; var title = ""; foreach (var key in Values.Keys) { if (j == 0) { title = Values[key].ToString(); j++; } ((IDictionary <String, Object>)_obj).Add(key, Values[key]); } #endregion var objUrl = UrlComponent.ToString(); _obj.objectType = this.Parent.BaseType; _obj.objectTypeID = this.ParentID; _obj.id = ShareID != Guid.Empty ? ShareID.ToString() : this.ID.ToString(); ContentList originalList = null; ContentDataItem originalItem = null; if (ShareID != Guid.Empty) { originalItem = Context.Find <ContentDataItem>(this.ShareID); originalList = originalItem.ParentID.Equals(this.ParentID) ? this.Parent.Model : Context.Find <ContentList>(originalItem.ParentID); var originalWeb = originalItem.ParentID.Equals(this.ParentID) ? this.Parent.Web.Model : Context.Find <Web>(originalList.WebID); objUrl = (new Uri(string.Format("{0}/{1}/lists/{2}/items/{3}.html", baseUrl, originalWeb.Name, originalList.Name, originalItem.Slug))).ToString(); } _obj.url = objUrl; #region additional properties activity.links = new { //view = this.UrlComponent, edit = Url.Content(this.Parent.GetEditItemUrl(this)), del = Url.Content("~/api/contents/deleteItem/" + this.ParentID.ToString()) }; activity.title = title; #endregion #region categories if (Categories != null && Categories.Count() > 0) { activity.categories = Categories.Select(c => new { id = c.ID, parentId = c.ParentID, name = c.Name, desc = c.Description }); } //dynamic categories = new ExpandoObject(); #endregion #region comments dynamic replies = new ExpandoObject(); replies.totalItems = ShareID != Guid.Empty ? Context.Count <Comment>(c => c.TargetUri.Equals(objUrl, StringComparison.OrdinalIgnoreCase)) : this.TotalComments; replies.disabled = originalItem != null ? !originalItem.EnableComments : !this.Model.EnableComments; replies.link = Url.Content(string.Format("~/api/comments?url={0}", objUrl)); #endregion #region ratings dynamic ratings = new ExpandoObject(); ratings.totalItems = originalItem != null ? originalItem.TotalVotes : this.TotalVotes; ratings.value = originalItem != null ? originalItem.Ratings : this.Ratings; ratings.disabled = originalList != null ? !originalList.AllowVotes : !this.Parent.AllowVotes; if (originalList != null) { ratings.url = Url.Content(string.Format("~/api/contents/vote/{0}?list={1}", ShareID.ToString(), originalList.Name)); } else { if (this.Parent != null) { ratings.url = Url.Content(string.Format("~/api/contents/vote/{0}?list={1}", this.ID.ToString(), this.Parent.Name)); } } #endregion #region attachments dynamic attachs = new ExpandoObject(); attachs.totalItems = originalItem != null ? originalItem.TotalAttachments : this.TotalAttachments; attachs.disabled = originalList != null ? !originalList.AllowAttachments : !this.Parent.AllowAttachments; if (originalItem != null) { attachs.items = Context.Where <ContentAttachment>(c => c.ItemID.Equals(originalItem.ID)).ToList().Select(attach => new { type = attach.ContentType, url = attach.Uri, name = attach.Name, id = attach.ID, size = attach.Size }).ToArray(); } else { if (this.Parent != null && this.Attachments != null) { if (this.Parent.AllowAttachments) { attachs.items = Attachments.Select(attach => new { type = attach.ContentType, url = attach.Uri, name = attach.Name, id = attach.ID, size = attach.Size }).ToList().ToArray(); } else { attachs.items = new object[0]; } } } _obj.attachments = attachs; #endregion dynamic reshares = new ExpandoObject(); reshares.totalItems = 0; reshares.link = Url.Content("~/api/contents/shares/" + (ShareID != Guid.Empty ? this.ShareID.ToString() : this.ID.ToString())); reshares.disabled = !this.Parent.AllowResharing; if (ShareID != Guid.Empty) { reshares.totalItems = Context.Count <ContentDataItem>(i => i.ShareID == this.ShareID); } else if (this.Parent != null && this.Parent.AllowResharing) { reshares.totalItems = Reshares().Count(); } _obj.reshares = reshares; _obj.replies = replies; _obj.ratings = ratings; activity.@object = _obj; return(activity); }
public ShareInstance(ShareID id) { this.id = id; }