public IActionResult Delete(EmployeeDeleteViewModel employee)
        {
            _unitOfWork.Employees.Delete(employee.Id);
            _unitOfWork.Complete();

            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
0
        public IActionResult Delete(EmployeeDeleteViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = _employeeRepository.GetEmployee(model.Id);

                if (employee != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        //string uploadsFolder = Path.Combine(_environment.WebRootPath, "imagesSupprimees"); //WebRootPath gives us the wwww folder
                        //string uniqueFileName = Guid.NewGuid().ToString() + "_" + employee.PhotoPath;
                        //string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                        //using (var fileStream = new FileStream(filePath, FileMode.Create))
                        //{
                        //    System.IO.File.Copy(employee.PhotoPath, filePath2);
                        //}

                        string filePath = Path.Combine(_environment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    _employeeRepository.Delete(employee.Id);
                    return(RedirectToAction("index"));
                }
            }
            return(View());
        }
Exemple #3
0
        //* part delete - step 3 - next step below with HttpPost in HomeController.cs
        public ViewResult Delete(int id)
        {
            Employee employee = _employeeRepositry.GetEmployee(id);
            EmployeeDeleteViewModel employeeDeleteViewModel = new EmployeeDeleteViewModel
            {
                Id = employee.Id,
            };

            return(View(employeeDeleteViewModel));
        }
Exemple #4
0
        public IActionResult Delete(EmployeeDeleteViewModel model) //* part delete - step3  - update Employee
        {
            if (ModelState.IsValid)                                //* Part 42 - step2 model validation - next step in Create.cshtml
            {
                Employee employee = _employeeRepositry.GetEmployee(model.Id);

                _employeeRepositry.Delete(employee.Id);
                return(RedirectToAction("List")); //* Part 56 - need to comment this line
            }

            return(View());
        }
Exemple #5
0
        public IActionResult DeleteEmployeeByEmail([FromBody] EmployeeDeleteViewModel employeeDelete)
        {
            try
            {
                employeeService.DeleteEmployee(employeeDelete.Email);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest("Can't delete employee with email " + employeeDelete.Email));
            }
        }
        public async Task <IActionResult> Delete(EmployeeDeleteViewModel model)
        {
            var webRootPath = _hostingEnvironment.WebRootPath;

            var imgToDelPath = Path.GetFullPath(webRootPath + model.ImageUrl);

            if (System.IO.File.Exists(imgToDelPath))
            {
                System.IO.File.Delete(imgToDelPath);
            }
            await _employeeService.Delete(model.Id);

            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult Delete(int id)
 {
     var employee = _employeeService.GetById(id);
     if(employee == null)
     {
         return NotFound();
     }
     var model = new EmployeeDeleteViewModel()
     {
         Id = employee.Id,
         FullName = employee.FullName
     };
     return View();
 }
Exemple #8
0
        public IActionResult Delete(int id)
        {
            Employee employee = _employeeRepository.GetEmployee(id);

            EmployeeDeleteViewModel employeeDeleteViewModel = new EmployeeDeleteViewModel
            {
                Id                = employee.Id,
                Name              = employee.Name,
                Email             = employee.Email,
                Department        = employee.Department,
                ExistingPhotoPath = employee.PhotoPath
            };

            return(View(employeeDeleteViewModel));
        }
        public async Task <IActionResult> Delete(EmployeeDeleteViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = _employeeService.GetById(model.Id);
                if (employee == null)
                {
                    return(NotFound());
                }
                await _employeeService.DeleteAsync(model.Id);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        public IActionResult Delete(int id)
        {
            var employee = _employeeService.GetByID(id);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeDeleteViewModel()
            {
                ID       = employee.ID,
                FullName = employee.FullName
            };

            return(View(model));
        }
Exemple #11
0
        public IActionResult Delete(int ID)
        {
            var employee = _employeeService.GetEmployeebyId(ID);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeDeleteViewModel()
            {
                ID       = employee.ID,
                FullName = employee.FirstName + (string.IsNullOrEmpty(employee.MiddleName) ? " " : " " + employee.MiddleName[0] + ".").ToUpper() + employee.LastName
            };

            return(View(model));
        }
Exemple #12
0
        public IActionResult Delete(int id)
        {
            var employee = _employeeService.GetById(id);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeDeleteViewModel()    //Pass in an instance of the DeleteViewModel to the View
            {
                Id       = employee.Id,
                FullName = employee.FullName
            };

            return(View(model));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var employee = await _employeeService.GetById(id);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeDeleteViewModel()
            {
                Id       = employee.Id,
                FullName = employee.FullName,
                ImageUrl = employee.ImageUrl
            };

            return(View(model));
        }
        public IActionResult Delete(int id)
        {
            var emp = _employeeservices.GetById(id);

            if (emp == null)
            {
                return(NotFound());
            }
            EmployeeDeleteViewModel model = new EmployeeDeleteViewModel()
            {
                Id       = emp.Id,
                FullName = emp.FullName
            };


            return(View(model));
        }
        public IActionResult Delete(int id)
        {
            var employee = _unitOfWork.Employees.Get(id);

            if (employee == null)
            {
                return(NotFound());
            }

            var viewModel = new EmployeeDeleteViewModel()
            {
                Id        = employee.Id,
                Firstname = employee.FirstName,
                Lastname  = employee.LastName
            };

            return(View(viewModel));
        }
        public ActionResult Delete(EmployeeDeleteViewModel model)
        {
            Employee findPreviousEmp = _empRepo.GetEmployee(model.ID);

            if (findPreviousEmp != null)
            {
                if (findPreviousEmp.PhotoPath != null)
                {
                    //After Deleting the Image from the Database
                    _empRepo.Delete(findPreviousEmp.ID);
                    //Delete the Image form the Server
                    var path = Path.Combine(_webHostEnvironment.WebRootPath, "images", findPreviousEmp.PhotoPath);
                    System.IO.File.Delete(path);
                    return(RedirectToAction("Programming", "Welcome"));
                }
            }
            return(View("EmployeeNotFound", model.ID));
        }
Exemple #17
0
        public IActionResult Delete(int id)
        {
            var employee = _employeeService.GetById(id);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeDeleteViewModel()
            {
                Id         = employee.Id,
                FirstName  = employee.FirstName,
                MiddleName = employee.MiddleName,
                LastName   = employee.LastName
            };

            return(View());
        }
        public async Task <IActionResult> Delete(int id)
        {
            var employee = await _unitOfWork.EmployeeRepository.GetByIdAsync(id);

            if (employee == null)
            {
                return(NotFound());
            }

            var model = new EmployeeDeleteViewModel()
            {
                Id        = employee.Id,
                FirstName = employee.FirstName,
                LastName  = employee.LastName
            };

            return(View(model));
        }
Exemple #19
0
        // GET: Employees/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ApplicationUser applicationUser = db.Users.Find(id);

            if (applicationUser == null)
            {
                return(HttpNotFound());
            }
            //ビューモデルにデータを詰め替える
            EmployeeDeleteViewModel employee = new EmployeeDeleteViewModel
            {
                Id           = applicationUser.Id,
                Email        = applicationUser.Email,
                EmployeeName = applicationUser.EmployeeName,
                CreatedAt    = applicationUser.CreatedAt,
                UpdatedAt    = applicationUser.UpdatedAt
            };

            //Roleを確認し、設定する
            if (employee.Role == "Admin")
            {
                employee.Role = "管理者";
            }
            else if (employee.Role == "Manager")
            {
                employee.Role = "部長";
            }
            else if (employee.Role == "Chief")
            {
                employee.Role = "課長";
            }
            else
            {
                employee.Role = "一般";
            }
            return(View(employee));
        }
        public ActionResult Delete(int id)
        {
            Employee employee = _empRepo.GetEmployee(id);

            if (employee != null)
            {
                EmployeeDeleteViewModel model = new EmployeeDeleteViewModel()
                {
                    ID            = employee.ID,
                    Name          = employee.Name,
                    Email         = employee.Email,
                    Department    = employee.Department,
                    PhotoPath     = employee.PhotoPath,
                    ExistingPhoto = employee.PhotoPath
                };

                return(View(model));
            }


            return(View("EmployeeNotFound", id));
        }
        public async Task <IActionResult> Delete(EmployeeDeleteViewModel model)
        {
            _unitOfWork.EmployeeRepository.Remove(model.Id);
            var employee = await _unitOfWork.EmployeeRepository.GetByIdAsync(model.Id);

            if (await _unitOfWork.SaveAsync())
            {
                Alert("Successfully deleted!", NotificationType.success);

                var filePath = Path.Combine(_hostingEnvironment.WebRootPath,
                                            employee.ImageUrl.Substring(1, employee.ImageUrl.Length - 1));
                if (!System.IO.File.Exists(filePath))
                {
                    return(NotFound());
                }

                GC.Collect();
                GC.WaitForPendingFinalizers();
                System.IO.File.Delete(filePath);
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Delete(EmployeeDeleteViewModel model)
        {
            await _employeeService.Delete(model.Id);

            return(RedirectToAction(nameof(Index)));
        }
 public IActionResult Delete(EmployeeDeleteViewModel model)
 {
     _employeeService.Delete(model.Id);
     return(RedirectToAction(nameof(Index)));
 }