Esempio n. 1
0
        public int SavePermissions(int groupId, int forumId, Permission permission)
        {
            string[] fieldNames = { "GroupID", "ForumID" };
            string[] fieldValues = { groupId.ToString(), forumId.ToString() };
            SharePointListItem listItem = Provider.GetListItemByField(ForumConstants.Lists_ForumAccess, fieldNames, fieldValues);

            int rc = 0;
            if (listItem == null)
            {
                string[] values = {
									  "Title", permission.ToString(),
									  "GroupID", groupId.ToString(),
									  "ForumID", forumId.ToString(),
				};

                listItem = new SharePointListItem(0, values);
                rc = Provider.AddListItem(ForumConstants.Lists_ForumAccess, listItem);
            }
            else
            {
                listItem["Title"] = permission.ToString();
                rc = Provider.UpdateListItem(ForumConstants.Lists_ForumAccess, listItem);
            }

            return rc;
        }
Esempio n. 2
0
        public int SavePermissions(int groupId, int forumId, Permission permission)
        {
            string[]           fieldNames  = { "GroupID", "ForumID" };
            string[]           fieldValues = { groupId.ToString(), forumId.ToString() };
            SharePointListItem listItem    = Provider.GetListItemByField(ForumConstants.Lists_ForumAccess, fieldNames, fieldValues);

            int rc = 0;

            if (listItem == null)
            {
                string[] values =
                {
                    "Title",   permission.ToString(),
                    "GroupID", groupId.ToString(),
                    "ForumID", forumId.ToString(),
                };

                listItem = new SharePointListItem(0, values);
                rc       = Provider.AddListItem(ForumConstants.Lists_ForumAccess, listItem);
            }
            else
            {
                listItem["Title"] = permission.ToString();
                rc = Provider.UpdateListItem(ForumConstants.Lists_ForumAccess, listItem);
            }

            return(rc);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the domain object.
        /// </summary>
        /// <param name="listItem">The list item.</param>
        /// <returns></returns>
        public static Category CreateDomainObject(SharePointListItem listItem)
        {
            Category category = new Category(listItem.Id, listItem["Title"]);

            category.SortOrder = Convert.ToInt32(listItem["SortOrder"]);

            return category;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the domain object.
        /// </summary>
        /// <param name="listItem">The list item.</param>
        /// <returns></returns>
        public static Category CreateDomainObject(SharePointListItem listItem)
        {
            Category category = new Category(listItem.Id, listItem["Title"]);

            category.SortOrder = Convert.ToInt32(listItem["SortOrder"]);

            return(category);
        }
Esempio n. 5
0
        public ForumUser GetLast()
        {
            SharePointListProvider   provider   = new SharePointListProvider(ForumApplication.Instance.SpWeb);
            SharePointListDescriptor descriptor = provider.GetAllListItems(ForumConstants.Lists_Users);
            SharePointListItem       item       = descriptor.SharePointListItems[descriptor.SharePointListItems.Length - 1];

            return(UserMapper.CreateDomainObject(item));
        }
Esempio n. 6
0
        public Group FindById(int id)
        {
            SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
            SharePointListItem     listItem = provider.GetListItembyID(ForumConstants.Lists_Groups, id);
            Group group = new Group();

            group.Id   = listItem.Id;
            group.Name = listItem["Title"];
            return(group);
        }
Esempio n. 7
0
        public Forum GetById(int id)
        {
            SharePointListItem currentItem = Provider.GetListItemByField(ForumConstants.Lists_Forums, "ID", id.ToString());

            if (currentItem == null)
            {
                return(new Forum(id, 1, "Default Forum"));
            }

            return(ForumMapper.CreateDomainObject(currentItem));
        }
Esempio n. 8
0
        public int Save(Group group)
        {
            SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
            string[] values = {
				"Title", group.Name,
			};
            SharePointListItem listItem = new SharePointListItem(group.Id, values);
            if (group.Id == 0)
                return provider.AddListItem(ForumConstants.Lists_Groups, listItem);
            else
                return provider.UpdateListItem(ForumConstants.Lists_Groups, listItem);
        }
Esempio n. 9
0
 public int UpdateListItem(string listName, SharePointListItem updateItem)
 {
     using (Identity.ImpersonateAppPool())
     {
         SPList list = this.GetList(listName);
         list.ParentWeb.AllowUnsafeUpdates = true;
         SPListItem itemById = list.Items.GetItemById(updateItem.Id);
         this.UpdateSPListItem(itemById, updateItem);
         itemById.Update();
         return(itemById.ID);
     }
 }
Esempio n. 10
0
 public int AddListItem(string listName, SharePointListItem newItem)
 {
     using (Identity.ImpersonateAppPool())
     {
         SPList list = this.GetList(listName);
         list.ParentWeb.AllowUnsafeUpdates = true;
         SPListItem spListItem = list.Items.Add();
         this.UpdateSPListItem(spListItem, newItem);
         spListItem.Update();
         return(spListItem.ID);
     }
 }
Esempio n. 11
0
        public Topic GetById(int id)
        {
            SharePointListItem currentItem = Provider.GetListItemByField(ForumConstants.Lists_Topics, "ID", id.ToString());

            // FIXME bit of a hack
            if (currentItem == null)
            {
                return(new Topic(id, 1, "Unknown Topic"));
            }

            return(TopicMapper.CreateDomainObject(currentItem));
        }
Esempio n. 12
0
 public int AddListItem(string listName, SharePointListItem newItem)
 {
     using (Identity.ImpersonateAppPool())
     {
         SPList list = this.GetList(listName);
         list.ParentWeb.AllowUnsafeUpdates = true;
         SPListItem spListItem = list.Items.Add();
         this.UpdateSPListItem(spListItem, newItem);
         spListItem.Update();
         return spListItem.ID;
     }
 }
Esempio n. 13
0
        public ForumUser GetBySharePointId(int id)
        {
            SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
            SharePointListItem     listItem = provider.GetListItemByField(ForumConstants.Lists_Users, "UserID", id.ToString());

            if (null == listItem)
            {
                CreateUserFromSharePointId(id);
                listItem = provider.GetListItemByField(ForumConstants.Lists_Users, "UserID", id.ToString());
            }

            return(UserMapper.CreateDomainObject(listItem));
        }
Esempio n. 14
0
 private static void LoadGroupsForUser(SharePointListItem listItem, ForumUser user)
 {
     string groupIds = listItem["Groups"];
     string delim = ";";
     char[] delimArray = delim.ToCharArray();
     string[] groupArray = groupIds.Split(delimArray);
     foreach (string s in groupArray)
     {
         int groupId = Convert.ToInt32(s);
         Group group = RepositoryRegistry.GroupRepository.FindById(groupId);
         user.Groups.Add(group);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Loads the specified list item.
        /// </summary>
        /// <param name="listItem">The list item.</param>
        /// <returns></returns>
        public static Forum CreateDomainObject(SharePointListItem listItem)
        {
            int   categoryId = Convert.ToInt32(listItem["CategoryID"]);
            Forum forum      = new Forum(listItem.Id, categoryId, listItem["Title"]);

            forum.Description = listItem["Description"];

            // TODO I think this is wrong. The last post should be set when
            // a topic is added, not modified
            forum.LastPost = Convert.ToDateTime(listItem["Modified"]);

            return(forum);
        }
Esempio n. 16
0
        /// <summary>
        /// Loads the specified list item.
        /// </summary>
        /// <param name="listItem">The list item.</param>
        /// <returns></returns>
        public static Forum CreateDomainObject(SharePointListItem listItem)
        {
            int categoryId = Convert.ToInt32(listItem["CategoryID"]);
            Forum forum = new Forum(listItem.Id, categoryId, listItem["Title"]);

            forum.Description = listItem["Description"];

            // TODO I think this is wrong. The last post should be set when
            // a topic is added, not modified
            forum.LastPost = Convert.ToDateTime(listItem["Modified"]);

            return forum;
        }
Esempio n. 17
0
        public static Message CreateDomainObject(SharePointListItem listItem)
        {
            Message message = new Message(Convert.ToInt32(listItem["TopicID"]));

            message.Name = listItem["Title"];
            message.UserId = Convert.ToInt32(listItem["UserID"]);
            message.Author = RepositoryRegistry.ForumUserRepository.GetBySharePointId(message.UserId);
            message.Created = Convert.ToDateTime(listItem["Created"]);
            message.Body = listItem["Body"];
            message.Id = listItem.Id;

            return message;
        }
Esempio n. 18
0
        public static Message CreateDomainObject(SharePointListItem listItem)
        {
            Message message = new Message(Convert.ToInt32(listItem["TopicID"]));

            message.Name    = listItem["Title"];
            message.UserId  = Convert.ToInt32(listItem["UserID"]);
            message.Author  = RepositoryRegistry.ForumUserRepository.GetBySharePointId(message.UserId);
            message.Created = Convert.ToDateTime(listItem["Created"]);
            message.Body    = listItem["Body"];
            message.Id      = listItem.Id;

            return(message);
        }
Esempio n. 19
0
        private static void LoadGroupsForUser(SharePointListItem listItem, ForumUser user)
        {
            string groupIds = listItem["Groups"];
            string delim    = ";";

            char[]   delimArray = delim.ToCharArray();
            string[] groupArray = groupIds.Split(delimArray);
            foreach (string s in groupArray)
            {
                int   groupId = Convert.ToInt32(s);
                Group group   = RepositoryRegistry.GroupRepository.FindById(groupId);
                user.Groups.Add(group);
            }
        }
Esempio n. 20
0
        public void Save(Message message)
        {
            SharePointListItem listItem = MessageMapper.CreateDto(message);

            if (message.Id == 0)
            {
                Provider.AddListItem(ForumConstants.Lists_Posts, listItem);
                //				TopicRepository.IncreasePostCount(message.TopicId);
            }
            else
            {
                Provider.UpdateListItem(ForumConstants.Lists_Posts, listItem);
            }
        }
Esempio n. 21
0
        public static Topic CreateDomainObject(SharePointListItem item)
        {
            Topic topic = new Topic(item.Id, Convert.ToInt32(item["ForumID"]), item["Title"]);

            topic.Views          = Convert.ToInt32(item["Views"]);
            topic.TopicStarterId = Convert.ToInt32(item["TopicStarterID"]);
            topic.Author         = RepositoryRegistry.ForumUserRepository.GetBySharePointId(topic.TopicStarterId);

            // Built in values from SharePoint list
            // TODO might be the wrong value
            topic.LastPost = Convert.ToDateTime(item["Modified"]);

            return(topic);
        }
Esempio n. 22
0
        public static Topic CreateDomainObject(SharePointListItem item)
        {
            Topic topic = new Topic(item.Id, Convert.ToInt32(item["ForumID"]), item["Title"]);

            topic.Views = Convert.ToInt32(item["Views"]);
            topic.TopicStarterId = Convert.ToInt32(item["TopicStarterID"]);
            topic.Author = RepositoryRegistry.ForumUserRepository.GetBySharePointId(topic.TopicStarterId);

            // Built in values from SharePoint list
            // TODO might be the wrong value
            topic.LastPost = Convert.ToDateTime(item["Modified"]);

            return topic;
        }
Esempio n. 23
0
        public static ForumUser CreateDomainObject(SharePointListItem listItem)
        {
            ForumUser user = new ForumUser();

            user.Id = Convert.ToInt32(listItem.Id);
            user.LastVisit = Convert.ToDateTime(listItem["LastVisit"]);
            user.UserId = Convert.ToInt32(listItem["UserID"]);
            user.NumPosts = Convert.ToInt32(listItem["NumPosts"]);
            user.Joined = Convert.ToDateTime(listItem["Created"]);
            user.IsAdmin = Convert.ToBoolean(listItem["IsAdmin"]);

            LoadGroupsForUser(listItem, user);
            LoadSharePointInfoForUser(user);

            return user;
        }
Esempio n. 24
0
        public static ForumUser CreateDomainObject(SharePointListItem listItem)
        {
            ForumUser user = new ForumUser();

            user.Id        = Convert.ToInt32(listItem.Id);
            user.LastVisit = Convert.ToDateTime(listItem["LastVisit"]);
            user.UserId    = Convert.ToInt32(listItem["UserID"]);
            user.NumPosts  = Convert.ToInt32(listItem["NumPosts"]);
            user.Joined    = Convert.ToDateTime(listItem["Created"]);
            user.IsAdmin   = Convert.ToBoolean(listItem["IsAdmin"]);

            LoadGroupsForUser(listItem, user);
            LoadSharePointInfoForUser(user);

            return(user);
        }
Esempio n. 25
0
        /// <summary>
        /// Saves the specified category.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        public int Save(Category category)
        {
            SharePointListItem listItem = CategoryMapper.CreateDto(category);
            int categoryId;

            if (listItem.Id == 0)
            {
                categoryId = Provider.AddListItem(ForumConstants.Lists_Category, listItem);
            }
            else
            {
                categoryId = Provider.UpdateListItem(ForumConstants.Lists_Category, listItem);
            }

            return(categoryId);
        }
Esempio n. 26
0
        public int Save(Forum forum)
        {
            SharePointListItem listItem = ForumMapper.CreateDto(forum);
            int newId = 0;

            if (forum.Id == 0)
            {
                newId = Provider.AddListItem(ForumConstants.Lists_Forums, listItem);
                SetupDefaultPermissions(newId);
            }
            else
            {
                newId = Provider.UpdateListItem(ForumConstants.Lists_Forums, listItem);
            }

            return(newId);
        }
Esempio n. 27
0
        public int Save(Topic topic)
        {
            SharePointListItem listItem = TopicMapper.CreateDto(topic);
            int newTopicId = 0;

            if (topic.Id == 0)
            {
                newTopicId = Provider.AddListItem(ForumConstants.Lists_Topics, listItem);
                RepositoryRegistry.ForumRepository.IncreaseCount(topic.ForumId);
            }
            else
            {
                newTopicId = Provider.UpdateListItem(ForumConstants.Lists_Topics, listItem);
            }

            return(newTopicId);
        }
Esempio n. 28
0
        public int Save(ForumUser user)
        {
            int userId;

            SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
            SharePointListItem     listItem = UserMapper.CreateDto(user);

            if (user.Id == 0)
            {
                userId = provider.AddListItem(ForumConstants.Lists_Users, listItem);
            }
            else
            {
                userId = provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
            }

            return(userId);
        }
Esempio n. 29
0
        public int Save(Group group)
        {
            SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);

            string[] values =
            {
                "Title", group.Name,
            };
            SharePointListItem listItem = new SharePointListItem(group.Id, values);

            if (group.Id == 0)
            {
                return(provider.AddListItem(ForumConstants.Lists_Groups, listItem));
            }
            else
            {
                return(provider.UpdateListItem(ForumConstants.Lists_Groups, listItem));
            }
        }
Esempio n. 30
0
        private SharePointListItem SPListItemtoDescriptor(SPListItem spListItem)
        {
            SharePointListItem item = new SharePointListItem();

            for (int i = 0; i < spListItem.Fields.Count; i++)
            {
                if (!spListItem.Fields[i].Hidden)
                {
                    try
                    {
                        item.Id = spListItem.ID;
                        string internalName = spListItem.Fields[i].InternalName;
                        string fieldValue   = (spListItem[internalName] != null) ? spListItem[spListItem.Fields[i].InternalName].ToString() : "";
                        item.Add(internalName, fieldValue, spListItem.Fields[i].ReadOnlyField);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(item);
        }
Esempio n. 31
0
 private void UpdateSPListItem(SPListItem spListItem, SharePointListItem sharePointListItem)
 {
     foreach (SharePointListField field in sharePointListItem.SharePointListFields)
     {
         try
         {
             SPField field2 = spListItem.Fields.GetField(field.Name);
             if (!field2.ReadOnlyField)
             {
                 if (field2.Type == SPFieldType.DateTime)
                 {
                     spListItem[field.Name] = DateTime.Parse(field.Value);
                 }
                 else
                 {
                     spListItem[field.Name] = field.Value;
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
Esempio n. 32
0
        /// <summary>
        /// Gets a category by its identity.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Category GetById(int id)
        {
            SharePointListItem currentItem = Provider.GetListItembyID(ForumConstants.Lists_Category, id);

            return(CategoryMapper.CreateDomainObject(currentItem));
        }
Esempio n. 33
0
 /// <summary>
 /// Adds the list values.
 /// </summary>
 /// <param name="values">The values.</param>
 protected void AddListValues(string[] values)
 {
     SharePointListItem listItem = new SharePointListItem(0, values);
     SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
     provider.AddListItem(listName, listItem);
 }
Esempio n. 34
0
 private SharePointListItem SPListItemtoDescriptor(SPListItem spListItem)
 {
     SharePointListItem item = new SharePointListItem();
     for (int i = 0; i < spListItem.Fields.Count; i++)
     {
         if (!spListItem.Fields[i].Hidden)
         {
             try
             {
                 item.Id = spListItem.ID;
                 string internalName = spListItem.Fields[i].InternalName;
                 string fieldValue = (spListItem[internalName] != null) ? spListItem[spListItem.Fields[i].InternalName].ToString() : "";
                 item.Add(internalName, fieldValue, spListItem.Fields[i].ReadOnlyField);
             }
             catch (Exception)
             {
             }
         }
     }
     return item;
 }
Esempio n. 35
0
 public int UpdateListItem(string listName, SharePointListItem updateItem)
 {
     using (Identity.ImpersonateAppPool())
     {
         SPList list = this.GetList(listName);
         list.ParentWeb.AllowUnsafeUpdates = true;
         SPListItem itemById = list.Items.GetItemById(updateItem.Id);
         this.UpdateSPListItem(itemById, updateItem);
         itemById.Update();
         return itemById.ID;
     }
 }
Esempio n. 36
0
 private void UpdateSPListItem(SPListItem spListItem, SharePointListItem sharePointListItem)
 {
     foreach (SharePointListField field in sharePointListItem.SharePointListFields)
     {
         try
         {
             SPField field2 = spListItem.Fields.GetField(field.Name);
             if (!field2.ReadOnlyField)
             {
                 if (field2.Type == SPFieldType.DateTime)
                 {
                     spListItem[field.Name] = DateTime.Parse(field.Value);
                 }
                 else
                 {
                     spListItem[field.Name] = field.Value;
                 }
             }
         }
         catch (Exception)
         {
         }
     }
 }
Esempio n. 37
0
        public Message GetById(int id)
        {
            SharePointListItem postItem = Provider.GetListItemByField(ForumConstants.Lists_Posts, "ID", id.ToString());

            return(MessageMapper.CreateDomainObject(postItem));
        }