From 0f2629f0603b3c8f5dddf0747da6916dbf479dc4 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Mar 2017 18:08:20 -0400 Subject: [PATCH] Profile work. --- .../Controllers/ProfilesController.cs | 29 +++++++++++++++++ Project-Unite/Models/IdentityModels.cs | 31 +++++++++++++++++++ Project-Unite/Project-Unite.csproj | 3 ++ .../Views/Profiles/ViewProfile.cshtml | 27 ++++++++++++++++ Project-Unite/Views/Shared/_Layout.cshtml | 9 +++++- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 Project-Unite/Controllers/ProfilesController.cs create mode 100644 Project-Unite/Views/Profiles/ViewProfile.cshtml diff --git a/Project-Unite/Controllers/ProfilesController.cs b/Project-Unite/Controllers/ProfilesController.cs new file mode 100644 index 0000000..c77afda --- /dev/null +++ b/Project-Unite/Controllers/ProfilesController.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Project_Unite.Models; + +namespace Project_Unite.Controllers +{ + [Authorize] + public class ProfilesController : Controller + { + // GET: Profiles + public ActionResult Index() + { + return View(); + } + + public ActionResult ViewProfile(string id) + { + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.DisplayName == id); + if (user == null) + return new HttpStatusCodeResult(404); + + return View(user); + } + } +} \ No newline at end of file diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs index 1cf9577..71b12b9 100644 --- a/Project-Unite/Models/IdentityModels.cs +++ b/Project-Unite/Models/IdentityModels.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; @@ -131,4 +132,34 @@ public static ApplicationDbContext Create() public DbSet ForumPosts { get; set; } } + + public class UserPost + { + public string Id { get; set; } + public string UserId { get; set; } + + [MaxLength(1000, ErrorMessage ="Your post can't have more than 1000 characters.")] + [AllowHtml] + [MinLength(20, ErrorMessage ="To prevent spam, you must have at least 20 characters in your post.")] + public string PostContents { get; set; } + + public DateTime PostedAt { get; set; } + + public Like[] Likes + { + get + { + return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x => x.IsDislike == false).ToArray(); + } + } + + public Like[] Dislikes + { + get + { + return new ApplicationDbContext().Likes.Where(l => l.Topic == this.Id).Where(x => x.IsDislike == true).ToArray(); + } + } + + } } \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index 100b767..9c09bdb 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -232,6 +232,7 @@ + Global.asax @@ -505,6 +506,8 @@ + + diff --git a/Project-Unite/Views/Profiles/ViewProfile.cshtml b/Project-Unite/Views/Profiles/ViewProfile.cshtml new file mode 100644 index 0000000..94ca858 --- /dev/null +++ b/Project-Unite/Views/Profiles/ViewProfile.cshtml @@ -0,0 +1,27 @@ +@model Project_Unite.Models.ApplicationUser +@{ + ViewBag.Title = Model.DisplayName; + ViewBag.Banner = Model.BannerUrl; +} + +
+

+ @if (string.IsNullOrWhiteSpace(Model.FullName)) + { @Model.DisplayName } + else + { + @Model.FullName (@Model.DisplayName)} +

+
+ +
+
+

User stats

+
    +
  • @Model.Codepoints Codepoints
  • +
  • Joined at: @Model.JoinedAt
  • +
  • Posts: @Model.PostCount
  • +
  • Topics: @Model.TopicCount
  • +
+
+
\ No newline at end of file diff --git a/Project-Unite/Views/Shared/_Layout.cshtml b/Project-Unite/Views/Shared/_Layout.cshtml index 932593f..6530022 100644 --- a/Project-Unite/Views/Shared/_Layout.cshtml +++ b/Project-Unite/Views/Shared/_Layout.cshtml @@ -12,7 +12,14 @@ @Scripts.Render("~/bundles/modernizr") - +@{ + string style = ""; + if(ViewBag.Model != null) + { + style = "background-image: url(\"" + ViewBag.Model + "\") cover;"; + } +} + @Scripts.Render("~/Scripts/highlight.js")