Inheritance: BaseObject
        public IHttpActionResult Put([FromBody]Post post)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var tPost = _postsSvc.GetPost(post.Id);
                var isAllowed = User.Identity.GetUserName() == tPost.User.UserName;

                if (!isAllowed)
                {
                    var notAllowedResult = new Post
                    {
                        Error = new Error
                        {
                            Id = (int)Common.Utils.Constants.Error.RequestNotAllowed,
                            Message = "Request not allowed. You cannot edit someone else's post."
                        }
                    };
                    return Ok(notAllowedResult);
                }

                return Ok(_postsSvc.UpdatePost(post));
            }
            catch (Exception ex)
            {
                _errorSignaler.SignalFromCurrentContext(ex);
                var errorResult = new Post
                {
                    Error = new Error
                    {
                        Id = (int)Common.Utils.Constants.Error.InternalError,
                        Message = ex.Message
                    }
                };
                return Ok(errorResult);
            }
        }
 public Post UpdatePost(Post post)
 {
     using (var svc = new ServiceProxyHelper<IPostsService>("PostsService"))
     {
         return svc.Proxy.UpdatePost(post);
     }
 }
 public Post UpdatePost(Post post, string authenticationToken)
 {
     throw new System.NotImplementedException();
 }
        public IHttpActionResult Post([FromBody]Post post)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                return Ok(_postsSvc.AddPost(post));
            }
            catch (Exception ex)
            {
                _errorSignaler.SignalFromCurrentContext(ex);
                var errorResult = new Post
                {
                    Error = new Error
                    {
                        Id = (int)Common.Utils.Constants.Error.InternalError,
                        Message = ex.Message
                    }
                };
                return Ok(errorResult);
            }
        }
        public Post UpdatePost(Post post)
        {
            var result = _postsLogic.UpdatePost(post);
            Cache.ReplaceEntry(result, result.Id);

            return result;
        }
        public Post AddPost(Post post)
        {
            var result = _postsLogic.AddPost(post);
            Cache.SetEntry(result, result.Id);

            return result;
        }
Exemple #7
0
        public Post PostCleanUp(Post post)
        {
            post.Tags = post.Tags != null ? PrepareTags(post.Tags) : null;
            post.PostContents = post.PostContents != null ? PreparePostContents(post.PostContents, post.Id) : null;
            post.Communities = post.Communities != null ? PrepareCommunities(post.Communities) : new List<Community>();

            return post;
        }
Exemple #8
0
        public Post GetPostProperties(Post post)
        {
            var contents = new List<PostContent>();
            var dbContents = _postContentRepository.Find(b => b.PostId == post.Id, true).ToList();
            dbContents.ForEach(b =>
            {
                b.Media.MediaPath = null;
                b.Media.ThumbnailPath = null;
                contents.Add(PostContentMapper.ToDto(b));
            });
            post.PostContents = contents;

            if (post.User.PictureId != null)
                post.User.Picture = MediaMapper.ToDto(_mediaRepository.Find(b => b.MediaId == (int)post.User.PictureId, false).FirstOrDefault());
            if (post.User.BackgroundId != null)
                post.User.Background = MediaMapper.ToDto(_mediaRepository.Find(b => b.MediaId == (int)post.User.BackgroundId, false).FirstOrDefault());

            return post;
        }
Exemple #9
0
        public Post UpdatePost(Post post)
        {
            try
            {
                if (!ValidatePostContents(post.PostContents))
                    throw new Exception("Cannot upload more than one video.");

                post = PostCleanUp(post);
                
                var tPost = _postRepository.Edit(PostMapper.ToEntity(post));
                return EntityToDtoPostCleanUp(tPost, tPost.PostId);
            }
            catch (Exception ex)
            {
                throw new BlogException(ex.Message, ex.InnerException);
            }
        }