1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed stupid ef relationships...

This commit is contained in:
Uncled1023 2016-01-26 22:13:20 -08:00
parent 407da9243f
commit 6713696bb5
16 changed files with 222 additions and 50 deletions

View File

@ -15,7 +15,7 @@ namespace Teknik
bundles.Add(new StyleBundle("~/Content/Common").Include(
"~/Content/bootstrap.css",
"~/Content/font-awesome.css",
"~/Content/teknik.css"));
"~/Content/common.css"));
bundles.Add(new ScriptBundle("~/bundles/common").Include(
"~/Scripts/jquery-{version}.js",

View File

@ -246,7 +246,7 @@ namespace Teknik.Areas.Blog.Controllers
[AllowAnonymous]
public ActionResult GetComments(int postID, int startCommentID, int count)
{
var comments = db.BlogComments.Where(p => (p.BlogPostId == postID)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
var comments = db.BlogComments.Include("BlogPost").Include("BlogPost.Blog").Include("BlogPost.Blog.User").Include("User").Where(p => (p.BlogPostId == postID)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
List<CommentViewModel> commentViews = new List<CommentViewModel>();
if (comments != null)
{
@ -300,7 +300,7 @@ namespace Teknik.Areas.Blog.Controllers
{
if (ModelState.IsValid)
{
BlogPostComment comment = db.BlogComments.Find(commentID);
BlogPostComment comment = db.BlogComments.Include("User").Where(c => c.BlogPostCommentId == commentID).FirstOrDefault();
if (comment != null)
{
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
@ -324,7 +324,7 @@ namespace Teknik.Areas.Blog.Controllers
{
if (ModelState.IsValid)
{
BlogPostComment comment = db.BlogComments.Find(commentID);
BlogPostComment comment = db.BlogComments.Include("User").Where(c => c.BlogPostCommentId == commentID).FirstOrDefault();
if (comment != null)
{
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))

View File

@ -92,7 +92,7 @@
$('#editComment').on('show.bs.modal', function (e) {
$("#edit_comment_post").val("");
commentID = encodeURIComponent($(e.relatedTarget).attr("id"));
commentID = $(e.relatedTarget).attr("id");
$("#edit_comment_postid").val(commentID);
$.ajax({
type: "POST",
@ -108,8 +108,8 @@
$("#edit_comment_submit").click(function () {
$('#editComment').modal('hide');
postID = encodeURIComponent($("#edit_comment_postid").val());
post = encodeURIComponent($("#edit_comment_post").val());
postID = $("#edit_comment_postid").val();
post = $("#edit_comment_post").val();
$.ajax({
type: "POST",
url: editCommentURL,

View File

@ -1,16 +1,7 @@
@model Teknik.Areas.Blog.ViewModels.CommentViewModel
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@Model.CommentId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@Model.CommentId").html(new_post);
// Post Conversion
var old_post = $("#comment_@Model.CommentId").text();
var new_post = converter.makeHtml(old_post);
$("#comment_@Model.CommentId").html(new_post);
</script>
@using Teknik.Helpers
<hr>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
@ -24,7 +15,7 @@
<button type="button" class="btn btn-danger delete_comment" id="@Model.CommentId">Delete</button>
}
</p>
<p id="comment_@Model.CommentId">@Model.Article</p>
<p id="comment_@Model.CommentId">@Html.Markdown(Model.Article)</p>
</div>
</div>
</div>

View File

@ -65,7 +65,7 @@
}
<ol class="breadcrumb">
<li><a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = (Model.System) ? string.Empty : Model.Blog.User.Username })">@((Model.System) ? Model.Config.BlogConfig.Title : (string.IsNullOrEmpty(Model.Blog.Title) ? string.Format("{0}'s Blog", Model.Blog.User.Username) : Model.Blog.Title))</a></li>
<li><a href="@Url.SubRouteUrl("blog", "Blog.Blog", new { username = (Model.System) ? string.Empty : Model.Blog.User.Username })">@((Model.System) ? Model.Config.BlogConfig.Title : (string.IsNullOrEmpty(Model.Blog.User.BlogSettings.Title) ? string.Format("{0}'s Blog", Model.Blog.User.Username) : Model.Blog.User.BlogSettings.Title))</a></li>
<li class="active"><a href="#">@Model.Title</a></li>
</ol>

View File

@ -305,7 +305,7 @@ namespace Teknik.Areas.Podcast.Controllers
[AllowAnonymous]
public ActionResult GetComments(int podcastId, int startCommentID, int count)
{
var comments = db.PodcastComments.Where(p => (p.PodcastId == podcastId)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
var comments = db.PodcastComments.Include("BlogPost").Include("BlogPost.Blog").Include("BlogPost.Blog.User").Include("User").Where(p => (p.PodcastId == podcastId)).OrderByDescending(p => p.DatePosted).Skip(startCommentID).Take(count).ToList();
List<CommentViewModel> commentViews = new List<CommentViewModel>();
if (comments != null)
{
@ -321,7 +321,7 @@ namespace Teknik.Areas.Podcast.Controllers
[AllowAnonymous]
public ActionResult GetCommentArticle(int commentID)
{
PodcastComment comment = db.PodcastComments.Where(p => (p.PodcastCommentId == commentID)).First();
PodcastComment comment = db.PodcastComments.Where(p => (p.PodcastCommentId == commentID)).FirstOrDefault();
if (comment != null)
{
return Json(new { result = comment.Article });
@ -359,7 +359,7 @@ namespace Teknik.Areas.Podcast.Controllers
{
if (ModelState.IsValid)
{
PodcastComment comment = db.PodcastComments.Find(commentID);
PodcastComment comment = db.PodcastComments.Include("User").Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
if (comment != null)
{
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
@ -383,7 +383,7 @@ namespace Teknik.Areas.Podcast.Controllers
{
if (ModelState.IsValid)
{
PodcastComment comment = db.PodcastComments.Find(commentID);
PodcastComment comment = db.PodcastComments.Include("User").Where(c => c.PodcastCommentId == commentID).FirstOrDefault();
if (comment != null)
{
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))

View File

@ -118,7 +118,7 @@
$('#editComment').on('show.bs.modal', function (e) {
$("#edit_comment_post").val("");
commentID = encodeURIComponent($(e.relatedTarget).attr("id"));
commentID = $(e.relatedTarget).attr("id");
$("#edit_comment_id").val(commentID);
$.ajax({
type: "POST",
@ -134,8 +134,8 @@
$("#edit_comment_submit").click(function () {
$('#editComment').modal('hide');
postID = encodeURIComponent($("#edit_comment_id").val());
post = encodeURIComponent($("#edit_comment_post").val());
postID = $("#edit_comment_id").val();
post = $("#edit_comment_post").val();
$.ajax({
type: "POST",
url: editCommentURL,

View File

@ -1,16 +1,7 @@
@model Teknik.Areas.Blog.ViewModels.CommentViewModel
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_@Model.CommentId").text();
var new_post = converter.makeHtml(old_post);
$("#title_@Model.CommentId").html(new_post);
// Post Conversion
var old_post = $("#comment_@Model.CommentId").text();
var new_post = converter.makeHtml(old_post);
$("#comment_@Model.CommentId").html(new_post);
</script>
@using Teknik.Helpers
<hr>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
@ -24,7 +15,7 @@
<button type="button" class="btn btn-danger delete_comment" id="@Model.CommentId">Delete</button>
}
</p>
<p id="comment_@Model.CommentId">@Model.Article</p>
<p id="comment_@Model.CommentId">@Html.Markdown(Model.Article)</p>
</div>
</div>
</div>

View File

@ -118,8 +118,8 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
var foundUser = db.Users.Where(b => b.Username == model.Username);
if (foundUser.Any())
var foundUser = db.Users.Where(b => b.Username == model.Username).FirstOrDefault();
if (foundUser != null)
{
return Json(new { error = "That username already exists." });
}
@ -134,6 +134,9 @@ namespace Teknik.Areas.Profile.Controllers
newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username;
newUser.HashedPassword = SHA384.Hash(model.Username, model.Password);
newUser.UserSettings = new UserSettings();
newUser.BlogSettings = new BlogSettings();
newUser.UploadSettings = new UploadSettings();
db.Users.Add(newUser);
db.SaveChanges();
@ -201,9 +204,20 @@ namespace Teknik.Areas.Profile.Controllers
{
if (ModelState.IsValid)
{
// Delete Blogs
Blog.Models.Blog blog = db.Blogs.Include("BlogPosts").Include("User").Where(u => u.User.Username == User.Identity.Name).FirstOrDefault();
if (blog != null)
{
db.Blogs.Remove(blog);
db.SaveChanges();
}
User user = db.Users.Where(u => u.Username == User.Identity.Name).FirstOrDefault();
if (user != null)
{
user.UserSettings = db.UserSettings.Find(user.UserId);
user.BlogSettings = db.BlogSettings.Find(user.UserId);
user.UploadSettings = db.UploadSettings.Find(user.UserId);
db.Users.Remove(user);
db.SaveChanges();
FormsAuthentication.SignOut();

View File

@ -17,6 +17,12 @@ namespace Teknik.Areas.Profile.Models
public string Description { get; set; }
public virtual User User { get; set; }
public virtual UserSettings UserSettings { get; set; }
public virtual UploadSettings UploadSettings { get; set; }
public BlogSettings()
{
Title = string.Empty;

View File

@ -17,6 +17,12 @@ namespace Teknik.Areas.Profile.Models
public bool ServerSideEncrypt { get; set; }
public virtual User User { get; set; }
public virtual BlogSettings BlogSettings { get; set; }
public virtual UserSettings UserSettings { get; set; }
public UploadSettings()
{
SaveKey = false;

View File

@ -8,7 +8,6 @@ namespace Teknik.Areas.Profile.Models
{
public class User
{
[Key]
public int UserId { get; set; }
public string Username { get; set; }
@ -21,13 +20,10 @@ namespace Teknik.Areas.Profile.Models
public List<Group> Groups { get; set; }
[Required]
public virtual UserSettings UserSettings { get; set; }
[Required]
public virtual BlogSettings BlogSettings { get; set; }
[Required]
public virtual UploadSettings UploadSettings { get; set; }
public User()

View File

@ -19,6 +19,12 @@ namespace Teknik.Areas.Profile.Models
public string Quote { get; set; }
public virtual User User { get; set; }
public virtual BlogSettings BlogSettings { get; set; }
public virtual UploadSettings UploadSettings { get; set; }
public UserSettings()
{
About = string.Empty;

View File

@ -276,3 +276,154 @@ font-size: 24px;
.blockquote-box.blockquote-warning .square{background-color:#F0AD4E;color:#FFF}
.blockquote-box.blockquote-danger{border-color:#D43F3A}
.blockquote-box.blockquote-danger .square{background-color:#D9534F;color:#FFF}
/* column height modifiers */
/* USAGE
<div class="row">
<div class="row-height">
<div class="col-xs-2 col-xs-height col-xs-middle">
<div class="inside"></div>
</div>
<div class="col-xs-4 col-lg-5 col-xs-height col-xs-middle">
<div class="inside"></div>
</div>
</div>
</div>
*/
/* content styles */
.inside {
margin-top: 20px;
margin-bottom: 20px;
background: #ededed;
background: -webkit-gradient(linear, left top, left bottom,color-stop(0%, #f4f4f4), color-stop(100%, #ededed));
background: -moz-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
background: -ms-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
}
.inside-full-height {
/*
// if you want to give content full height give him height: 100%;
// with content full height you can't apply margins to the content
// content full height does not work in ie http://stackoverflow.com/questions/27384433/ie-display-table-cell-child-ignores-height-100
*/
height: 100%;
margin-top: 0;
margin-bottom: 0;
}
/* columns of same height styles */
.row-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-height {
display: table-cell;
float: none;
height: 100%;
}
.col-top {
vertical-align: top;
}
.col-middle {
vertical-align: middle;
}
.col-bottom {
vertical-align: bottom;
}
@media (min-width: 480px) {
.row-xs-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-xs-height {
display: table-cell;
float: none;
height: 100%;
}
.col-xs-top {
vertical-align: top;
}
.col-xs-middle {
vertical-align: middle;
}
.col-xs-bottom {
vertical-align: bottom;
}
}
@media (min-width: 768px) {
.row-sm-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-sm-height {
display: table-cell;
float: none;
height: 100%;
}
.col-sm-top {
vertical-align: top;
}
.col-sm-middle {
vertical-align: middle;
}
.col-sm-bottom {
vertical-align: bottom;
}
}
@media (min-width: 992px) {
.row-md-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-md-height {
display: table-cell;
float: none;
height: 100%;
}
.col-md-top {
vertical-align: top;
}
.col-md-middle {
vertical-align: middle;
}
.col-md-bottom {
vertical-align: bottom;
}
}
@media (min-width: 1200px) {
.row-lg-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-lg-height {
display: table-cell;
float: none;
height: 100%;
}
.col-lg-top {
vertical-align: top;
}
.col-lg-middle {
vertical-align: middle;
}
.col-lg-bottom {
vertical-align: bottom;
}
}

View File

@ -40,13 +40,24 @@ namespace Teknik.Models
{
modelBuilder.Entity<User>()
.HasRequired(a => a.UserSettings)
.WithRequiredPrincipal();
.WithRequiredPrincipal(a => a.User);
modelBuilder.Entity<User>()
.HasRequired(a => a.BlogSettings)
.WithRequiredPrincipal();
.WithRequiredPrincipal(a => a.User);
modelBuilder.Entity<User>()
.HasRequired(a => a.UploadSettings)
.WithRequiredPrincipal();
.WithRequiredPrincipal(a => a.User);
modelBuilder.Entity<UserSettings>()
.HasRequired(a => a.BlogSettings)
.WithRequiredPrincipal(a => a.UserSettings);
modelBuilder.Entity<UserSettings>()
.HasRequired(a => a.UploadSettings)
.WithRequiredPrincipal(a => a.UserSettings);
modelBuilder.Entity<BlogSettings>()
.HasRequired(a => a.UploadSettings)
.WithRequiredPrincipal(a => a.BlogSettings);
// Users
modelBuilder.Entity<User>().ToTable("Users");

View File

@ -351,7 +351,7 @@
<Content Include="Images\logo-blue-io.svg" />
<Content Include="Images\logo-blue.svg" />
<Content Include="Global.asax" />
<Content Include="Content\teknik.css" />
<Content Include="Content\commono.css" />
<Content Include="Images\Icon.png" />
<Content Include="ConnectionStrings.config" />
<Content Include="Areas\Blog\Views\web.config" />