Browse Source

Split user settings into multiple objects.

tags/2.0.2
Teknikode 5 years ago
parent
commit
a68e7cca02

+ 7
- 12
Teknik/Areas/Blog/Controllers/BlogController.cs View File

@@ -44,16 +44,11 @@ namespace Teknik.Areas.Blog.Controllers
}
else // A user specific blog
{
Models.Blog blog = null;
var blogs = db.Blogs.Include("User").Where(p => p.User.Username == username);
if (blogs.Any())
{
blog = blogs.First();
ViewBag.Title = blog.User.Username + "'s Blog - " + Config.Title;
}
Models.Blog blog = db.Blogs.Include("User").Where(p => p.User.Username == username && p.BlogId != Constants.SERVERBLOGID).FirstOrDefault();
// find the blog specified
if (blog != null)
{
ViewBag.Title = blog.User.Username + "'s Blog - " + Config.Title;
bool isAuth = User.IsInRole("Admin");
var foundPosts = db.BlogPosts.Include("Blog").Include("Blog.User").Where(p => (p.BlogId == blog.BlogId && !p.System) &&
(p.Published || p.Blog.User.Username == User.Identity.Name || isAuth)).FirstOrDefault();
@@ -61,8 +56,8 @@ namespace Teknik.Areas.Blog.Controllers
model.BlogId = blog.BlogId;
model.UserId = blog.UserId;
model.User = blog.User;
model.Title = blog.Title;
model.Description = blog.Description;
model.Title = blog.User.BlogSettings.Title;
model.Description = blog.User.BlogSettings.Description;
model.HasPosts = (foundPosts != null);

return View(model);
@@ -179,7 +174,7 @@ namespace Teknik.Areas.Blog.Controllers
{
if (ModelState.IsValid)
{
BlogPost post = db.BlogPosts.Find(postID);
BlogPost post = db.BlogPosts.Include("Blog").Include("Blog.User").Where(p => p.BlogPostId == postID).FirstOrDefault();
if (post != null)
{
if (User.IsInRole("Admin") || post.Blog.User.Username == User.Identity.Name)
@@ -204,7 +199,7 @@ namespace Teknik.Areas.Blog.Controllers
{
if (ModelState.IsValid)
{
BlogPost post = db.BlogPosts.Find(postID);
BlogPost post = db.BlogPosts.Include("Blog").Include("Blog.User").Where(p => p.BlogPostId == postID).FirstOrDefault();
if (post != null)
{
if (User.IsInRole("Admin") || post.Blog.User.Username == User.Identity.Name)
@@ -229,7 +224,7 @@ namespace Teknik.Areas.Blog.Controllers
{
if (ModelState.IsValid)
{
BlogPost post = db.BlogPosts.Find(postID);
BlogPost post = db.BlogPosts.Include("Blog").Include("Blog.User").Where(p => p.BlogPostId == postID).FirstOrDefault();
if (post != null)
{
if (User.IsInRole("Admin") || post.Blog.User.Username == User.Identity.Name)

+ 0
- 4
Teknik/Areas/Blog/Models/Blog.cs View File

@@ -10,10 +10,6 @@ namespace Teknik.Areas.Blog.Models

public int UserId { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public User User { get; set; }

public List<BlogPost> BlogPosts { get; set; }

+ 36
- 47
Teknik/Areas/Profile/Controllers/ProfileController.cs View File

@@ -34,11 +34,10 @@ namespace Teknik.Areas.Profile.Controllers
ViewBag.Title = "User Does Not Exist - " + Config.Title;
ViewBag.Message = "The User does not exist";

var userQuery = db.Users.Where(u => u.Username == username);
User user = db.Users.Where(u => u.Username == username).FirstOrDefault();

if (userQuery != null && userQuery.Any())
if (user != null)
{
Models.User user = userQuery.First();
ViewBag.Title = username + "'s Profile - " + Config.Title;
ViewBag.Message = "Viewing " + username + "'s Profile";
@@ -47,18 +46,11 @@ namespace Teknik.Areas.Profile.Controllers
model.Email = string.Format("{0}@{1}", user.Username, Config.Host);
model.JoinDate = user.JoinDate;
model.LastSeen = user.LastSeen;
model.About = user.About;
model.Website = user.Website;
model.Quote = user.Quote;

// fill in Blog details
var blog = db.Blogs.Where(b => b.UserId == user.UserId);
if (blog != null && blog.Any())
{
Blog.Models.Blog foundBlog = blog.First();
model.BlogTitle = foundBlog.Title;
model.BlogDescription = foundBlog.Description;
}
model.UserSettings = user.UserSettings;
model.BlogSettings = user.BlogSettings;
model.UploadSettings = user.UploadSettings;

return View(model);
}
model.Error = true;
@@ -162,47 +154,45 @@ namespace Teknik.Areas.Profile.Controllers

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(string curPass, string newPass, string newPassConfirm, string website, string quote, string about, string blogTitle, string blogDesc)
public ActionResult Edit(string curPass, string newPass, string newPassConfirm, string website, string quote, string about, string blogTitle, string blogDesc, bool saveKey, bool serverSideEncrypt)
{
if (ModelState.IsValid)
{
User user = db.Users.Where(u => u.Username == User.Identity.Name).First();
if (user != null)
{
var foundBlog = db.Blogs.Where(b => b.UserId == user.UserId);
if (foundBlog != null && foundBlog.Any())
// Changing Password?
if (!string.IsNullOrEmpty(curPass) && (!string.IsNullOrEmpty(newPass) || !string.IsNullOrEmpty(newPassConfirm)))
{
Blog.Models.Blog blog = foundBlog.First();
// Changing Password?
if (!string.IsNullOrEmpty(curPass) && (!string.IsNullOrEmpty(newPass) || !string.IsNullOrEmpty(newPassConfirm)))
// Old Password Valid?
if (SHA384.Hash(User.Identity.Name, curPass) != user.HashedPassword)
{
// Old Password Valid?
if (SHA384.Hash(User.Identity.Name, curPass) != user.HashedPassword)
{
return Json(new { error = "Invalid Original Password." });
}
// The New Password Match?
if (newPass != newPassConfirm)
{
return Json(new { error = "New Password Must Match." });
}
user.HashedPassword = SHA384.Hash(User.Identity.Name, newPass);
return Json(new { error = "Invalid Original Password." });
}
user.Website = website;
user.Quote = quote;
user.About = about;
// The New Password Match?
if (newPass != newPassConfirm)
{
return Json(new { error = "New Password Must Match." });
}
user.HashedPassword = SHA384.Hash(User.Identity.Name, newPass);
}
user.UserSettings.Website = website;
user.UserSettings.Quote = quote;
user.UserSettings.About = about;

blog.Title = blogTitle;
blog.Description = blogDesc;
user.BlogSettings.Title = blogTitle;
user.BlogSettings.Description = blogDesc;

db.Entry(blog).State = EntityState.Modified;
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return Json(new { result = true });
}
user.UploadSettings.SaveKey = saveKey;
user.UploadSettings.ServerSideEncrypt = serverSideEncrypt;

db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return Json(new { result = true });
}
return Json(new { error = "User does not exist" });
}
return Json(new { error = "Unable to save profile." });
return Json(new { error = "Invalid Parameters" });
}

[HttpPost]
@@ -211,17 +201,16 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
var user = db.Users.Where(u => u.Username == User.Identity.Name);
if (user != null && user.Any())
User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
{
Models.User foundUser = user.First();
db.Users.Remove(foundUser);
db.Users.Remove(user);
db.SaveChanges();
FormsAuthentication.SignOut();
return Json(new { result = true });
}
}
return Json(new { error = "Unable to delete user." });
return Json(new { error = "Unable to delete user" });
}
}
}

+ 26
- 0
Teknik/Areas/Profile/Models/BlogSettings.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Teknik.Areas.Profile.Models
{
public class BlogSettings
{
[Key]
public int UserId { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public BlogSettings()
{
Title = string.Empty;
Description = string.Empty;
}
}
}

+ 26
- 0
Teknik/Areas/Profile/Models/UploadSettings.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Teknik.Areas.Profile.Models
{
public class UploadSettings
{
[Key]
public int UserId { get; set; }

public bool SaveKey { get; set; }

public bool ServerSideEncrypt { get; set; }

public UploadSettings()
{
SaveKey = false;
ServerSideEncrypt = false;
}
}
}

+ 13
- 8
Teknik/Areas/Profile/Models/User.cs View File

@@ -2,11 +2,13 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;

namespace Teknik.Areas.Profile.Models
{
public class User
{
[Key]
public int UserId { get; set; }
public string Username { get; set; }
@@ -18,12 +20,15 @@ namespace Teknik.Areas.Profile.Models
public DateTime LastSeen { get; set; }

public List<Group> Groups { get; set; }
[Required]
public virtual UserSettings UserSettings { get; set; }

public string About { get; set; }

public string Website { get; set; }
public string Quote { get; set; }
[Required]
public virtual BlogSettings BlogSettings { get; set; }
[Required]
public virtual UploadSettings UploadSettings { get; set; }

public User()
{
@@ -32,9 +37,9 @@ namespace Teknik.Areas.Profile.Models
JoinDate = DateTime.Now;
LastSeen = DateTime.Now;
Groups = new List<Group>();
About = string.Empty;
Website = string.Empty;
Quote = string.Empty;
//UserSettings = new UserSettings();
//BlogSettings = new BlogSettings();
//UploadSettings = new UploadSettings();
}
}
}

+ 29
- 0
Teknik/Areas/Profile/Models/UserSettings.cs View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Teknik.Areas.Profile.Models
{
public class UserSettings
{
[Key]
public int UserId { get; set; }

public string About { get; set; }

public string Website { get; set; }

public string Quote { get; set; }

public UserSettings()
{
About = string.Empty;
Website = string.Empty;
Quote = string.Empty;
}
}
}

+ 5
- 1
Teknik/Areas/Profile/Scripts/Profile.js View File

@@ -32,6 +32,8 @@
about = $("#update_about").val();
blog_title = $("#update_blog_title").val();
blog_desc = $("#update_blog_description").val();
upload_saveKey = $("#update_upload_saveKey").is(":checked");
upload_serverSideEncrypt = $("#update_upload_serverSideEncrypt").is(":checked");
$.ajax({
type: "POST",
url: editUserURL,
@@ -43,7 +45,9 @@
quote: quote,
about: about,
blogTitle: blog_title,
blogDesc: blog_desc
blogDesc: blog_desc,
saveKey: upload_saveKey,
serverSideEncrypt: upload_serverSideEncrypt
}),
success: function (html) {
if (html.result) {

+ 4
- 7
Teknik/Areas/Profile/ViewModels/ProfileViewModel.cs View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.Areas.Profile.Models;
using Teknik.ViewModels;

namespace Teknik.Areas.Profile.ViewModels
@@ -18,14 +19,10 @@ namespace Teknik.Areas.Profile.ViewModels

public DateTime LastSeen { get; set; }

public string About { get; set; }
public UserSettings UserSettings { get; set; }

public string Website { get; set; }
public BlogSettings BlogSettings { get; set; }

public string Quote { get; set; }

public string BlogTitle { get; set; }

public string BlogDescription { get; set; }
public UploadSettings UploadSettings { get; set; }
}
}

+ 30
- 21
Teknik/Areas/Profile/Views/Profile/Index.cshtml View File

@@ -16,10 +16,10 @@
bool OwnProfile = (Model.Username == User.Identity.Name || User.IsInRole("Admin"));

<div class="row">
<div class="col-sm-3@((string.IsNullOrEmpty(Model.About) && !OwnProfile) ? " col-sm-offset-4" : string.Empty)"><h1>@Model.Username</h1></div>
<div class="col-sm-3@((string.IsNullOrEmpty(Model.UserSettings.About) && !OwnProfile) ? " col-sm-offset-4" : string.Empty)"><h1>@Model.Username</h1></div>
</div>
<div class="row">
<div class="col-sm-3@((string.IsNullOrEmpty(Model.About) && !OwnProfile) ? " col-sm-offset-4" : string.Empty)"><!--left col-->
<div class="col-sm-3@((string.IsNullOrEmpty(Model.UserSettings.About) && !OwnProfile) ? " col-sm-offset-4" : string.Empty)"><!--left col-->
<ul class="list-group">
<li class="list-group-item text-muted">Profile</li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Joined</strong></span> <time datetime="@Model.LastSeen.ToString("o")">@Model.JoinDate.ToString("MMMM dd, yyyy")</time></li>
@@ -28,33 +28,33 @@
<li class="list-group-item text-right"><span class="pull-left"><strong>Last Seen</strong></span> <time datetime="@Model.LastSeen.ToString("o")">@Model.LastSeen.ToString("MMMM dd, yyyy")</time></li>
}
<li class="list-group-item text-right"><span class="pull-left"><strong>Email</strong></span> <a href="mailto:@Model.Email">@Model.Email</a></li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Blog</strong></span> <a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = Model.Username })" id="blog_title">@(string.IsNullOrEmpty(Model.BlogTitle) ? string.Format("{0}'s Blog", Model.Username) : Model.BlogTitle)</a></li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Blog</strong></span> <a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = Model.Username })" id="blog_title">@(string.IsNullOrEmpty(Model.BlogSettings.Title) ? string.Format("{0}'s Blog", Model.Username) : Model.BlogSettings.Title)</a></li>
<li class="list-group-item text-right"><span class="pull-left"><strong>Git</strong></span> <a href="@Url.SubRouteUrl("git", "Git.Index", new { username = Model.Username })">Public Repos</a></li>
@if (OwnProfile)
{
<li class="list-group-item text-center"><button type="button" class="btn btn-danger" id="delete_account">Delete Account</button></li>
}
</ul>
@if (!string.IsNullOrEmpty(Model.Website))
@if (!string.IsNullOrEmpty(Model.UserSettings.Website))
{
<div class="panel panel-default">
<div class="panel-heading">Website <i class="fa fa-link fa-1x"></i></div>
<div class="panel-body"><a href="@Model.Website" id="website">@Model.Website</a></div>
<div class="panel-body"><a href="@Model.UserSettings.Website" id="website">@Model.UserSettings.Website</a></div>
</div>
}
@if (!string.IsNullOrEmpty(Model.Quote))
@if (!string.IsNullOrEmpty(Model.UserSettings.Quote))
{
<div class="panel panel-default">
<div class="panel-heading">Quote <i class="fa fa-quote-right fa-1x"></i></div>
<div class="panel-body" id="quote">@Model.Quote</div>
<div class="panel-body" id="quote">@Model.UserSettings.Quote</div>
</div>
}
</div><!--/col-3-->
<div class="col-sm-9">
@if (!string.IsNullOrEmpty(Model.About) && OwnProfile)
@if (!string.IsNullOrEmpty(Model.UserSettings.About) && OwnProfile)
{
<ul class="nav nav-tabs" id="myTab">
@if (!string.IsNullOrEmpty(Model.About))
@if (!string.IsNullOrEmpty(Model.UserSettings.About))
{
<li @((OwnProfile) ? string.Empty : "class=\"active\"")>
<a href="#about" data-toggle="tab"> About Myself </a>
@@ -68,10 +68,10 @@
</ul>
}
<div class="tab-content">
@if (!string.IsNullOrEmpty(Model.About))
@if (!string.IsNullOrEmpty(Model.UserSettings.About))
{
<div class="tab-pane @((!OwnProfile) ? " active" : string.Empty)" id="about">
<div class="col-sm-12" id="markdown_body">@Html.Markdown(@Model.About)</div>
<div class="col-sm-12" id="markdown_body">@Html.Markdown(@Model.UserSettings.About)</div>
</div><!--/tab-pane-->
}
@if (OwnProfile)
@@ -103,17 +103,17 @@
<div class="row">
<div class="form-group col-sm-6">
<label for="update_website"><h4>Website</h4></label>
<input class="form-control" id="update_website" name="update_website" placeholder="http://www.noneofyourbusiness.com/" title="enter your website" type="text" value="@Model.Website" />
<input class="form-control" id="update_website" name="update_website" placeholder="http://www.noneofyourbusiness.com/" title="enter your website" type="text" value="@Model.UserSettings.Website" />
</div>
<div class="form-group col-sm-6">
<label for="update_quote"><h4>Quote</h4></label>
<input class="form-control" id="update_quote" name="update_quote" placeholder="I have a dream!" title="enter a memorable quote" type="text" value="@Model.Quote" maxlength="140" />
<input class="form-control" id="update_quote" name="update_quote" placeholder="I have a dream!" title="enter a memorable quote" type="text" value="@Model.UserSettings.Quote" maxlength="140" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="update_about"><h4>About Yourself</h4></label>
<textarea class="form-control" name="update_about" id="update_about" placeholder="I'm awesome" title="enter any information you want to share with the world." data-provide="markdown" rows="10">@Model.About</textarea>
<textarea class="form-control" name="update_about" id="update_about" placeholder="I'm awesome" title="enter any information you want to share with the world." data-provide="markdown" rows="10">@Model.UserSettings.About</textarea>
</div>
</div>
<!-- Blog Settings -->
@@ -126,11 +126,11 @@
<div class="row">
<div class="form-group col-sm-6">
<label for="update_blog_title"><h4>Title</h4></label>
<input class="form-control" id="update_blog_title" name="update_blog_title" placeholder="click bait" title="enter your blog's title" type="text" value="@Model.BlogTitle" />
<input class="form-control" id="update_blog_title" name="update_blog_title" placeholder="click bait" title="enter your blog's title" type="text" value="@Model.BlogSettings.Title" />
</div>
<div class="form-group col-sm-6">
<label for="update_blog_description"><h4>Description</h4></label>
<input class="form-control" id="update_blog_description" name="update_blog_description" placeholder="This blog is not worth reading." title="enter your blog's description" type="text" value="@Model.BlogDescription" />
<input class="form-control" id="update_blog_description" name="update_blog_description" placeholder="This blog is not worth reading." title="enter your blog's description" type="text" value="@Model.BlogSettings.Description" />
</div>
</div>
<!-- Upload Settings -->
@@ -140,13 +140,22 @@
</div>
</div>
<hr>
<!-- Paste Settings -->
<div class="row">
<div class="col-sm-12 text-center">
<h3>Paste Settings</h3>
<div class="col-sm-6">
<div class="checkbox">
<label>
<input id="update_upload_saveKey" name="update_upload_saveKey" title="whether the key should be saved on the server or not" type="checkbox" value="true" @(Model.UploadSettings.SaveKey ? "checked=\"checked\"" : "") /> Save Key on Server
</label>
</div>
</div>
</div>
<hr>
<div class="col-sm-6">
<div class="checkbox">
<label>
<input id="update_upload_serverSideEncrypt" name="update_upload_serverSideEncrypt" title="whether the file should be encrypted server side or client side" type="checkbox" value="true" @(Model.UploadSettings.ServerSideEncrypt ? "checked=\"checked\"" : "") /> Encrypt on Server Side
</label>
</div>
</div>
</div>
<!-- Save Settings -->
<div class="row">
<div class="form-group col-sm-12">

+ 17
- 4
Teknik/Areas/RSS/Controllers/RSSController.cs View File

@@ -29,19 +29,32 @@ namespace Teknik.Areas.RSS.Controllers
// If empty, grab the main blog
Blog.Models.Blog blog = null;
string blogUrl = string.Empty;
string title = string.Empty;
string description = string.Empty;
bool isSystem = string.IsNullOrEmpty(username);
if (string.IsNullOrEmpty(username))
if (isSystem)
{
blog = db.Blogs.Include("BlogPosts").Include("User").Where(b => b.BlogId == Constants.SERVERBLOGID).FirstOrDefault();
blog = db.Blogs.Include("BlogPosts").Include("User").Include("BlogSettings").Where(b => b.BlogId == Constants.SERVERBLOGID).FirstOrDefault();
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog");
}
else
{
blog = db.Blogs.Include("BlogPosts").Include("User").Where(b => b.User.Username == username).FirstOrDefault();
blog = db.Blogs.Include("BlogPosts").Include("User").Include("BlogSettings").Where(b => b.User.Username == username).FirstOrDefault();
blogUrl = Url.SubRouteUrl("blog", "Blog.Blog", new { username = username });
}
if (blog != null)
{
if (isSystem)
{
title = Config.BlogConfig.Title;
description = Config.BlogConfig.Description;
}
else
{
title = blog.User.BlogSettings.Title;
description = blog.User.BlogSettings.Description;
}

List<SyndicationItem> items = new List<SyndicationItem>();

foreach (BlogPost post in blog.BlogPosts)
@@ -58,7 +71,7 @@ namespace Teknik.Areas.RSS.Controllers
}
}

SyndicationFeed feed = new SyndicationFeed(blog.Title, blog.Description, new Uri(blogUrl), items);
SyndicationFeed feed = new SyndicationFeed(title, description, new Uri(blogUrl), items);

return new RssResult(feed);
}

+ 0
- 36
Teknik/Areas/RSS/Views/web.config View File

@@ -1,36 +0,0 @@
<?xml version="1.0"?>

<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization" />
<add namespace="Teknik" />
</namespaces>
</pages>
</system.web.webPages.razor>

<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>

<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

+ 24
- 0
Teknik/Models/TeknikEntities.cs View File

@@ -17,6 +17,10 @@ namespace Teknik.Models
public DbSet<User> Users { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<Role> Roles { get; set; }
// User Settings
public DbSet<UserSettings> UserSettings { get; set; }
public DbSet<BlogSettings> BlogSettings { get; set; }
public DbSet<UploadSettings> UploadSettings { get; set; }
// Blogs
public DbSet<Blog> Blogs { get; set; }
public DbSet<BlogPost> BlogPosts { get; set; }
@@ -34,15 +38,35 @@ namespace Teknik.Models

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasRequired(a => a.UserSettings)
.WithRequiredPrincipal();
modelBuilder.Entity<User>()
.HasRequired(a => a.BlogSettings)
.WithRequiredPrincipal();
modelBuilder.Entity<User>()
.HasRequired(a => a.UploadSettings)
.WithRequiredPrincipal();

// Users
modelBuilder.Entity<User>().ToTable("Users");
modelBuilder.Entity<Group>().ToTable("Groups");
modelBuilder.Entity<Role>().ToTable("Roles");
// User Settings
modelBuilder.Entity<UserSettings>().ToTable("Users");
modelBuilder.Entity<BlogSettings>().ToTable("Users");
modelBuilder.Entity<UploadSettings>().ToTable("Users");
// Blogs
modelBuilder.Entity<Blog>().ToTable("Blogs");
modelBuilder.Entity<BlogPost>().ToTable("BlogPosts");
modelBuilder.Entity<PodcastComment>().ToTable("BlogComments");
// Contact
modelBuilder.Entity<Contact>().ToTable("Contact");
// Uploads
modelBuilder.Entity<Upload>().ToTable("Uploads");
// Pastes
modelBuilder.Entity<Paste>().ToTable("Pastes");
// Podcasts
modelBuilder.Entity<Podcast>().ToTable("Podcasts");
modelBuilder.Entity<PodcastFile>().ToTable("PodcastFiles");
modelBuilder.Entity<PodcastComment>().ToTable("PodcastComments");

+ 3
- 5
Teknik/Teknik.csproj View File

@@ -193,6 +193,9 @@
<Compile Include="Areas\Privacy\PrivacyAreaRegistration.cs" />
<Compile Include="Areas\Privacy\ViewModels\PrivacyViewModel.cs" />
<Compile Include="Areas\Profile\Controllers\ProfileController.cs" />
<Compile Include="Areas\Profile\Models\BlogSettings.cs" />
<Compile Include="Areas\Profile\Models\UploadSettings.cs" />
<Compile Include="Areas\Profile\Models\UserSettings.cs" />
<Compile Include="Areas\Profile\ProfileAreaRegistration.cs" />
<Compile Include="Areas\Profile\ViewModels\ProfileViewModel.cs" />
<Compile Include="Areas\RSS\Controllers\RSSController.cs" />
@@ -431,7 +434,6 @@
<Content Include="Areas\Podcast\Views\Podcast\Comments.cshtml" />
<Content Include="Areas\Podcast\Views\Podcast\ViewPodcast.cshtml" />
<Content Include="App_Data\Config.json" />
<Content Include="Areas\RSS\Views\web.config" />
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
<Content Include="Scripts\bootbox\bootbox.min.js" />
@@ -521,10 +523,6 @@
<Folder Include="Areas\Privacy\Models\" />
<Folder Include="Areas\Privacy\Views\Shared\" />
<Folder Include="Areas\Profile\Views\Shared\" />
<Folder Include="Areas\RSS\Models\" />
<Folder Include="Areas\RSS\ViewModels\" />
<Folder Include="Areas\RSS\Views\RSS\" />
<Folder Include="Areas\RSS\Views\Shared\" />
<Folder Include="Areas\Upload\Views\Shared\" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save