public IActionResult Create(CreatePostIn postIn) { if (_postSvc.Create(postIn, out var post) == false) { return(Ok(new { success = false, reason = "Failed to Create Post", })); } return(Ok(new { success = true, post, })); }
public bool Create(CreatePostIn postIn, out Post createdPost, out Content createdContent) { createdPost = null; createdContent = null; if (postIn == null) { return(false); } var postId = Guid.NewGuid().ToString(); var contentId = Guid.NewGuid().ToString(); Post post = new Post { Id = postId, Title = postIn.Title, Creator = postIn.Creator, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ContentId = contentId, ViewCount = 0, LikeCount = 0, ExtraInfo = postIn.PostExtInfo, }; Content content = new Content { Id = contentId, Text = postIn.Text, PostId = postId, ExtraInfo = postIn.ContentExtInfo, }; _contents.InsertOne(content); _posts.InsertOne(post); createdPost = post; createdContent = content; return(true); }
public bool Create(CreatePostIn postIn, out Post created) { created = null; // Validation { if (postIn == null) { return(false); throw new Exception("Input is Null"); } if (string.IsNullOrWhiteSpace(postIn.Title)) { return(false); throw new Exception("Title is Null or Empty"); } if (string.IsNullOrWhiteSpace(postIn.CreatorId)) { return(false); throw new Exception("Creator Id is Null or Empty"); } if (string.IsNullOrWhiteSpace(postIn.Text)) { return(false); throw new Exception("Text is Null or Empty"); } if (postIn.IsAnonymous) { if (string.IsNullOrWhiteSpace(postIn.Password)) { return(false); } } else { if (_postRepo.Read(postIn.CreatorId, out var read) == false) { return(false); throw new Exception(string.Format("Failed to Find User ({0})", postIn.CreatorId)); } // 본인확인 - session? } } var postId = Guid.NewGuid().ToString(); Post post = new Post { Id = postId, Title = postIn.Title, CreatorId = postIn.CreatorId, CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Text = postIn.Text, ViewCount = 0, LikeCount = 0, Tags = postIn.Tags, Comments = new List <Comment>(), IsAnonymous = postIn.IsAnonymous, Password = postIn.Password, }; if (_postRepo.Create(post, out created) == false) { return(false); throw new Exception("Failed to Create Post"); } return(true); }