Inheritance: BaseObject
Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 public Post UpdatePost(Post post)
 {
     using (var svc = new ServiceProxyHelper<IPostsService>("PostsService"))
     {
         return svc.Proxy.UpdatePost(post);
     }
 }
Esempio n. 3
0
 public Post UpdatePost(Post post, string authenticationToken)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        public Post UpdatePost(Post post)
        {
            var result = _postsLogic.UpdatePost(post);
            Cache.ReplaceEntry(result, result.Id);

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

            return result;
        }
Esempio n. 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;
        }
Esempio n. 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;
        }
Esempio n. 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);
            }
        }