コード例 #1
0
        public bool Update(string id, UpdatePostIn postIn)
        {
            Post read = null;

            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    return(false);
                }

                if (postIn == null)
                {
                    return(false);
                }

                if (id == postIn.Id)
                {
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(postIn.Title))
                {
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(postIn.Text))
                {
                    return(false);
                }

                if (_postRepo.Read(id, out read) == false)
                {
                    return(false);
                }

                if (read.IsAnonymous)
                {
                    if (postIn.Password != read.Password)
                    {
                        return(false);
                    }
                }
                else
                {
                    // 본인 확인 - session?
                }
            }

            read.Title = postIn.Title;
            read.Text  = postIn.Text;
            read.Tags  = postIn.Tags;

            if (_postRepo.Update(id, read) == false)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public bool Update(string postId, UpdatePostIn postIn, out Post updatedPost, out Content updatedContent)
        {
            updatedPost    = null;
            updatedContent = null;

            if (string.IsNullOrWhiteSpace(postId))
            {
                return(false);
            }

            if (postIn == null)
            {
                return(false);
            }

            if (postId == postIn.Id)
            {
                return(false);
            }

            var post = _posts
                       .Find(p => p.Id == postId)
                       .SingleOrDefault();

            if (post == null)
            {
                return(false);
            }

            var content = _contents
                          .Find(c => c.Id == post.ContentId)
                          .SingleOrDefault();

            if (content == null)
            {
                return(false);
            }

            post.Title     = postIn.Title;
            post.ExtraInfo = postIn.PostExtInfo;

            content.Text      = postIn.Text;
            content.ExtraInfo = postIn.ContentExtInfo;

            _posts.ReplaceOne(p => p.Id == post.Id, post);
            _contents.ReplaceOne(c => c.Id == content.Id, content);

            return(true);
        }
コード例 #3
0
        public IActionResult Update(string id, UpdatePostIn postIn)
        {
            if (_postSvc.Update(id, postIn) == false)
            {
                return(Ok(new
                {
                    success = false,
                    reason = "Failed to Update Post",
                }));
            }

            return(Ok(new
            {
                success = true,
            }));
        }
コード例 #4
0
        public IActionResult Update(string id, UpdatePostIn postIn)
        {
            { }

            if (_postSvc.Update(id, postIn, out var post, out var content) == false)
            {
                return(Ok(new
                {
                    success = false,
                    reason = "Failed to Update Post",
                }));
            }

            return(Ok(new
            {
                success = true,
                post,
                content,
            }));
        }