private string PrograsUplodFile(EmployeeCreatViewModel model)
        {
            string uniqfilename = null;

            if (model.Photo != null)
            {
                string uplodsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                uniqfilename = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filepath = Path.Combine(uplodsFolder, uniqfilename);
                model.Photo.CopyTo(new FileStream(filepath, FileMode.Create));
            }

            return(uniqfilename);
        }
        public IActionResult Delete(int id)
        {
            EmployeeCreatViewModel models = new EmployeeCreatViewModel();
            Employees model = _employeeRepostiory.getEmployeeDetails(id);

            if (model.PhotoPath != null)
            {
                string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.PhotoPath);
                System.IO.File.Delete(filePath);

                model.PhotoPath = ProcessUploadedFile(models);
            }
            _employeeRepostiory.Delete(id);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        private string ProcessUploadedFile(EmployeeCreatViewModel model)
        {
            string uniqueFileName = null;

            if (model.Photo != null)
            {
                string UploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "image");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(UploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.Photo.CopyTo(fileStream);
                }
            }

            return(uniqueFileName);
        }
 public IActionResult Create(EmployeeCreatViewModel model)
 {
     if (ModelState.IsValid)
     {
         string   uniqfilename = PrograsUplodFile(model);
         Employee newEmployee  = new Employee
         {
             Name       = model.Name,
             Email      = model.Email,
             Department = model.Department,
             PhotoPath  = uniqfilename
         };
         _empoyleeRepository.Add(newEmployee);
         return(RedirectToAction("Details", new { id = newEmployee.Id }));
     }
     return(View());
 }
 public IActionResult Create(EmployeeCreatViewModel model)
 {
     if (ModelState.IsValid)
     {
         string    uniqueFileName = ProcessUploadedFile(model);
         Employees newEmp         = new Employees
         {
             Name       = model.Name,
             Email      = model.Email,
             Department = model.Department,
             PhotoPath  = uniqueFileName
         };
         _employeeRepostiory.Add(newEmp);
         return(RedirectToAction("details", new { id = newEmp.Id }));
     }
     return(View());
 }