void ReleaseDesignerOutlets() { if (PostAuthor != null) { PostAuthor.Dispose(); PostAuthor = null; } if (PostName != null) { PostName.Dispose(); PostName = null; } }
public async Task <ActionResult <AuthorResponse> > PostAuthor([FromBody] PostAuthor author) { string[] values = author.FullName.Split(' '); string firstName = values[0]; string lastName = values[1]; Author newAuthor = new Author() { FirstName = firstName, LastName = lastName }; _context.Authors.Add(newAuthor); await _context.SaveChangesAsync(); return(this.Ok(new AuthorResponse() { Id = newAuthor.Id, FirstName = newAuthor.FirstName, LastName = newAuthor.LastName })); }
async public Task <BlogPostDto> AddBlogPostAsync(BlogPostDto post) { if (post == null) { throw new ArgumentNullException("blogPost"); } //Post newPost = post.Adapt<Post>(); //newPost.CreatedAt = DateTime.UtcNow; //newPost.UpdatedAt = DateTime.UtcNow; //newPost.PostStatusId = (int)post.PostStatus; Post newPost = post.Adapt <Post>(); newPost.CreatedAt = DateTime.UtcNow; newPost.UpdatedAt = DateTime.UtcNow; newPost.PostStatus = null; //Post znewPost = new Post() //{ // Title = post.Title, // PostContent = post.PostContent, // Excerpt = post.Excerpt, // PostStatusId = (int)post.PostStatusId, // CommentStatusId = (int)post.CommentStatusId, // CommentCount = 0, // CreatedAt = DateTime.UtcNow, // UpdatedAt = DateTime.UtcNow, //}; Context.Post.Add(newPost); BlogPost newBlogPost = new BlogPost() { BlogId = post.BlogId, Post = newPost }; Context.BlogPost.Add(newBlogPost); Dictionary <string, Tag> existingTags = Context.Tag.Where(i => post.Tags.Contains(i.Name)).ToDictionary(i => i.Name.ToLower()); foreach (string tag in post.Tags) { Tag t = existingTags.ContainsKey(tag.ToLower()) ? existingTags[tag.ToLower()] : null; if (t == null) { t = new Tag() { Name = tag, Active = true, CreatedAt = DateTime.UtcNow }; } Context.PostTag.Add(new PostTag() { Post = newPost, Tag = t, CreatedAt = DateTime.UtcNow }); } PostAuthor primaryPostAuthor = new PostAuthor() { AuthorId = post.PrimaryAuthorId, Post = newPost, IsPrimary = true, ListOrder = 1, }; Context.PostAuthor.Add(primaryPostAuthor); await Context.SaveChangesAsync(); post = newPost.Adapt <BlogPostDto>(); post.BlogId = newBlogPost.BlogId; return(post); }
public static string ToString(PostAuthor author) { return $"{author.Name}|{author.Slug}|{author.Email}"; }