Пример #1
0
        public async Task<JsonResult> Upload(HttpPostedFileBase file)
        {
            var filename = file.FileName;
            if (file.ContentLength > 5*1024*1024) // 5MB
            {
                return new FormattedJsonResult(new {result = "error", message = "Cannot upload files larger than 5 MB"});
            }

            var buffer = new byte[file.ContentLength];
            file.InputStream.Read(buffer, 0, file.ContentLength);

            var dashboard = await GetDashboard(Request.Headers["accessCode"]);
            string uploadPath = Request.Headers["uploadPath"];
            var encryptor = new DashboardEncryptor(dashboard);

            var encryptedFile = encryptor.Encrypt(filename, uploadPath, buffer, file.ContentType);

            if (dashboard.DashboardItems.Any(f => f.Path == encryptedFile.Path && f.Name == encryptedFile.Name))
            {
                return new FormattedJsonResult(new { result = "error", message = "File with the same name already exists." });
            }

            dashboard.DashboardItems.Add(encryptedFile);

            await repository.Update(dashboard);
            return new FormattedJsonResult(new { result = "success" });
        }
Пример #2
0
        public async Task<FormattedJsonResult> New()
        {
            var encryptor = new DashboardEncryptor();
            await repository.Insert(encryptor.Dashboard);

            return new FormattedJsonResult(new { AccessCode = encryptor.PassCode });
        }
Пример #3
0
        public async Task<FormattedJsonResult> NewFolder(string name, string path)
        {
            path = path ?? string.Empty;
            var accessCode = Request.Headers["accessCode"];
            var dashboard = await repository.FindByAccessCode(accessCode);
            var encryptor = new DashboardEncryptor(dashboard);

            dashboard.DashboardItems.Add(encryptor.Encrypt(name, path));
            await this.repository.Update(dashboard);

            return new FormattedJsonResult(new { Result = "success" });
        }