Esempio n. 1
0
 public ActionResult InstallActivity(GalleryActivity activity, Folder category)
 {
     var jsResult = new JsInstallResult();
     Item item = GalleryProcessor.InstallActivity(this.StorageContext, Storage.NewSuggestionsContext, this.CurrentUser, category, null, activity);
     if (item != null)
     {
         jsResult.FolderID = item.FolderID;
         jsResult.ItemID = item.ID;
     }
     else
     {
         jsResult.StatusCode = HttpStatusCode.NotFound;
     }
     JsonResult result = new JsonResult();
     result.Data = jsResult;
     return result;
 }
Esempio n. 2
0
        public static Item InstallActivity(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, User user, Folder category, Guid? subCategory, GalleryActivity galleryActivity)
        {
            // get activity from context
            var activity = suggestionsContext.GalleryActivities.FirstOrDefault(ga => ga.ID == galleryActivity.ID);
            if (activity == null)
                return null;

            if (category == null)
            {
                var galleryCategory = suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.ID == activity.CategoryID);
                if (galleryCategory == null)
                    return null;
                category = CreateCategory(userContext, user, galleryCategory.Name);
            }

            return InstallActivity(userContext, suggestionsContext, category, subCategory, activity);
        }
Esempio n. 3
0
        // may return either Folder or Item (caller should verify)
        public static object InstallCategory(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, User user, Folder category, Guid? parentID, GalleryCategory newCategory)
        {
            object result = null;
            try
            {
                // find the gallery category in the database (by ID if present, otherwise by name)
                GalleryCategory galleryCategory = newCategory.ID > 0 ?
                    suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.ID == newCategory.ID) :
                    suggestionsContext.GalleryCategories.FirstOrDefault(gc => gc.Name == newCategory.Name);
                if (galleryCategory == null)
                {
                    TraceLog.TraceError("InstallCategory could not find Category ID " + newCategory.ID);
                    return result;
                }

                // if the caller didn't pass in a Category, merge with an existing folder (by name), or create a new folder
                if (category == null)
                {
                    category = CreateCategory(userContext, user, newCategory.Name);
                    parentID = null;
                    result = category;
                }
                else
                {
                    // otherwise, create this (sub)category as a subitem
                    DateTime now = DateTime.Now;
                    var subCategory = new Item()
                    {
                        ID = Guid.NewGuid(),
                        Name = galleryCategory.Name,
                        FolderID = category.ID,
                        ParentID = parentID,
                        UserID = category.UserID,
                        ItemTypeID = SystemItemTypes.Category,
                        IsList = true,
                        Created = now,
                        LastModified = now,
                    };
                    result = subCategory;

                    // make this the last subcategory in the category
                    float sortOrder = (userContext.Items.Any(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                                  i.ItemTypeID == SystemItemTypes.Category && (parentID.HasValue ? i.ParentID == parentID : i.ParentID == null)) ?
                        userContext.Items.Where(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                     i.ItemTypeID == SystemItemTypes.Category && (parentID.HasValue ? i.ParentID == parentID : i.ParentID == null)).
                        Select(i => i.SortOrder).
                        Max() :
                        0f) + 1000f;
                    subCategory.SortOrder = sortOrder;

                    userContext.Items.Add(subCategory);
                    userContext.SaveChanges();
                    parentID = subCategory.ID;
                }

                // process all of the subcategories under this (sub)category in the database
                var subCategories = suggestionsContext.GalleryCategories.Where(gc => gc.ParentID == galleryCategory.ID);
                foreach (var sc in subCategories)
                    InstallCategory(userContext, suggestionsContext, user, category, parentID, sc);

                // process all the Activities under this (sub)category
                var activities = suggestionsContext.GalleryActivities.Where(ga => ga.CategoryID == galleryCategory.ID);
                foreach (var activity in activities)
                    InstallActivity(userContext, suggestionsContext, category, parentID, activity);
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("InstallCategory failed", ex);
                return result;
            }
            return result;
        }
