public Post CreatePost() { Post result = new Post() { Title = this.Title, PostContent = this.Text, CreationDare = DateTime.Now }; return result; }
public HttpResponseMessage PostAPost(PostCreateModel model, string sessionKey) { var responseMsg = this.PerformOperation(() => { if (model.Title == null || model.Title.Length == 0) { throw new ArgumentException("You must have post title!"); } if (model.PostContent == null || model.PostContent.Length == 0) { throw new ArgumentException("You must have post content!"); } var context = new CoolBlogEntity(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user==null) { throw new InvalidOperationException("No user with this sessionKey"); } Post post = new Post() { Title = model.Title, PostContent = model.PostContent, CreationDare=model.CreationDate, User=user, Tags = PostDataPersister.GetPostTitleWords(model.Title).ToList(), Approved = true }; context.Posts.Add(post); context.SaveChanges(); model.Id = post.Id; return model; }); return responseMsg; }