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));
}
}
}