public IActionResult Edit(UploadEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Upload upload = _uploadRepository.GetUpload(model.Id);

                upload.Name        = model.Name;
                upload.Description = model.Description;
                //upload.Department = model.Department;

                if (model.Project != null)
                {
                    if (model.ExistingUploadPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                       "projects", model.ExistingUploadPath);
                        System.IO.File.Delete(filePath);
                    }

                    upload.UploadPath = ProcessUploadedFile(model);
                }


                _uploadRepository.Update(upload);

                return(RedirectToAction("index"));
            }

            return(View(model));
        }
        public ViewResult Edit(int id)
        {
            Upload upload = _uploadRepository.GetUpload(id);
            UploadEditViewModel uploadEditViewModel = new UploadEditViewModel
            {
                Id          = upload.Id,
                Name        = upload.Name,
                Description = upload.Description,
                //Department = upload.Department,
                ExistingUploadPath = upload.UploadPath
            };

            return(View(uploadEditViewModel));
        }
        public IActionResult Delete(UploadEditViewModel model)
        {
            Upload upload = _uploadRepository.GetUpload(model.Id);

            if (upload != null)
            {
                _uploadRepository.Delete(upload.Id);

                if (upload.UploadPath != null)
                {
                    string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                   "projects", upload.UploadPath);
                    System.IO.File.Delete(filePath);
                }
            }
            return(RedirectToAction("index"));
        }
        public IActionResult Download(UploadEditViewModel model)
        {
            Upload upload = _uploadRepository.GetUpload(model.Id);

            if (upload.UploadPath == null)
            {
                return(View("NotFound"));
            }


            if (upload.UploadPath != null)
            {
                string fileName = Path.GetFileName(upload.UploadPath);
                string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                               "projects", upload.UploadPath);
                byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
                return(File(fileBytes, "application/force-download", fileName));
            }

            return(View(model));
        }