using System Web using System Web Mvc using Microsoft AspNet Identity

 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using YourDrive.Models;
namespace YourDrive.Controllers
{
[Authorize]
public class DriveController : Controller
{
DriveRepository repository;
DriveRepository Repository
{
get
{
return repository ??
(repository = new DriveRepository(User.Identity.GetUserId()));
}
set
{
repository = value;
}
}
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public JsonResult AddFile(string name, string catalogPath, HttpPostedFileBase file)
{
if (name == null || catalogPath == null || file == null) return Json(false);
byte[] data = new byte[file.ContentLength];
file.InputStream.Read(data, 0, data.Length);
return Json(Repository.AddFile(name, catalogPath, data));
}
[HttpPost]
public JsonResult DeleteFile(string name, string catalogPath)
{
return Json(Repository.DeleteFile(name, catalogPath));
}
[HttpPost]
public JsonResult RenameFile(string name, string catalogPath, string newName)
{
return Json(Repository.RenameFile(name, catalogPath, newName));
}
[HttpGet]
public FileContentResult DownloadFile(string name, string catalogPath)
{
return File(Repository.GetFile(name, catalogPath), "application/octet-stream");
}
[HttpPost]
public JsonResult GetElements(string catalogPath)
{
return Json(Repository.GetElementsByCatalogPath(catalogPath));
}
[HttpPost]
public JsonResult AddCatalog(string name, string catalogPath)
{
return Json(Repository.AddCatalog(name, catalogPath));
}
[HttpPost]
public JsonResult DeleteCatalog(string name, string catalogPath)
{
return Json(Repository.DeleteCatalog(name, catalogPath));
}
[HttpPost]
public JsonResult RenameCatalog(string name, string catalogPath, string newName)
{
return Json(Repository.RenameCatalog(name, catalogPath, newName));
}
[HttpPost]
public JsonResult SwitchAccessMode(string catalogPath)
{
return Json(Repository.SwitchAccessMode(catalogPath));
}
[HttpPost]
public JsonResult GetChangeToken(string catalogPath)
{
return Json(Repository.GetChangeToken(catalogPath));
}
}
}