当前位置: 首页>>代码示例>>C#>>正文


C# Item.AddCollaborator方法代码示例

本文整理汇总了C#中System.Item.AddCollaborator方法的典型用法代码示例。如果您正苦于以下问题:C# Item.AddCollaborator方法的具体用法?C# Item.AddCollaborator怎么用?C# Item.AddCollaborator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Item的用法示例。


在下文中一共展示了Item.AddCollaborator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddCollaboratorAsync

        /// <summary></summary>
        /// <param name="item"></param>
        /// <param name="collaborator"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task AddCollaboratorAsync(Item item, Collaborator collaborator, CancellationToken cancellationToken)
        {
            if (item == null) throw new ArgumentNullException("item");
            if (collaborator == null) throw new ArgumentNullException("collaborator");
            if (item.Collaborators.Contains(collaborator)) throw new InvalidOperationException("target user is already included in collaborators.");

            const string insert = @"
INSERT INTO [dbo].[Collaborators] (
    [ItemId],
    [UserId],
    [RoleType]
) VALUES (
    @ItemId,
    @UserId,
    @RoleType
)
";
            using (var cn = CreateConnection())
            {
                await cn.OpenAsync(cancellationToken).ConfigureAwait(false);

                await
                    cn.ExecuteAsync(insert, new { ItemId = item.Id, UserId = collaborator.Id, RoleType = collaborator.Role })
                        .ConfigureAwait(false);
            }

            item.AddCollaborator(collaborator);
        }
开发者ID:yuki87,项目名称:Hinata-on-premise,代码行数:33,代码来源:ItemDbCommand.cs

示例2: ToEntity

        public Item ToEntity()
        {
            var item = new Item
            {
                Id = Id,
                Title = Title,
                Body = Body,
                Type = Type,
                IsPublic = IsPublic,
                CreatedDateTime = CreatedDateTime,
                LastModifiedDateTime = LastModifiedDateTime,
                CommentCount = CommentCount,
                RevisionCount = RevisionCount,
                RevisionNo = RevisionNo,
                PublicType = PublicType,
            };

            if (!string.IsNullOrWhiteSpace(Author))
            {
                var xmlAuthor = new XmlDocument();
                xmlAuthor.LoadXml(Author);
                var jsonAuthor = Regex.Replace(JsonConvert.SerializeXmlNode(xmlAuthor), "(?<=\")(@)(?!.*\":\\s )",
                    "",
                    RegexOptions.IgnoreCase);
                var jObjectAuthor = JObject.Parse(jsonAuthor)["Author"];
                var author = JsonConvert.DeserializeObject<User>(jObjectAuthor.ToString());
                item.Author = author;
            }
            else
            {
                item.Author = User.Unknown;
            }

            if (!string.IsNullOrWhiteSpace(Editor))
            {
                var xmlEditor = new XmlDocument();
                xmlEditor.LoadXml(Editor);
                var jsonEditor = Regex.Replace(JsonConvert.SerializeXmlNode(xmlEditor), "(?<=\")(@)(?!.*\":\\s )",
                    "",
                    RegexOptions.IgnoreCase);
                var jObjectEditor = JObject.Parse(jsonEditor)["Editor"];
                var editor = JsonConvert.DeserializeObject<User>(jObjectEditor.ToString());
                item.Editor = editor;
            }
            else
            {
                item.Editor = User.Unknown;
            }

            if (!string.IsNullOrWhiteSpace(Tags))
            {
                var xmlTags = new XmlDocument();
                xmlTags.LoadXml(Tags);
                var jsonTags = Regex.Replace(JsonConvert.SerializeXmlNode(xmlTags), "(?<=\")(@)(?!.*\":\\s )", "",
                    RegexOptions.IgnoreCase);
                var jObjectTags = JObject.Parse(jsonTags)["Tags"]["Tag"];
                if (jObjectTags.Type == JTokenType.Array)
                {
                    var tags = JsonConvert.DeserializeObject<IEnumerable<ItemTag>>(jObjectTags.ToString());
                    foreach (var tag in tags)
                    {
                        item.ItemTags.Add(tag);
                    }
                }
                else
                {
                    var tag = JsonConvert.DeserializeObject<ItemTag>(jObjectTags.ToString());
                    item.ItemTags.Add(tag);
                }
            }

            if (!string.IsNullOrWhiteSpace(Collaborators))
            {

                var xmlCollaborators = new XmlDocument();
                xmlCollaborators.LoadXml(Collaborators);
                var jsonCollaborators = Regex.Replace(JsonConvert.SerializeXmlNode(xmlCollaborators),
                    "(?<=\")(@)(?!.*\":\\s )", "", RegexOptions.IgnoreCase);
                var jObjectCollaborators = JObject.Parse(jsonCollaborators)["Collaborators"]["Collaborator"];
                if (jObjectCollaborators.Type == JTokenType.Array)
                {
                    var collaborators = JsonConvert.DeserializeObject<IEnumerable<Collaborator>>(jObjectCollaborators.ToString());
                    foreach (var collaborator in collaborators)
                    {
                        item.AddCollaborator(collaborator);
                    }
                }
                else
                {
                    var collaborator = JsonConvert.DeserializeObject<Collaborator>(jObjectCollaborators.ToString());
                    item.AddCollaborator(collaborator);
                }
            }

            return item;
        }
开发者ID:yuki87,项目名称:Hinata-on-premise,代码行数:96,代码来源:ItemDataModels.cs

示例3: SaveCollaboratorsAsync

        /// <summary>記事の共同編集者を更新します。</summary>
        /// <param name="item">共同編集者を更新する記事</param>
        /// <param name="collaborators">共同編集者</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>        
        public async Task SaveCollaboratorsAsync(Item item, Collaborator[] collaborators, CancellationToken cancellationToken)
        {
            if (item == null) throw new ArgumentNullException("item");
            if (collaborators == null) throw new ArgumentNullException("collaborators");

            const string delete = @"
DELETE FROM [dbo].[Collaborators]
WHERE [ItemId] = @ItemId
";

            const string insert = @"
INSERT INTO [dbo].[Collaborators] (
    [ItemId],
    [UserId],
    [RoleType]
) VALUES (
    @ItemId,
    @UserId,
    @RoleType
)
";
            using (var cn = CreateConnection())
            {
                await cn.OpenAsync(cancellationToken).ConfigureAwait(false);

                using (var tr = cn.BeginTransaction())
                {
                    try
                    {
                        await cn.ExecuteAsync(delete, new {ItemId = item.Id}, tr).ConfigureAwait(false);

                        foreach (var collaborator in collaborators)
                        {
                            await
                                cn.ExecuteAsync(insert, new { ItemId = item.Id, UserId = collaborator.Id, RoleType = collaborator.Role }, tr)
                                    .ConfigureAwait(false);
                        }

                        tr.Commit();

                        item.ClearAllCollaborators();
                        foreach (var collaborator in collaborators)
                        {
                            item.AddCollaborator(collaborator);
                        }
                    }
                    catch
                    {
                        tr.Rollback();
                        throw;
                    }
                }
            }
        }
开发者ID:yuki87,项目名称:Hinata-on-premise,代码行数:59,代码来源:ItemDbCommand.cs


注:本文中的System.Item.AddCollaborator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。