|
@@ -203,17 +203,7 @@ namespace Teknik.Areas.Upload.Controllers
|
203
|
203
|
// Check Expiration
|
204
|
204
|
if (UploadHelper.CheckExpiration(upload))
|
205
|
205
|
{
|
206
|
|
- string subDir = upload.FileName[0].ToString();
|
207
|
|
- string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
208
|
|
- // Delete from the DB
|
209
|
|
- _dbContext.Uploads.Remove(upload);
|
210
|
|
- _dbContext.SaveChanges();
|
211
|
|
-
|
212
|
|
- // Delete the File
|
213
|
|
- if (System.IO.File.Exists(filePath))
|
214
|
|
- {
|
215
|
|
- System.IO.File.Delete(filePath);
|
216
|
|
- }
|
|
206
|
+ DeleteFile(upload);
|
217
|
207
|
return new StatusCodeResult(StatusCodes.Status404NotFound);
|
218
|
208
|
}
|
219
|
209
|
|
|
@@ -432,17 +422,7 @@ namespace Teknik.Areas.Upload.Controllers
|
432
|
422
|
// Check Expiration
|
433
|
423
|
if (UploadHelper.CheckExpiration(upload))
|
434
|
424
|
{
|
435
|
|
- string delDir = upload.FileName[0].ToString();
|
436
|
|
- string delPath = Path.Combine(_config.UploadConfig.UploadDirectory, delDir, upload.FileName);
|
437
|
|
- // Delete from the DB
|
438
|
|
- _dbContext.Uploads.Remove(upload);
|
439
|
|
- _dbContext.SaveChanges();
|
440
|
|
-
|
441
|
|
- // Delete the File
|
442
|
|
- if (System.IO.File.Exists(delPath))
|
443
|
|
- {
|
444
|
|
- System.IO.File.Delete(delPath);
|
445
|
|
- }
|
|
425
|
+ DeleteFile(upload);
|
446
|
426
|
return Json(new { error = new { message = "File Does Not Exist" } });
|
447
|
427
|
}
|
448
|
428
|
|
|
@@ -500,17 +480,7 @@ namespace Teknik.Areas.Upload.Controllers
|
500
|
480
|
model.File = file;
|
501
|
481
|
if (!string.IsNullOrEmpty(upload.DeleteKey) && upload.DeleteKey == key)
|
502
|
482
|
{
|
503
|
|
- string subDir = upload.FileName[0].ToString();
|
504
|
|
- string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
505
|
|
- // Delete from the DB
|
506
|
|
- _dbContext.Uploads.Remove(upload);
|
507
|
|
- _dbContext.SaveChanges();
|
508
|
|
-
|
509
|
|
- // Delete the File
|
510
|
|
- if (System.IO.File.Exists(filePath))
|
511
|
|
- {
|
512
|
|
- System.IO.File.Delete(filePath);
|
513
|
|
- }
|
|
483
|
+ DeleteFile(upload);
|
514
|
484
|
model.Deleted = true;
|
515
|
485
|
}
|
516
|
486
|
else
|
|
@@ -550,23 +520,28 @@ namespace Teknik.Areas.Upload.Controllers
|
550
|
520
|
{
|
551
|
521
|
if (foundUpload.User.Username == User.Identity.Name)
|
552
|
522
|
{
|
553
|
|
- string subDir = foundUpload.FileName[0].ToString();
|
554
|
|
- string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, foundUpload.FileName);
|
555
|
|
- // Delete from the DB
|
556
|
|
- _dbContext.Uploads.Remove(foundUpload);
|
557
|
|
- _dbContext.SaveChanges();
|
558
|
|
-
|
559
|
|
- // Delete the File
|
560
|
|
- if (System.IO.File.Exists(filePath))
|
561
|
|
- {
|
562
|
|
- System.IO.File.Delete(filePath);
|
563
|
|
- }
|
564
|
|
-
|
|
523
|
+ DeleteFile(foundUpload);
|
565
|
524
|
return Json(new { result = true });
|
566
|
525
|
}
|
567
|
526
|
return Json(new { error = new { message = "You do not have permission to edit this Paste" } });
|
568
|
527
|
}
|
569
|
|
- return Json(new { error = new { message = "This Paste does not exist" } });
|
|
528
|
+ return Json(new { error = new { message = "This Upload does not exist" } });
|
|
529
|
+ }
|
|
530
|
+
|
|
531
|
+ private void DeleteFile(Models.Upload upload)
|
|
532
|
+ {
|
|
533
|
+ string subDir = upload.FileName[0].ToString();
|
|
534
|
+ string filePath = Path.Combine(_config.UploadConfig.UploadDirectory, subDir, upload.FileName);
|
|
535
|
+
|
|
536
|
+ // Delete the File
|
|
537
|
+ if (System.IO.File.Exists(filePath))
|
|
538
|
+ {
|
|
539
|
+ System.IO.File.Delete(filePath);
|
|
540
|
+ }
|
|
541
|
+
|
|
542
|
+ // Delete from the DB
|
|
543
|
+ _dbContext.Uploads.Remove(upload);
|
|
544
|
+ _dbContext.SaveChanges();
|
570
|
545
|
}
|
571
|
546
|
}
|
572
|
547
|
}
|