Esempio n. 1
0
 public Database.Entities.Forum.Post Convert(Models.Forum.CRUD.Post source, Database.Entities.Forum.Post destination, ResolutionContext context)
 {
     return(new Database.Entities.Forum.Post
     {
         Id = source.Id,
         Message = source.Message,
         ParentPostId = source.ParentPostId,
         CreatedByUserId = source.CreatedByUserId,
     });
 }
Esempio n. 2
0
 public Task <List <Result> > CreatePost([FromBody] Models.Forum.CRUD.Post post)
 {
     try
     {
         _logger.Information("Requesting to create a new post {@post}", post);
         return(_postRepository.CreatePostAsync(post));
     }
     catch (Exception ex)
     {
         _logger.Warning(ex, "An unexpected error occured when trying to create a post");
         throw;
     }
 }
Esempio n. 3
0
        public async Task <List <Result> > UpdatePostAsync(Models.Forum.CRUD.Post post)
        {
            var updatePost = _mapper.Map <Database.Entities.Forum.Post>(post);

            updatePost.Updated = DateTime.Now;

            var isUpdated = _dbClient.UpdatePostAsync(updatePost);
            var results   = await new List <Result>().Get(isUpdated, ResultMessages.UpdatePost);

            if (await isUpdated)
            {
                await ComplementPostWithPotentialUrlTipAndLineupAsync(updatePost.Id, post, results);
            }

            return(results);
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
 public Task <List <Result> > UpdatePost([FromBody] Models.Forum.CRUD.Post post)
 {
     _logger.Debug("Requesting to update an existing post");
     return(_postRepository.UpdatePostAsync(post));
 }