mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Made podcast creation/editing work.
This commit is contained in:
parent
c48bfc3be9
commit
36a0db2533
@ -43,7 +43,7 @@ namespace Teknik.Areas.Blog
|
||||
"~/Scripts/ocupload/1.1.2/ocupload.js",
|
||||
"~/Scripts/PageDown/Markdown.Converter.js",
|
||||
"~/Scripts/PageDown/Markdown.Sanitizer.js",
|
||||
"~/Scripts/bootstrap-markdown.js",
|
||||
//"~/Scripts/bootstrap-markdown.js", Uneeded?
|
||||
"~/Scripts/bootbox/bootbox.min.js",
|
||||
"~/Areas/Blog/Scripts/Blog.js"));
|
||||
// Register Style Bundles
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Teknik.Areas.Podcast.Models;
|
||||
using Teknik.Areas.Blog.Models;
|
||||
using Teknik.Areas.Home.ViewModels;
|
||||
using Teknik.Controllers;
|
||||
@ -31,7 +32,10 @@ namespace Teknik.Areas.Home.Controllers
|
||||
if (foundPosts != null)
|
||||
lastPosts = foundPosts.ToList();
|
||||
// Grab the latest podcasts
|
||||
List<BlogPost> lastPods = new List<BlogPost>();
|
||||
List<Podcast.Models.Podcast> lastPods = new List<Podcast.Models.Podcast>();
|
||||
var foundPods = db.Podcasts.OrderBy(post => post.DatePosted).Where(p => p.Published).Take(10);
|
||||
if (foundPods != null)
|
||||
lastPods = foundPods.ToList();
|
||||
|
||||
model.SitePosts = lastSite;
|
||||
model.Podcasts = lastPods;
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Teknik.Areas.Blog.Models;
|
||||
using Teknik.Areas.Podcast.Models;
|
||||
using Teknik.ViewModels;
|
||||
|
||||
namespace Teknik.Areas.Home.ViewModels
|
||||
@ -11,7 +12,7 @@ namespace Teknik.Areas.Home.ViewModels
|
||||
public class HomeViewModel : ViewModelBase
|
||||
{
|
||||
public List<BlogPost> SitePosts { get; set; }
|
||||
public List<BlogPost> Podcasts { get; set; }
|
||||
public List<Podcast.Models.Podcast> Podcasts { get; set; }
|
||||
public List<BlogPost> BlogPosts { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
@model Teknik.Areas.Home.ViewModels.HomeViewModel
|
||||
|
||||
@using Teknik.Areas.Blog.Models
|
||||
@using Teknik.Areas.Podcast.Models
|
||||
|
||||
@Styles.Render("~/Content/home")
|
||||
@Scripts.Render("~/bundles/home")
|
||||
@ -133,21 +134,21 @@
|
||||
<ul class="list-group">
|
||||
@if (Model.SitePosts.Any())
|
||||
{
|
||||
foreach (Post post in Model.SitePosts)
|
||||
foreach (BlogPost post in Model.SitePosts)
|
||||
{
|
||||
<script>
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@post.PostId").text();
|
||||
var old_post = $("#title_@post.BlogPostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@post.PostId").html(new_post);
|
||||
$("#title_@post.BlogPostId").html(new_post);
|
||||
</script>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="blog-post-sm">
|
||||
<h2 class="blog-post-title-sm text-left">
|
||||
<a href="@Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
|
||||
<a href="@Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.BlogPostId })" id="title_@post.BlogPostId">@post.Title</a>
|
||||
</h2>
|
||||
<p class="blog-post-meta-sm text-left text-muted">
|
||||
Posted on <time datetime="@post.DatePosted.ToString("o")">@post.DatePosted.ToString("MMMM dd, yyyy")</time> by <a href="@Url.SubRouteUrl("profile", "Profile.Index", new { username = post.Blog.User.Username })">@post.Blog.User.Username</a>
|
||||
@ -184,24 +185,24 @@
|
||||
<ul class="list-group">
|
||||
@if (Model.Podcasts.Any())
|
||||
{
|
||||
foreach (Post post in Model.Podcasts)
|
||||
foreach (Podcast podcast in Model.Podcasts)
|
||||
{
|
||||
<script>
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@post.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@post.PostId").html(new_post);
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@podcast.PodcastId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@podcast.PodcastId").html(new_post);
|
||||
</script>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="blog-post-sm">
|
||||
<h2 class="blog-post-title-sm text-left">
|
||||
<a href="@Url.SubRouteUrl("podcast", "Podcast.View", new { username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
|
||||
<a href="@Url.SubRouteUrl("podcast", "Podcast.View", new { episode = podcast.Episode })" id="title_@podcast.PodcastId">@podcast.Title</a>
|
||||
</h2>
|
||||
<p class="blog-post-meta-sm text-left text-muted">
|
||||
Posted on <time datetime="@post.DatePosted.ToString("o")">@post.DatePosted.ToString("MMMM dd, yyyy")</time>
|
||||
Posted on <time datetime="@podcast.DatePosted.ToString("o")">@podcast.DatePosted.ToString("MMMM dd, yyyy")</time>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -235,20 +236,20 @@
|
||||
<ul class="list-group">
|
||||
@if (Model.BlogPosts.Any())
|
||||
{
|
||||
foreach (Post post in Model.BlogPosts)
|
||||
foreach (BlogPost post in Model.BlogPosts)
|
||||
{
|
||||
<script>
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@post.PostId").text();
|
||||
var old_post = $("#title_@post.BlogPostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@post.PostId").html(new_post);
|
||||
$("#title_@post.BlogPostId").html(new_post);
|
||||
</script>
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="blog-post-sm">
|
||||
<h2 class="blog-post-title-sm text-left"><a href="@Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.PostId })" id="title_@post.PostId">@post.Title</a>
|
||||
<h2 class="blog-post-title-sm text-left"><a href="@Url.SubRouteUrl("blog", "Blog.Post", new { username = post.Blog.User.Username, id = post.BlogPostId })" id="title_@post.BlogPostId">@post.Title</a>
|
||||
</h2>
|
||||
<p class="blog-post-meta-sm text-left text-muted">
|
||||
Posted on <time datetime="@post.DatePosted.ToString("o")">@post.DatePosted.ToString("MMMM dd, yyyy")</time> by <a href="@Url.SubRouteUrl("profile", "Profile.Index", new { username = post.Blog.User.Username })">@post.Blog.User.Username</a>
|
||||
|
@ -22,7 +22,7 @@ namespace Teknik.Areas.Paste
|
||||
|
||||
// Generate random url
|
||||
string url = Utility.RandomString(config.PasteConfig.UrlLength);
|
||||
while (db.Pastes.Where(p => p.Url == url) != null)
|
||||
while (db.Pastes.Where(p => p.Url == url).FirstOrDefault() != null)
|
||||
{
|
||||
url = Utility.RandomString(config.PasteConfig.UrlLength);
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Teknik.Areas.Podcast.Models;
|
||||
using Teknik.Areas.Podcast.ViewModels;
|
||||
using Teknik.Controllers;
|
||||
using Teknik.Models;
|
||||
@ -13,21 +15,19 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
public class PodcastController : DefaultController
|
||||
{
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
// GET: Blogs/Details/5
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Index()
|
||||
{
|
||||
MainViewModel model = new MainViewModel();
|
||||
model.Title = Config.PodcastConfig.Title;
|
||||
model.Description = Config.PodcastConfig.Description;
|
||||
try
|
||||
{
|
||||
ViewBag.Title = "Teknik Blog - " + Config.Title;
|
||||
var foundPodcasts = (User.IsInRole("Admin")) ? db.Podcasts.FirstOrDefault() : db.Podcasts.Where(p => (p.Published)).FirstOrDefault();
|
||||
ViewBag.Title = "Teknikast - " + Config.Title;
|
||||
var foundPodcasts = (User.IsInRole("Podcast")) ? db.Podcasts.FirstOrDefault() : db.Podcasts.Where(p => (p.Published)).FirstOrDefault();
|
||||
if (foundPodcasts != null)
|
||||
{
|
||||
model = new MainViewModel();
|
||||
model.Title = Config.PodcastConfig.Title;
|
||||
model.Description = Config.PodcastConfig.Description;
|
||||
model.HasPodcasts = (foundPodcasts != null);
|
||||
}
|
||||
else
|
||||
@ -47,14 +47,13 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
#region Posts
|
||||
// GET: Blogs/Details/5
|
||||
#region Podcasts
|
||||
[AllowAnonymous]
|
||||
public ActionResult View(int episode)
|
||||
{
|
||||
PodcastViewModel model = new PodcastViewModel();
|
||||
// find the podcast specified
|
||||
var foundPodcast = (User.IsInRole("Admin")) ? db.Podcasts.Where(p => p.Episode == episode).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.Episode == episode)).FirstOrDefault();
|
||||
var foundPodcast = (User.IsInRole("Podcast")) ? db.Podcasts.Include("Files").Where(p => p.Episode == episode).FirstOrDefault() : db.Podcasts.Include("Files").Where(p => (p.Published && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
model.PodcastId = foundPodcast.PodcastId;
|
||||
@ -71,12 +70,43 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
return View("~/Areas/Podcast/Views/Podcast/ViewPodcast.cshtml", model);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
public ActionResult Download(int episode, string fileName)
|
||||
{
|
||||
// find the podcast specified
|
||||
var foundPodcast = (User.IsInRole("Podcast")) ? db.Podcasts.Include("Files").Where(p => p.Episode == episode).FirstOrDefault() : db.Podcasts.Include("Files").Where(p => (p.Published && p.Episode == episode)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
PodcastFile file = foundPodcast.Files.Where(f => f.FileName == fileName).FirstOrDefault();
|
||||
if (file != null)
|
||||
{
|
||||
if (System.IO.File.Exists(file.Path))
|
||||
{
|
||||
// Read in the file
|
||||
byte[] data = System.IO.File.ReadAllBytes(file.Path);
|
||||
|
||||
// Create File
|
||||
var cd = new System.Net.Mime.ContentDisposition
|
||||
{
|
||||
FileName = file.FileName,
|
||||
Inline = true
|
||||
};
|
||||
|
||||
Response.AppendHeader("Content-Disposition", cd.ToString());
|
||||
|
||||
return File(data, file.ContentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcasts(int startPodcastID, int count)
|
||||
{
|
||||
var podcasts = (User.IsInRole("Admin")) ? db.Podcasts.OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList()
|
||||
: db.Podcasts.Where(p => p.Published).OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList();
|
||||
var podcasts = (User.IsInRole("Podcast")) ? db.Podcasts.Include("Files").OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList()
|
||||
: db.Podcasts.Include("Files").Where(p => p.Published).OrderByDescending(p => p.DatePosted).Skip(startPodcastID).Take(count).ToList();
|
||||
List<PodcastViewModel> podcastViews = new List<PodcastViewModel>();
|
||||
if (podcasts != null)
|
||||
{
|
||||
@ -88,67 +118,135 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
return PartialView("~/Areas/Podcast/Views/Podcast/Podcasts.cshtml", podcastViews);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastEpisode(int podcastId)
|
||||
{
|
||||
var foundPodcast = (User.IsInRole("Podcast")) ? db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Episode });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastTitle(int podcastId)
|
||||
{
|
||||
var foundPodcast = (User.IsInRole("Admin")) ? db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
var foundPodcast = (User.IsInRole("Podcast")) ? db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Title });
|
||||
}
|
||||
return Json(new { error = "No title found" });
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPodcastDescription(int podcastId)
|
||||
{
|
||||
var foundPodcast = (User.IsInRole("Admin")) ? db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
var foundPodcast = (User.IsInRole("Podcast")) ? db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() : db.Podcasts.Where(p => (p.Published && p.PodcastId == podcastId)).FirstOrDefault();
|
||||
if (foundPodcast != null)
|
||||
{
|
||||
return Json(new { result = foundPodcast.Description });
|
||||
}
|
||||
return Json(new { error = "No article found" });
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult CreatePodcast(string title, string description, HttpPostedFileBase[] files)
|
||||
public ActionResult CreatePodcast(int episode, string title, string description)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Handle saving of files
|
||||
Models.Podcast podcast = db.Podcasts.Create();
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DatePosted = DateTime.Now;
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
// Grab the next episode number
|
||||
Models.Podcast lastPod = db.Podcasts.Where(p => p.Episode == episode).FirstOrDefault();
|
||||
if (lastPod == null)
|
||||
{
|
||||
if (Request.Files.Count > 0)
|
||||
{
|
||||
// Create the podcast object
|
||||
Models.Podcast podcast = db.Podcasts.Create();
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
podcast.DatePosted = DateTime.Now;
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
|
||||
db.Podcasts.Add(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
// Handle saving of files
|
||||
for (int i = 0; i < Request.Files.Count; i++)
|
||||
{
|
||||
HttpPostedFileBase file = Request.Files[i]; //Uploaded file
|
||||
//Use the following properties to get file's name, size and MIMEType
|
||||
int fileSize = file.ContentLength;
|
||||
string fileName = file.FileName;
|
||||
string mimeType = file.ContentType;
|
||||
string fileExt = Path.GetExtension(fileName);
|
||||
if (!Directory.Exists(Config.PodcastConfig.PodcastDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(Config.PodcastConfig.PodcastDirectory);
|
||||
}
|
||||
string newName = string.Format("Teknikast_Episode_{0}{1}", episode, fileExt);
|
||||
int index = 1;
|
||||
while (System.IO.File.Exists(Path.Combine(Config.PodcastConfig.PodcastDirectory, newName)))
|
||||
{
|
||||
newName = string.Format("Teknikast_Episode_{0} ({1}){2}", episode, index, fileExt);
|
||||
index++;
|
||||
}
|
||||
string fullPath = Path.Combine(Config.PodcastConfig.PodcastDirectory, newName);
|
||||
PodcastFile podFile = new PodcastFile();
|
||||
podFile.Path = fullPath;
|
||||
podFile.FileName = newName;
|
||||
podFile.ContentType = mimeType;
|
||||
podcast.Files = new List<PodcastFile>();
|
||||
podcast.Files.Add(podFile);
|
||||
|
||||
file.SaveAs(fullPath);
|
||||
}
|
||||
|
||||
db.Podcasts.Add(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "You must submit at least one podcast audio file" });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to create a podcast" });
|
||||
}
|
||||
return Json(new { error = "No podcast created" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult EditPodcast(int podcastId, string title, string description)
|
||||
public ActionResult EditPodcast(int podcastId, int episode, string title, string description)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
{
|
||||
if (db.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null)
|
||||
{
|
||||
podcast.Episode = episode;
|
||||
podcast.Title = title;
|
||||
podcast.Description = description;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "That episode already exists" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to edit this podcast" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
return Json(new { error = "Invalid Inputs" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -157,18 +255,23 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
podcast.Published = publish;
|
||||
if (publish)
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
{
|
||||
podcast.Published = publish;
|
||||
if (publish)
|
||||
podcast.DatePublished = DateTime.Now;
|
||||
db.Entry(podcast).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to publish this podcast" });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
return Json(new { error = "Invalid Inputs" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -177,15 +280,20 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
db.Podcasts.Remove(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
Models.Podcast podcast = db.Podcasts.Find(podcastId);
|
||||
if (podcast != null)
|
||||
{
|
||||
db.Podcasts.Remove(podcast);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "No podcast found" });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to delete this podcast" });
|
||||
}
|
||||
return Json(new { error = "No post found" });
|
||||
return Json(new { error = "Invalid Inputs" });
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -224,17 +332,21 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
Models.PodcastComment comment = db.PodcastComments.Create();
|
||||
comment.PodcastId = podcastId;
|
||||
comment.UserId = db.Users.Where(u => u.Username == User.Identity.Name).First().UserId;
|
||||
comment.Article = article;
|
||||
comment.DatePosted = DateTime.Now;
|
||||
if (db.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault() != null)
|
||||
{
|
||||
Models.PodcastComment comment = db.PodcastComments.Create();
|
||||
comment.PodcastId = podcastId;
|
||||
comment.UserId = db.Users.Where(u => u.Username == User.Identity.Name).First().UserId;
|
||||
comment.Article = article;
|
||||
comment.DatePosted = DateTime.Now;
|
||||
|
||||
db.PodcastComments.Add(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
db.PodcastComments.Add(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "That podcast does not exist" });
|
||||
}
|
||||
return Json(new { error = "No comment created" });
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -246,13 +358,18 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
Models.PodcastComment comment = db.PodcastComments.Find(commentID);
|
||||
if (comment != null)
|
||||
{
|
||||
comment.Article = article;
|
||||
db.Entry(comment).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
{
|
||||
comment.Article = article;
|
||||
db.Entry(comment).State = EntityState.Modified;
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to edit this comment" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
@ -264,12 +381,17 @@ namespace Teknik.Areas.Podcast.Controllers
|
||||
Models.PodcastComment comment = db.PodcastComments.Find(commentID);
|
||||
if (comment != null)
|
||||
{
|
||||
db.PodcastComments.Remove(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
|
||||
{
|
||||
db.PodcastComments.Remove(comment);
|
||||
db.SaveChanges();
|
||||
return Json(new { result = true });
|
||||
}
|
||||
return Json(new { error = "You don't have permission to delete this comment" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
}
|
||||
return Json(new { error = "No comment found" });
|
||||
return Json(new { error = "Invalid Parameters" });
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -30,6 +30,13 @@ namespace Teknik.Areas.Podcast
|
||||
new { controller = "Podcast", action = "View" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.PodcastController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Podcast.Download", // Route name
|
||||
new List<string>() { "dev", "podcast" }, // Subdomains
|
||||
"File/{episode}/{fileName}", // URL with parameters
|
||||
new { controller = "Podcast", action = "Download" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.PodcastController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Podcast.Action", // Route name
|
||||
new List<string>() { "dev", "podcast" }, // Subdomains
|
||||
@ -43,7 +50,7 @@ namespace Teknik.Areas.Podcast
|
||||
"~/Scripts/bootbox/bootbox.min.js",
|
||||
"~/Scripts/PageDown/Markdown.Converter.js",
|
||||
"~/Scripts/PageDown/Markdown.Sanitizer.js",
|
||||
"~/Scripts/bootstrap-markdown.js",
|
||||
//"~/Scripts/bootstrap-markdown.js", Uneeded?
|
||||
"~/Scripts/jquery-ui.widgets.js",
|
||||
"~/Scripts/jquery.iframe-transport.js",
|
||||
"~/Scripts/audioplayer.min.js",
|
||||
|
@ -1,31 +1,55 @@
|
||||
$(document).ready(function () {
|
||||
$("#podcast_submit").click(function () {
|
||||
$('#newPodcast').modal('hide');
|
||||
var fd = new FormData();
|
||||
var fileInput = document.getElementById('podcast_files');
|
||||
for (i = 0; i < fileInput.files.length; i++) {
|
||||
//Appending each file to FormData object
|
||||
fd.append(fileInput.files[i].name, fileInput.files[i]);
|
||||
}
|
||||
episode = $("#podcast_episode").val();
|
||||
title = $("#podcast_title").val();
|
||||
post = $("#podcast_description").val();
|
||||
files = $("#podcast_files").val();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: addPodcastURL,
|
||||
data: AddAntiForgeryToken({ title: title, description: post, files: files }),
|
||||
success: function (html) {
|
||||
if (html.result) {
|
||||
description = $("#podcast_description").val();
|
||||
|
||||
fd.append("episode", episode);
|
||||
fd.append("title", title);
|
||||
fd.append("description", description);
|
||||
fd.append('__RequestVerificationToken', $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val());
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', addPodcastURL);
|
||||
xhr.send(fd);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
obj = JSON.parse(xhr.responseText);
|
||||
if (obj.result) {
|
||||
window.location.reload();
|
||||
}
|
||||
else {
|
||||
$("#top_msg").css('display', 'inline', 'important');
|
||||
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + html.error + '</div>');
|
||||
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + obj.error + '</div>');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#editPodcast').on('show.bs.modal', function (e) {
|
||||
$("#edit_podcast_episode").val("");
|
||||
$("#edit_podcast_title").val("");
|
||||
$("#edit_podcast_description").val("");
|
||||
podcastId = $(e.relatedTarget).attr("id");
|
||||
$("#edit_podcast_podcastid").val(podcastId);
|
||||
$("#edit_podcast_podcastId").val(podcastId);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: getPodcastEpisodeURL,
|
||||
data: { podcastID: podcastId },
|
||||
success: function (html) {
|
||||
if (html.result) {
|
||||
$("#edit_podcast_episode").val(html.result);
|
||||
}
|
||||
}
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: getPodcastTitleURL,
|
||||
@ -51,12 +75,13 @@
|
||||
$("#edit_submit").click(function () {
|
||||
$('#editPodcast').modal('hide');
|
||||
podcastId = $("#edit_podcast_podcastId").val();
|
||||
episode = $("#edit_podcast_episode").val();
|
||||
title = $("#edit_podcast_title").val();
|
||||
description = $("#edit_podcast_description").val();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: editPodcastURL,
|
||||
data: AddAntiForgeryToken({ podcastId: podcastId, title: title, description: description }),
|
||||
data: AddAntiForgeryToken({ podcastId: podcastId, episode: episode, title: title, description: description }),
|
||||
success: function (html) {
|
||||
if (html.result) {
|
||||
window.location.reload();
|
||||
@ -138,9 +163,9 @@ function loadMorePodcasts(start, count) {
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$(".podcast-main").append(html);
|
||||
linkPostDelete('.delete_podcast');
|
||||
linkPostPublish('.publish_podcast');
|
||||
linkPostUnpublish('.unpublish_podcast');
|
||||
linkPodcastDelete('.delete_podcast');
|
||||
linkPodcastPublish('.publish_podcast');
|
||||
linkPodcastUnpublish('.unpublish_podcast');
|
||||
linkAudioPlayer('audio');
|
||||
$(window).bind('scroll', bindScrollPosts);
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
var uploadURL = '@Url.SubRouteUrl("upload", "Upload.Upload")';
|
||||
|
||||
var getPodcastsURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcasts" })';
|
||||
var getPodcastEpisodeURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastEpisode" })';
|
||||
var getPodcastTitleURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastTitle" })';
|
||||
var getPodcastArticleURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastArticle" })';
|
||||
var getPodcastDescriptionURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastDescription" })';
|
||||
var publishPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "PublishPodcast" })';
|
||||
var addPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "CreatePodcast" })';
|
||||
var editPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "EditPodcast" })';
|
||||
@ -37,7 +38,7 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@if (User.IsInRole("Admin") || User.IsInRole("Podcast"))
|
||||
@if (User.IsInRole("Podcast"))
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
@ -47,12 +48,18 @@
|
||||
<div class="modal fade" id="newPodcast" tabindex="-1" role="dialog" aria-labelledby="newPodcastLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form class="form" action="##" method="post" id="publishPodcast">
|
||||
<form class="form" action="##" method="post" id="publishPodcast" enctype="multipart/form-data">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cancel</span></button>
|
||||
<h4 class="modal-title" id="newPodcastLabel">Create a New Podcast</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="podcast_episode"><h4>Episode Number</h4></label>
|
||||
<input class="form-control" name="podcast_episode" id="podcast_episode" placeholder="1" title="enter an episode number for the podcast" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="podcast_title"><h4>Title</h4></label>
|
||||
@ -68,7 +75,7 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="files"><h4>Upload Podcast</h4></label>
|
||||
<input id="files" name="files" type="file" placeholder="podcast.ogg" title="select the podcast file." multiple="multiple" />
|
||||
<input id="podcast_files" name="podcast_files" type="file" placeholder="podcast.ogg" title="select the podcast file." multiple>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -94,6 +101,12 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="edit_podcast_podcastId" id="edit_podcast_podcastId" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_podcast_episode"><h4>Episode Number</h4></label>
|
||||
<input class="form-control" name="edit_podcast_episode" id="edit_podcast_episode" placeholder="1" title="enter an episode number for the podcast" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_podcast_title"><h4>Title</h4></label>
|
||||
|
@ -11,10 +11,10 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<div class="podcast-post">
|
||||
<h2 class="podcast-post-title text-center"><a href="@Url.SubRouteUrl("podcast", "Podcast.View", new { episode = Model.Episode })" id="title_@Model.PodcastId">@Model.Title</a></h2>
|
||||
<h2 class="podcast-post-title text-center"><a href="@Url.SubRouteUrl("podcast", "Podcast.View", new { episode = Model.Episode })" id="title_@Model.PodcastId">Episode @Model.Episode - @Model.Title</a></h2>
|
||||
<p class="podcast-post-meta text-center text-muted">
|
||||
Posted on <time datetime="@Model.DatePosted.ToString("o")">@Model.DatePosted.ToString("MMMM dd, yyyy")</time>
|
||||
@if (User.IsInRole("Admin") || User.IsInRole("Podcast"))
|
||||
@if (User.IsInRole("Podcast"))
|
||||
{
|
||||
<br />
|
||||
<button type="button" class="btn btn-info edit_post" id="@Model.PodcastId" data-toggle="modal" data-target="#editPodcast">Edit</button>
|
||||
@ -26,24 +26,30 @@
|
||||
{
|
||||
<button type="button" class="btn btn-success publish_podcast" id="@Model.PodcastId">Publish</button>
|
||||
}
|
||||
<button type="button" class="btn btn-danger delete_post" id="@Model.PodcastId">Delete</button>
|
||||
<button type="button" class="btn btn-danger delete_podcast" id="@Model.PodcastId">Delete</button>
|
||||
}
|
||||
</p>
|
||||
@if (Model.Files != null)
|
||||
{
|
||||
<div class="text-center">
|
||||
<audio preload="none" controls>
|
||||
@foreach (PodcastFile file in Model.Files)
|
||||
{
|
||||
<source src="@file.Path" type="@file.ContentType" />
|
||||
<source src="@Url.SubRouteUrl("podcast", "Podcast.Download", new { episode = Model.Episode, fileName = file.FileName })" type="@file.ContentType" />
|
||||
}
|
||||
</audio>
|
||||
</div>
|
||||
}
|
||||
<br />
|
||||
<p id="podcast_@Model.PodcastId">@Model.Description</p>
|
||||
@foreach (PodcastFile file in Model.Files)
|
||||
@if (Model.Files != null)
|
||||
{
|
||||
<div class="row text-center">
|
||||
<a href="@Url.SubRouteUrl("podcast", "Podcast.Download", new { file = file.FileName })">Direct Download - @file.ContentType</a>
|
||||
</div>
|
||||
foreach (PodcastFile file in Model.Files)
|
||||
{
|
||||
<div class="row text-center">
|
||||
<a href="@Url.SubRouteUrl("podcast", "Podcast.Download", new { episode = Model.Episode, fileName = file.FileName })">Direct Download - @file.ContentType</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,9 +1,33 @@
|
||||
@model Teknik.Areas.Podcast.ViewModels.PodcastViewModel
|
||||
|
||||
<script>
|
||||
// We need to define the action URLs for the script
|
||||
|
||||
var uploadURL = '@Url.SubRouteUrl("upload", "Upload.Upload")';
|
||||
|
||||
var getPodcastsURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcasts" })';
|
||||
var getPodcastEpisodeURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastEpisode" })';
|
||||
var getPodcastTitleURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastTitle" })';
|
||||
var getPodcastDescriptionURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetPodcastDescription" })';
|
||||
var publishPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "PublishPodcast" })';
|
||||
var addPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "CreatePodcast" })';
|
||||
var editPodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "EditPodcast" })';
|
||||
var deletePodcastURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "DeletePodcast" })';
|
||||
|
||||
var getCommentsURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetComments" })';
|
||||
var getCommentArticleURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "GetCommentArticle" })';
|
||||
var addCommentURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "CreateComment" })';
|
||||
var editCommentURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "EditComment" })';
|
||||
var deleteCommentURL = '@Url.SubRouteUrl("podcast", "Podcast.Action", new { action = "DeleteComment" })';
|
||||
</script>
|
||||
|
||||
@Styles.Render("~/Content/podcast")
|
||||
@Scripts.Render("~/bundles/podcast")
|
||||
|
||||
<div class="container">
|
||||
@if (!Model.Error)
|
||||
{
|
||||
@if (User.IsInRole("Admin"))
|
||||
if (User.IsInRole("Podcast"))
|
||||
{
|
||||
<div class="modal fade" id="editPodcast" tabindex="-1" role="dialog" aria-labelledby="editPodcastLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
@ -15,6 +39,12 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="edit_podcast_postid" id="edit_podcast_postid" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_podcast_episode"><h4>Episode Number</h4></label>
|
||||
<input class="form-control" name="edit_podcast_episode" id="edit_podcast_episode" placeholder="1" title="enter an episode number for the podcast" type="number" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_podcast_title"><h4>Title</h4></label>
|
||||
@ -50,7 +80,7 @@
|
||||
<div class="podcast-main" id="@Model.PodcastId">
|
||||
@Html.Partial("Podcast", Model)
|
||||
</div>
|
||||
@if (User.IsInRole("Admin"))
|
||||
if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
|
@ -11,6 +11,7 @@ namespace Teknik.Configuration
|
||||
public string Description { get; set; }
|
||||
public int PodcastsToLoad { get; set; }
|
||||
public int CommentsToLoad { get; set; }
|
||||
public string PodcastDirectory { get; set; }
|
||||
|
||||
public PodcastConfig()
|
||||
{
|
||||
@ -23,6 +24,7 @@ namespace Teknik.Configuration
|
||||
Description = string.Empty;
|
||||
PodcastsToLoad = 10;
|
||||
CommentsToLoad = 10;
|
||||
PodcastDirectory = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@ -341,7 +341,6 @@
|
||||
<Content Include="Global.asax" />
|
||||
<Content Include="Content\teknik.css" />
|
||||
<Content Include="Images\Icon.png" />
|
||||
<Content Include="App_Data\Config.json" />
|
||||
<Content Include="ConnectionStrings.config" />
|
||||
<Content Include="Areas\Blog\Views\web.config" />
|
||||
<Content Include="Areas\Blog\Views\Blog\Blog.cshtml" />
|
||||
@ -422,6 +421,7 @@
|
||||
<Content Include="Areas\Podcast\Views\Podcast\Comment.cshtml" />
|
||||
<Content Include="Areas\Podcast\Views\Podcast\Comments.cshtml" />
|
||||
<Content Include="Areas\Podcast\Views\Podcast\ViewPodcast.cshtml" />
|
||||
<Content Include="App_Data\Config.json" />
|
||||
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
|
||||
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
|
||||
<Content Include="Scripts\bootbox\bootbox.min.js" />
|
||||
|
Loading…
Reference in New Issue
Block a user