mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
Skin repo index and viewskin pages
This commit is contained in:
parent
6e4b5e6de7
commit
aaebed46d5
6 changed files with 209 additions and 0 deletions
61
Project-Unite/Controllers/SkinsController.cs
Normal file
61
Project-Unite/Controllers/SkinsController.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Project_Unite.Models;
|
||||
|
||||
namespace Project_Unite.Controllers
|
||||
{
|
||||
public class SkinsController : Controller
|
||||
{
|
||||
// GET: Skins
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View(new ApplicationDbContext().Skins);
|
||||
}
|
||||
|
||||
public ActionResult ViewSkin(string id)
|
||||
{
|
||||
var db = new ApplicationDbContext();
|
||||
var skn = db.Skins.FirstOrDefault(x => x.Name == id);
|
||||
if (skn == null)
|
||||
return new HttpStatusCodeResult(404);
|
||||
return View(skn);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public ActionResult PostSkin()
|
||||
{
|
||||
var model = new CreateSkinViewModel();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult PostSkin(CreateSkinViewModel model)
|
||||
{
|
||||
if(!ModelState.IsValid)
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
var db = new ApplicationDbContext();
|
||||
var skin = new Skin();
|
||||
skin.Id = Guid.NewGuid().ToString();
|
||||
skin.Name = model.Title;
|
||||
skin.ShortDescription = model.ShortDescription;
|
||||
skin.PostedAt = DateTime.Now;
|
||||
skin.FullDescription = model.LongDescription;
|
||||
skin.UserId = User.Identity.GetUserId();
|
||||
skin.VersionId = "";
|
||||
skin.DownloadUrl = Path.Combine("~/Uploads", model.SkinFile.FileName);
|
||||
model.SkinFile.SaveAs(Path.Combine(Server.MapPath("~/Uploads"), model.SkinFile.FileName));
|
||||
db.Skins.Add(skin);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("ViewSkin", new { id = skin.Name });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -194,6 +194,7 @@ public static ApplicationDbContext Create()
|
|||
return new ApplicationDbContext();
|
||||
}
|
||||
|
||||
public DbSet<Skin> Skins { get; set; }
|
||||
public DbSet<Configuration> Configs { get; set; }
|
||||
public DbSet<ShiftoriumUpgrade> ShiftoriumUpgrades { get; set; }
|
||||
public DbSet<Notification> Notifications { get; set; }
|
||||
|
@ -212,6 +213,7 @@ public static ApplicationDbContext Create()
|
|||
public DbSet<ForumPollVote> ForumPollVotes { get; set; }
|
||||
public DbSet<ForumPost> ForumPosts { get; set; }
|
||||
public DbSet<Story> Stories { get; set; }
|
||||
public DbSet<View> Views { get; set; }
|
||||
}
|
||||
|
||||
public class UserPost
|
||||
|
|
72
Project-Unite/Models/Skin.cs
Normal file
72
Project-Unite/Models/Skin.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Project_Unite.Models
|
||||
{
|
||||
public class Skin
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ShortDescription { get; set; }
|
||||
public string FullDescription { get; set; }
|
||||
public string VersionId { get; set; }
|
||||
public string DownloadUrl { get; set; }
|
||||
public string ScreenshotUrl { get; set; }
|
||||
public DateTime PostedAt { get; set; }
|
||||
|
||||
public Like[] Likes
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ApplicationDbContext().Likes.Where(x => x.Topic == this.Id).Where(x => x.IsDislike == false).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public Like[] Dislikes
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ApplicationDbContext().Likes.Where(x => x.Topic == this.Id).Where(x => x.IsDislike == true).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public View[] Views
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ApplicationDbContext().Views.Where(x => x.ContentId == this.Id).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class View
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string ContentId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateSkinViewModel
|
||||
{
|
||||
[Required]
|
||||
[MaxLength(128, ErrorMessage = "Your title may not contain more than 128 characters.")]
|
||||
[MinLength(5, ErrorMessage = "You need to supply a valuable title.")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(500, ErrorMessage ="Your short description may not contain more than 500 characters.")]
|
||||
public string ShortDescription { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Html)]
|
||||
public string LongDescription { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Upload)]
|
||||
public HttpPostedFileBase SkinFile { get; set; }
|
||||
}
|
||||
}
|
|
@ -242,6 +242,7 @@
|
|||
<Compile Include="Controllers\ManageController.cs" />
|
||||
<Compile Include="Controllers\ModeratorController.cs" />
|
||||
<Compile Include="Controllers\ProfilesController.cs" />
|
||||
<Compile Include="Controllers\SkinsController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -420,6 +421,7 @@
|
|||
<Compile Include="Models\ManageViewModels.cs" />
|
||||
<Compile Include="Models\Notification.cs" />
|
||||
<Compile Include="Models\Role.cs" />
|
||||
<Compile Include="Models\Skin.cs" />
|
||||
<Compile Include="NotificationDaemon.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Startup.cs" />
|
||||
|
@ -520,6 +522,8 @@
|
|||
<Content Include="Views\Profiles\ViewProfile.cshtml" />
|
||||
<Content Include="Views\Profiles\_NewPost.cshtml" />
|
||||
<Content Include="Views\Admin\CreateUser.cshtml" />
|
||||
<Content Include="Views\Skins\ViewSkin.cshtml" />
|
||||
<Content Include="Views\Skins\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
|
47
Project-Unite/Views/Skins/Index.cshtml
Normal file
47
Project-Unite/Views/Skins/Index.cshtml
Normal file
|
@ -0,0 +1,47 @@
|
|||
@model IEnumerable<Project_Unite.Models.Skin>
|
||||
@{
|
||||
ViewBag.Title = "Skin Repository";
|
||||
}
|
||||
|
||||
<h2>ShiftOS Skin Repository</h2>
|
||||
|
||||
<p>ShiftOS skins allow you to shift the operating system to look like anything you want. You can make it look like other operating systems, you can give the UI a different feel, or you could just change the titlebar font. The sky and your disk space is the limit.</p>
|
||||
|
||||
<p>You can either create your own skin, or you can select from the many skins in the Skin Reposiory made by the community.</p>
|
||||
|
||||
<ul class="nav nav-pills">
|
||||
@if (Request.IsAuthenticated)
|
||||
{
|
||||
<li><a href="@Url.Action("PostSkin")"><span class="glyphicon glyphicon-plus"></span> Post a skin!</a></li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th style="max-width:128px;"></th>
|
||||
<th style="width:65%;">Skin</th>
|
||||
<th>Popularity</th>
|
||||
<th>Download</th>
|
||||
</tr>
|
||||
@foreach(var skin in Model)
|
||||
{
|
||||
<tr>
|
||||
<td><img src="@skin.ScreenshotUrl" style="width:auto;height:auto;" /></td>
|
||||
<td>
|
||||
@Html.ActionLink(skin.Name, "ViewSkin", "Skins", new { id = skin.Name }, null) <br/>
|
||||
<p>By @Html.UserLink(skin.UserId) on @skin.PostedAt</p>
|
||||
</td>
|
||||
<td>
|
||||
@* First we'll do the likes... *@
|
||||
<span class="glyphicon glyphicon-thumbs-up"></span> @skin.Likes.Length
|
||||
@* Now the dislikes. *@
|
||||
<span class="glyphicon glyphicon-thumbs-down"></span> @skin.Dislikes.Length
|
||||
@*Now the views.*@
|
||||
<span class="glyphicon glyphicon-eye-open"></span> @skin.Views.Length
|
||||
</td>
|
||||
<td>
|
||||
<a href="@skin.DownloadUrl" class="btn btn-default"><span class="glyphicon glyphicon-arrow-down"></span> Download this skin</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
23
Project-Unite/Views/Skins/ViewSkin.cshtml
Normal file
23
Project-Unite/Views/Skins/ViewSkin.cshtml
Normal file
|
@ -0,0 +1,23 @@
|
|||
@model Project_Unite.Models.Skin
|
||||
@{
|
||||
ViewBag.Title = Model.Name + " - Skin Repository";
|
||||
}
|
||||
|
||||
<h2>@Model.Name</h2>
|
||||
|
||||
<p>...a skin by @Html.UserLink(Model.UserId) on @Model.PostedAt</p>
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<a href="@Model.ScreenshotUrl"><img src="@Model.ScreenshotUrl" style="max-width:100%;width:auto;height:auto;" alt="Screenshot of @Model.Name. Click to show full-size image." /></a>
|
||||
|
||||
<ul class="nav nav-pills">
|
||||
<li><a href="@Model.DownloadUrl"><span class="glyphicon glyphicon-arrow-down"></span> Download</a></li>
|
||||
</ul>
|
||||
|
||||
<p>@Model.ShortDescription</p>
|
||||
|
||||
<p>@Html.Markdown(Model.FullDescription)</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in a new issue