Exemple #1
0
        public ActionResult Index(FormCollection form, HttpPostedFileBase file)
        {
            //HttpPostedFileBase file = Request.Files[0 ];


            UploadsViewModel uploadsViewModel = Session["Uploads"] != null ? Session["Uploads"] as UploadsViewModel : new UploadsViewModel();


            uploadsViewModel.ID = long.Parse(form["id"]);

            File upload = new File();

            upload.FileID   = uploadsViewModel.Uploads.Count + 1;
            upload.FileName = file.FileName;
            upload.FilePath = "~/TestFolder/" + file.FileName;



            //if (file.ContentLength < 4048576)    we can check file size before saving if we need to restrict file size or we can check it on client side as well
            //{

            if (file != null)
            {
                file.SaveAs(Server.MapPath(upload.FilePath));
                uploadsViewModel.Uploads.Add(upload);
                Session["Uploads"] = uploadsViewModel;
            }

            // Save FileName and Path to Database according to your business requirements

            //}


            return(PartialView("~/Views/Shared/_UploadsPartial.cshtml", uploadsViewModel.Uploads));
        }
Exemple #2
0
        public ActionResult DeleteFile(long id)
        {
            /* Use input Id to delete the record from db logically by setting IsDeleted bit in your table or delete it physically whatever is suitable for you
             * for DEMO purpose i am stroing it in Session */

            UploadsViewModel viewModel = Session["Uploads"] as UploadsViewModel;

            File file = viewModel.Uploads.Single(x => x.FileID == id);

            try
            {
                System.IO.File.Delete(Server.MapPath(file.FilePath));
                viewModel.Uploads.Remove(file);
            }

            catch (Exception)
            {
                return(PartialView("~/Views/Shared/_UploadsPartial.cshtml", viewModel.Uploads));
            }



            return(PartialView("~/Views/Shared/_UploadsPartial.cshtml", viewModel.Uploads));
        }
Exemple #3
0
 public IActionResult Create(UploadsViewModel model)
 {
     return(View());
 }
Exemple #4
0
        public ActionResult GetFiles(long Id)
        {
            UploadsViewModel viewModel = Session["Uploads"] as UploadsViewModel;

            return(PartialView("~/Views/Shared/_UploadsPartial.cshtml", (viewModel == null ? new UploadsViewModel().Uploads : viewModel.Uploads)));
        }
 public TransfersViewModel(DownloadsViewModel downloadsVM, UploadsViewModel uploadsVM)
 {
     DownloadsVM = downloadsVM;
     UploadsVM   = uploadsVM;
 }
Exemple #6
0
        public async Task <IActionResult> Index()
        {
            var vm = new UploadsViewModel();

            return(View(vm));
        }