// GET: Employees/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Employee employee = db.Employees.Find(id); if (employee == null) { return(HttpNotFound()); } var model = new EmployeeEditVM { SelectedTeamId = employee.MemberOf?.Id ?? 0, Id = employee.Id, FirstName = employee.FirstName, LastName = employee.LastName, EmployeeNumber = employee.EmployeeNumber, AvailableTeams = new SelectList(db.Teams.ToList(), "Id", "Name") }; return(View(model)); }
public async Task <IActionResult> Edit(EmployeeEditVM model) { if (!ModelState.IsValid) { ViewData["Genders"] = CreateGendersDropDownList(); ViewData["Positions"] = CreatePositionsDropDownList(); return(View(model)); } Employee employeeToEdit = await context.Employees.FirstOrDefaultAsync(e => e.Id == model.Id); if (employeeToEdit == null) { return(NotFound()); } employeeToEdit.Name = model.Name; employeeToEdit.Patronymic = model.Patronymic; employeeToEdit.Surname = model.Surname; employeeToEdit.Gender = model.Gender; employeeToEdit.PositionId = model.Position; employeeToEdit.Birthdate = model.Birthdate; employeeToEdit.Phone = model.Phone; await context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Create(EmployeeEditVM model) { if (ModelState.IsValid) { var currentTeam = db.Teams.Find(model.SelectedTeamId); var alreadyExists = currentTeam.Employees.Any(x => x.EmployeeNumber == model.EmployeeNumber); if (alreadyExists) { ModelState.AddModelError("EmployeeNumber", "Person Already Exists with that Employee Number on the Team."); model.AvailableTeams = new SelectList(db.Teams.ToList(), "Id", "Name"); return(View(model)); } var employee = new Employee { FirstName = model.FirstName, LastName = model.LastName, EmployeeNumber = model.EmployeeNumber, MemberOf = currentTeam }; db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } model.AvailableTeams = new SelectList(db.Teams.ToList(), "Id", "Name"); return(View(model)); }
public ViewResult Edit(int id) { Employee employee = _employeeRepository.GetEmployee(id); EmployeeEditVM employeeEditVM = EmployeeEditVM.CreateViewModel(employee); return(View(employeeEditVM)); }
public IActionResult Edit(EmployeeEditVM model) { if (ModelState.IsValid) { var objFromDb = _employeeRepository.GetEmployee(model.Id); objFromDb.Department = model.Department; objFromDb.Email = model.Email; objFromDb.Name = model.Name; if (model.Photos != null) { if (model.ExistingPhotoPath != null) { string filePath = Path.Combine (String.Format($"{hostingEnvironment.WebRootPath}/Images/{model.ExistingPhotoPath}")); System.IO.File.Delete(filePath); } objFromDb.PhotoPath = ProcessUploadedFile(model); } _employeeRepository.Update(objFromDb); return(RedirectToAction(nameof(Details), new { id = objFromDb.Id })); } return(View()); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Employee employee = await context.Employees .Include(p => p.Position) .FirstOrDefaultAsync(e => e.Id == id); if (employee == null) { return(NotFound()); } EmployeeEditVM model = new EmployeeEditVM { Id = employee.Id, Name = employee.Name, Patronymic = employee.Patronymic, Surname = employee.Surname, Gender = employee.Gender, Position = employee.Position.Id, Birthdate = employee.Birthdate, Phone = employee.Phone }; ViewData["Genders"] = CreateGendersDropDownList(); ViewData["Positions"] = CreatePositionsDropDownList(); return(View(model)); }
// GET: Employees/Create public ActionResult Create() { var model = new EmployeeEditVM { SelectedTeamId = 0, AvailableTeams = new SelectList(db.Teams.ToList(), "Id", "Name") }; return(View(model)); }
// GET: Employee/Edit/5 public ActionResult Edit(int id) { Employee employee = _employeeService.GetEmployeeById(id); if (employee == null) { return(NotFound()); } EmployeeEditVM model = _mapper.Map <EmployeeEditVM>(employee); return(View(model)); }
public ActionResult Edit(int id) { Employee emp = _employeeRepository.GetEmployee(id); EmployeeEditVM employeeEditVM = new EmployeeEditVM { Id = id, Name = emp.Name, Email = emp.Email, Department = emp.Department, Existingphotopath = emp.PhotoPath }; return(View(employeeEditVM)); }
public IActionResult Edit(int id) { var objFromDb = _employeeRepository.GetEmployee(id); var editObject = new EmployeeEditVM { Department = objFromDb.Department, Email = objFromDb.Email, Id = objFromDb.Id, Name = objFromDb.Name, ExistingPhotoPath = objFromDb.PhotoPath }; return(View(editObject)); }
public ActionResult Edit(EmployeeEditVM model) { if (ModelState.IsValid) { var employee = db.Employees.Find(model.Id); employee.FirstName = model.FirstName; employee.LastName = model.LastName; employee.EmployeeNumber = model.EmployeeNumber; employee.MemberOf = db.Teams.Find(model.SelectedTeamId); db.SaveChanges(); return(RedirectToAction("Index")); } model.AvailableTeams = new SelectList(db.Teams.ToList(), "Id", "Name"); return(View(model)); }
public ActionResult Edit(int id, EmployeeEditVM model) { ModelState.Remove("Name"); if (!ModelState.IsValid) { return(View(model)); } Employee newEmployee = _mapper.Map <Employee>(model); Employee employee = _employeeService.GetEmployeeById(id); employee.Email = newEmployee.Email; employee.DepartmentId = newEmployee.DepartmentId; employee.Photo = newEmployee.Photo ?? employee.Photo; employee.Resume = newEmployee.Resume ?? employee.Resume; _employeeService.Update(employee); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(EmployeeEditVM viewModel) { if (ModelState.IsValid) { Employee employee = _employeeRepository.GetEmployee(viewModel.Id); employee.Name = viewModel.Name; employee.Email = viewModel.Email; employee.Department = viewModel.Department; if (viewModel.Photo != null) { if (viewModel.ExistingPhotoPath != null) { DeletePhoto(viewModel.ExistingPhotoPath); } employee.PhotoPath = ProcessUploadedPhoto(viewModel); } _employeeRepository.Update(employee); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Edit(EmployeeEditVM model) { if (ModelState.IsValid) // its mean no validation Error { Employee emp = _employeeRepository.GetEmployee(model.Id); emp.Name = model.Name; emp.Email = model.Email; emp.Department = model.Department; if (model.Photo != null) { if (model.Existingphotopath != null) { string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.Existingphotopath); System.IO.File.Delete(filePath); } emp.PhotoPath = ProcessUploadFile(model); } _employeeRepository.Update(emp); return(RedirectToAction("Index")); } return(View()); }