Esempio n. 4
0
        public static Item InstallActivity(UserStorageContext userContext, SuggestionsStorageContext suggestionsContext, Folder category, Guid? subCategory, GalleryActivity galleryActivity)
        {
            Item result = null;
            try
            {
                // deserialize the definition
                var def = JsonSerializer.Deserialize<ActivityDefinition>(galleryActivity.Definition);

                // create the new item corresponding to the activity
                DateTime now = DateTime.Now;
                var activity = new Item()
                {
                    ID = Guid.NewGuid(),
                    Name = def.Name,
                    FolderID = category.ID,
                    ParentID = subCategory,
                    UserID = category.UserID,
                    ItemTypeID = SystemItemTypes.Activity,
                    IsList = true,
                    Status = StatusTypes.Active,
                    Created = now,
                    LastModified = now,
                };
                result = activity;

                // make this the last activity in the (sub)category
                float sortOrder = (userContext.Items.Any(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                              i.ItemTypeID == SystemItemTypes.Activity && (subCategory.HasValue ? i.ParentID == subCategory : i.ParentID == null)) ?
                    userContext.Items.Where(i => i.UserID == category.UserID && i.FolderID == category.ID &&
                                                 i.ItemTypeID == SystemItemTypes.Activity && (subCategory.HasValue ? i.ParentID == subCategory : i.ParentID == null)).
                    Select(i => i.SortOrder).
                    Max() :
                    0f) + 1000f;
                activity.SortOrder = sortOrder;

                // set ActivityID of gallery activity this Item is created from
                activity.GetFieldValue(ExtendedFieldNames.ActivityID, true).Value = galleryActivity.ID.ToString();

                // if provided, set the default cadence of the activity
                if (def.Recurrence != null)
                    activity.GetFieldValue(FieldNames.Repeat, true).Value = def.Recurrence.ToString();

                // if provided, set the status
                if (def.Status != null)
                    activity.Status = def.Status;

                userContext.Items.Add(activity);
                userContext.SaveChanges();

                // install all the steps for the activity
                sortOrder = 1;
                foreach (var step in def.Steps)
                {
                    InstallStep(userContext, category, activity.ID, step, sortOrder);
                    sortOrder += 1;
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("InstallActivity failed", ex);
                return result;
            }
            return result;
        }
Esempio n. 5
0
        private static void InstallStep(UserStorageContext userContext, Folder category, Guid activity, ActivityStep activityStep, float sortOrder)
        {
            try
            {
                DateTime now = DateTime.Now;
                var status = (sortOrder == 1) ? StatusTypes.Active : null;
                var step = new Item()
                {
                    ID = Guid.NewGuid(),
                    Name = activityStep.Name,
                    FolderID = category.ID,
                    UserID = category.UserID,
                    ParentID = activity,
                    ItemTypeID = SystemItemTypes.Step,
                    SortOrder = sortOrder * 1000f,
                    Status = status,
                    Created = now,
                    LastModified = now,
                    FieldValues = new List<FieldValue>()
                };

                // TODO: calculate proper due date for first & last steps (based on recurrence setting)
                if (sortOrder == 1)
                {   // TEMPORARY: set first step due date to today
                    step.GetFieldValue(FieldNames.DueDate, true).Value = now.ToUniversalTime().ToLongDateString();
                }
                step.GetFieldValue(FieldNames.ActionType, true).Value = activityStep.Action;
                userContext.Items.Add(step);
                userContext.SaveChanges();
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("InstallStep failed for step " + activityStep.Name, ex);
            }
        }
Esempio n. 6
0
        private static Folder CreateCategory(UserStorageContext userContext, User user, string name)
        {
            var category = userContext.Folders.FirstOrDefault(f => f.UserID == user.ID && f.Name == name);
            if (category == null)
            {
                category = new Folder()
                {
                    ID = Guid.NewGuid(),
                    Name = name,
                    UserID = user.ID,
                    ItemTypeID = SystemItemTypes.Category,
                };

                // make this the last category in the list
                float sortOrder = (userContext.Folders.Any(i => i.UserID == user.ID && i.ItemTypeID == SystemItemTypes.Category) ?
                    userContext.Folders.Where(i => i.UserID == user.ID && i.ItemTypeID == SystemItemTypes.Category).
                    Select(i => i.SortOrder).
                    Max() :
                    0f) + 1000f;
                category.SortOrder = sortOrder;

                userContext.Folders.Add(category);
                userContext.SaveChanges();
            }
            return category;
        }
Esempio n. 7
0
 /// <summary>
 /// Delete all items in a folder.  While there are any items, we use the ItemResource's recursive
 /// delete static methods to delete each item and any potential children.  This way we ensure that 
 /// the deletes are done in the proper order.
 /// </summary>
 /// <param name="folder"></param>
 /// <returns></returns>
 private bool DeleteItems(Folder folder)
 {
     bool multipleItemsDeleted = false;
     while (StorageContext.Items.Any(i => i.FolderID == folder.ID))
     {
         var item = StorageContext.Items.First(i => i.FolderID == folder.ID);
         // delete all the items with ParentID of this item.ID (recursively, from the bottom up)
         multipleItemsDeleted = ItemResource.DeleteItemChildrenRecursively(StorageContext, item);
         // delete all ItemRef FieldValues with Value of this item.ID
         multipleItemsDeleted |= ItemResource.DeleteItemReferences(CurrentUser, StorageContext, item);
         StorageContext.Items.Remove(item);
         StorageContext.SaveChanges();
     }
     return multipleItemsDeleted;
 }
Esempio n. 8
0
        // Update the requested folder with values from the new folder
        // Currently, the algorithm updates only if the server's current value is equal
        // to the original value passed in.
        // NOTE: the server value for folders currently does not include the Item collection
        // because we did not .Include() it in the EF query.  This works well so that the update
        // loop bypasses the Items collection - we are only updating scalar values.
        private bool Update(Folder requestedFolder, Folder originalFolder, Folder newFolder)
        {
            bool updated = false;
            // TODO: timestamps!
            Type t = requestedFolder.GetType();
            foreach (PropertyInfo pi in t.GetProperties())
            {
                object serverValue = pi.GetValue(requestedFolder, null);
                object origValue = pi.GetValue(originalFolder, null);
                object newValue = pi.GetValue(newFolder, null);

                // if the value has changed, process further
                if (!Object.Equals(origValue, newValue))
                {
                    // if the server has the original value, make the update
                    if (Object.Equals(serverValue, origValue))
                    {
                        pi.SetValue(requestedFolder, newValue, null);
                        updated = true;
                    }
                }
            }

            return updated;
        }
Esempio n. 9
0
 // get or create a List by value in given folder for given user
 public Item GetOrCreateListByValue(User user, Folder folder, string value, string name, Guid? itemTypeID = null)
 {
     if (itemTypeID == null) { itemTypeID = SystemItemTypes.NameValue; }
     try
     {   // get the list with given value in given folder
         if (Items.Any(i => i.UserID == user.ID && i.FolderID == folder.ID &&
             i.FieldValues.Any(fv => fv.FieldName == FieldNames.Value && fv.Value == value)))
         {
             return Items.Single(i => i.UserID == user.ID && i.FolderID == folder.ID &&
                 i.FieldValues.Any(fv => fv.FieldName == FieldNames.Value && fv.Value == value));
         }
         else
         {   // create new list with given value and name in given folder
             DateTime now = DateTime.UtcNow;
             var list = new Item()
             {
                 ID = Guid.NewGuid(),
                 Name = name,
                 FolderID = folder.ID,
                 UserID = user.ID,
                 IsList = true,
                 ItemTypeID = itemTypeID.Value,
                 ParentID = null,
                 Created = now,
                 LastModified = now,
                 FieldValues = new List<FieldValue>()
             };
             list.GetFieldValue(FieldNames.Value, true).Value = value;
             Items.Add(list);
             SaveChanges();
             TraceLog.TraceInfo(string.Format("Created list by value '{0}' in folder '{1}' for user '{2}'", value, folder.Name, user.Name));
             return list;
         }
     }
     catch (Exception ex)
     {
         TraceLog.TraceException(string.Format("Could not find or create list by value '{0}' in folder '{1}' for user '{2}'", value, folder.Name, user.Name), ex);
         return null;
     }
 }
Esempio n. 10
0
 // get or create a List by name in given folder for given user
 public Item GetOrCreateList(User user, Folder folder, string name, Guid? itemTypeID = null)
 {
     return GetOrCreateItem(user, folder, name, itemTypeID, true);
 }
Esempio n. 11
0
 // get or create an Item by name in given folder for given user (include FieldValues if NOT a List)
 public Item GetOrCreateItem(User user, Folder folder, string name, Guid? itemTypeID = null, bool isList = false)
 {
     if (itemTypeID == null) { itemTypeID = SystemItemTypes.NameValue; }
     try
     {   // get the list with given name in given folder
         if (Items.Any(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name))
         {
             if (isList)
                 return Items.Single(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name);
             else
                 return Items.Include("FieldValues").Single(i => i.UserID == user.ID && i.FolderID == folder.ID && i.Name == name);
         }
         else
         {   // create new item with given name in given folder
             DateTime now = DateTime.UtcNow;
             var item = new Item()
             {
                 ID = Guid.NewGuid(),
                 Name = name,
                 FolderID = folder.ID,
                 UserID = user.ID,
                 IsList = isList,
                 ItemTypeID = itemTypeID.Value,
                 ParentID = null,
                 Created = now,
                 LastModified = now
             };
             Items.Add(item);
             SaveChanges();
             TraceLog.TraceInfo(string.Format("Created item named '{0}' in folder '{1}' for user '{2}'", name, folder.Name, user.Name));
             return item;
         }
     }
     catch (Exception ex)
     {
         TraceLog.TraceException(string.Format("Could not find or create item named '{0}' in folder '{1}' for user '{2}'", name, folder.Name, user.Name), ex);
         return null;
     }
 }
Esempio n. 12
0
 // get or create a Folder by name for given user
 public Folder GetOrCreateFolder(User user, string name, Guid itemTypeID)
 {
     try
     {   // get the folder by name for user
         if (Folders.Any(f => f.UserID == user.ID && f.Name == name))
         {
             return Folders.Single(f => f.UserID == user.ID && f.Name == name);
         }
         else
         {   // create the folder with given name and itemTypeID for user
             var folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = Guid.NewGuid(), UserID = user.ID, PermissionID = BuiltSteady.Product.Shared.Entities.Permissions.Full };
             var folder = new Folder()
             {
                 ID = folderUser.FolderID,
                 SortOrder = 0,
                 Name = name,
                 UserID = user.ID,
                 ItemTypeID = itemTypeID,
                 Items = new List<Item>(),
                 FolderUsers = new List<FolderUser>() { folderUser }
             };
             Folders.Add(folder);
             SaveChanges();
             TraceLog.TraceInfo(string.Format("Created folder named '{0}' for user '{1}'", name, user.Name));
             return folder;
         }
     }
     catch (Exception ex)
     {
         TraceLog.TraceException(string.Format("Could not find or create folder named '{0}' for user '{1}'", name, user.Name), ex);
         return null;
     }
 }
