Beispiel #1
0
        private async Task ComplementPostWithPotentialUrlTipAndLineupAsync(int postId, Models.Forum.CRUD.Post post, List <Result> results)
        {
            if (!string.IsNullOrEmpty(post.UrlTipHref))
            {
                if (!_dbClient.UrlTipEqualsCurrentUrlTipOnPostId(postId, post.UrlTipHref))
                {
                    if (!(post.UrlTipHref.StartsWith("http://") || post.UrlTipHref.StartsWith("https://")))
                    {
                        post.UrlTipHref = post.UrlTipHref.Insert(0, "http://");
                    }
                    var urlTip = new Database.Entities.Forum.UrlTip
                    {
                        PostId  = postId,
                        Clicks  = 0,
                        Href    = post.UrlTipHref,
                        Created = DateTime.Now
                    };
                    results.Update(await _dbClient.CreateUrlTipAsync(urlTip), ResultMessages.CreateUrlTip);
                }
            }
            else
            {
                if (await _dbClient.PostHasAnUrlTipConnectedToItAsync(postId))
                {
                    await _dbClient.DeleteUrlTipAsync(postId);
                }
            }

            if (post.LineupId > 0)
            {
                var postToLineup = new Database.Entities.Forum.PostToLineup
                {
                    PostId   = postId,
                    LineupId = post.LineupId,
                    Created  = DateTime.Now
                };
                results.Update(await _dbClient.ConnectLineupToPostAsync(postToLineup), ResultMessages.CreateLineupToPost);
            }
            else
            {
                if (await _dbClient.PostHasALineupConnectedToItAsync(postId))
                {
                    await _dbClient.DeleteLineupConnectionToPostAsync(postId);
                }
            }
        }