blob: 0b6b7321dec974b40f3aaf2f48eaef63c190568b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 });
}
}
}
|