コード例 #1
0
        public static JSONObject GetValues(string referenceId, string itemId)
        {
            var data = GetImageGalleryData(referenceId);

            var result = new JSONObject();

            var item = data.Items.Where(i => i.Id == itemId).FirstOrDefault();
            bool isRoot = item== null || item.Id == HttpContext.Current.Request.QueryString["itemid"];

            result.AddValue("isRoot", isRoot);

            if (isRoot)
            {
                result.AddValue("canMoveUp", false);
                result.AddValue("canMoveDown", false);
                result.AddValue("headline", "");
                result.AddValue("content", "");
            }
            else
            {
                var index = data.Items.IndexOf(item);
                result.AddValue("canMoveUp", index > 0);
                result.AddValue("canMoveDown", index < data.Items.Count - 1);
                result.AddValue("name", item.Text);
                result.AddValue("headline", item.Headline);
                result.AddValue("content", item.Content);
                if (!string.IsNullOrEmpty(item.ImageId))
                {
                    var media = new global::umbraco.cms.businesslogic.media.Media(Convert.ToInt32(item.ImageId));
                    {
                        result.AddValue("imageId", item.ImageId);
                        result.AddValue("imageName", media.Text);
                        result.AddValue("imageUrl", (string)media.getProperty("umbracoFile").Value);
                    }
                }
            }
            return result;
        }
コード例 #2
0
 public static JSONObject SetItemValue(string referenceId, string itemId, JSONObject value)
 {
     var result = new JSONObject();
     var data = GetImageGalleryData(referenceId);
     var item = data.Items.Where(i => i.Id == itemId).FirstOrDefault();
     foreach (var key in value.Keys)
     {
         switch (key)
         {
             case "name":
                 item.Text = (string) value[key];
                 break;
             case "headline":
                 item.Headline = (string) value[key];
                 break;
             case "content":
                 item.Content = (string) value[key];
                 break;
             case "imageId":
                 item.ImageId = (string) value[key];
                 if (!string.IsNullOrEmpty(item.ImageId))
                 {
                     var media = new global::umbraco.cms.businesslogic.media.Media(Convert.ToInt32(item.ImageId));
                     {
                         result.AddValue("imageId", item.ImageId);
                         result.AddValue("imageName", media.Text);
                         result.AddValue("imageUrl", (string)media.getProperty("umbracoFile").Value);
                     }
                 }
                 break;
         }
     }
     result.AddValue("value", data.ToJSON().ToString());
     return result;
 }