Esempio n. 13
0
        public static List<Folder> DefaultFolders(User currentUser)
        {
            List<Folder> folders = new List<Folder>();
            Dictionary<Guid, object> defaultLists = new Dictionary<Guid, object>();
            DateTime now = DateTime.Now;
            Item item;
            Folder folder;
            Guid folderID = Guid.NewGuid();

            #if !CLIENT
            FolderUser folderUser;
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Inbox folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 1000,
                Name = UserEntities.Inbox,
                ItemTypeID = SystemItemTypes.Category,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);
            // make this defaultList for Activities
            defaultLists.Add(SystemItemTypes.Activity, folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Personal folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 2000,
                Name = UserEntities.Personal,
                ItemTypeID = SystemItemTypes.Category,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Auto folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 3000,
                Name = UserEntities.Auto,
                ItemTypeID = SystemItemTypes.Category,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Home folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 4000,
                Name = UserEntities.Home,
                ItemTypeID = SystemItemTypes.Category,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Finance folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 5000,
                Name = UserEntities.Finance,
                ItemTypeID = SystemItemTypes.Category,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create People folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 50000,
                Name = UserEntities.People,
                ItemTypeID = SystemItemTypes.Contact,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);
            // make this defaultList for Contacts
            defaultLists.Add(SystemItemTypes.Contact, folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create Places folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 50001,
                Name = UserEntities.Places,
                ItemTypeID = SystemItemTypes.Location,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);
            // make this defaultList for Locations
            defaultLists.Add(SystemItemTypes.Location, folder);

            #if !CLIENT
            folderID = Guid.NewGuid();
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            // create $WebClient folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 0,
                Name = SystemEntities.WebClient,
                ItemTypeID = SystemItemTypes.NameValue,
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            };
            folders.Add(folder);
            #endif

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create $PhoneClient folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 0,
                Name = SystemEntities.PhoneClient,
                ItemTypeID = SystemItemTypes.NameValue,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            folderID = Guid.NewGuid();
            #if !CLIENT
            folderUser = new FolderUser() { ID = Guid.NewGuid(), FolderID = folderID, UserID = currentUser.ID, PermissionID = Permissions.Full };
            #endif
            // create $Client folder
            folder = new Folder()
            {
                ID = folderID,
                SortOrder = 0,
                Name = SystemEntities.Client,
                ItemTypeID = SystemItemTypes.NameValue,
            #if CLIENT
                Items = new ObservableCollection<Item>(),
            #else
                Items = new List<Item>(),
                UserID = currentUser.ID,
                FolderUsers = new List<FolderUser>() { folderUser }
            #endif
            };
            folders.Add(folder);

            // create DefaultLists list
            var defaultListItemID = Guid.NewGuid();
            item = new Item()
            {
                ID = defaultListItemID,
                SortOrder = 0,
                Name = SystemEntities.DefaultLists,
                FolderID = folder.ID,
                IsList = true,
                ItemTypeID = SystemItemTypes.Reference,
                ParentID = null,
                Created = now,
                LastModified = now,
            #if !CLIENT
                UserID = currentUser.ID,
            #endif
            };
            folder.Items.Add(item);

            // add defaultList References for each ItemType
            int sortOrder = 1;
            foreach (var keyValue in defaultLists)
            {
                item = new Item()
                {
                    ID = Guid.NewGuid(),
                    SortOrder = sortOrder++,
                    Name = SystemItemTypes.Names[keyValue.Key],
                    FolderID = folder.ID,
                    IsList = false,
                    ItemTypeID = SystemItemTypes.Reference,
                    ParentID = defaultListItemID,
                    Created = now,
                    LastModified = now,
            #if CLIENT
                    FieldValues = new ObservableCollection<FieldValue>(),
            #else
                    FieldValues = new List<FieldValue>(),
                    UserID = currentUser.ID,
            #endif
                };

                if (keyValue.Value is Folder)
                {
                    Folder folderToRef = (Folder)keyValue.Value;
            #if CLIENT
                    item.GetFieldValue(FieldNames.EntityRef, true).Value = folderToRef.ID.ToString();
                    item.GetFieldValue(FieldNames.EntityType, true).Value = EntityTypes.Folder;
                    item.GetFieldValue(FieldNames.Value, true).Value = keyValue.Key.ToString();
            #else
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityRef, folderToRef.ID.ToString()));
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityType, EntityTypes.Folder));
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.Value, keyValue.Key.ToString()));
            #endif
                }
                if (keyValue.Value is Item)
                {
                    Item itemToRef = (Item)keyValue.Value;
            #if CLIENT
                    item.GetFieldValue(FieldNames.EntityRef, true).Value = itemToRef.ID.ToString();
                    item.GetFieldValue(FieldNames.EntityType, true).Value = EntityTypes.Item;
                    item.GetFieldValue(FieldNames.Value, true).Value = keyValue.Key.ToString();
            #else
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityRef, itemToRef.ID.ToString()));
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.EntityType, EntityTypes.Item));
                    item.FieldValues.Add(Item.CreateFieldValue(item.ID, FieldNames.Value, keyValue.Key.ToString()));
            #endif
                }

                folder.Items.Add(item);
            }

            return folders;
        }