From b1e6d3dee9fa6519c65dd7564eac02b9e68bc3ce Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Apr 2017 21:13:44 -0400 Subject: Developer blog --- Project-Unite/Models/BlogModels.cs | 65 ++++++++++++++++++++++++++++++++++ Project-Unite/Models/IdentityModels.cs | 1 + 2 files changed, 66 insertions(+) create mode 100644 Project-Unite/Models/BlogModels.cs (limited to 'Project-Unite/Models') diff --git a/Project-Unite/Models/BlogModels.cs b/Project-Unite/Models/BlogModels.cs new file mode 100644 index 0000000..00ffbea --- /dev/null +++ b/Project-Unite/Models/BlogModels.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Project_Unite.Models +{ + public class PostBlogViewModel + { + [Required(ErrorMessage="Please enter a name for your post!")] + [MinLength(5, ErrorMessage ="Your post's name must have at least 5 characters.")] + [MaxLength(50, ErrorMessage = "Your post's name must have at least 50 characters.")] + public string Name { get; set; } + + [AllowHtml] + [Required(ErrorMessage ="You can't post an empty blog post!")] + [MinLength(20, ErrorMessage = "Your post must have at least 20 characters.")] + public string Contents { get; set; } + } + + public class BlogPost + { + public string Id { get; set; } + public string AuthorId { get; set; } + public ForumPost[] Comments + { + get + { + return new ApplicationDbContext().ForumPosts.Where(x => x.Parent == this.Id).ToArray(); + } + } + public Like[] Likes + { + get + { + return new ApplicationDbContext().Likes.Where(x => x.Topic == this.Id&&x.IsDislike == false).ToArray(); + } + } + + public string Name { get; set; } + + public string Summary + { + get + { + return Contents.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)[0]; + } + } + + public Like[] Dislikes + { + get + { + return new ApplicationDbContext().Likes.Where(x => x.Topic == this.Id && x.IsDislike == true).ToArray(); + + } + } + + public DateTime PostedAt { get; set; } + + public string Contents { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index cf04def..42f9e30 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -219,6 +219,7 @@ namespace Project_Unite.Models return new ApplicationDbContext(); } + public DbSet BlogPosts { get; set; } public DbSet ReadPosts { get; set; } public DbSet Downloads { get; set; } public DbSet Backups { get; set; } -- cgit v1.2.3