// GET: Cities/Delete/5 public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } var employee = await db.Employees .Include(c => c.City).Include(d => d.Designation) .FirstOrDefaultAsync(m => m.EmployeeId == id); EmployeeEditViewModels employeeEditViewModels = new EmployeeEditViewModels { Id = employee.EmployeeId, Name = employee.Name, Email = employee.Email, Contact = employee.Contact, Address = employee.Address, ExistingPhotoPath = employee.Image, CityId = employee.CityId, Status = employee.Status }; ViewBag.Title = "Delete"; if (employee == null) { return(NotFound()); } ViewBag.Title = "Delete"; ViewData["CityId"] = new SelectList(db.Cities, "CityId", "Name", employee.CityId); ViewData["DesignationId"] = new SelectList(db.Designations, "DesignationId", "Name", employee.DesignationId); return(View("Edit", employeeEditViewModels)); }
// GET: Cities/Details/5 //// GET: Cities/Create //public IActionResult Create() //{ // ViewData["CityId"] = new SelectList(db.Cities, "CityId", "Name"); // ViewData["DesignationId"] = new SelectList(db.Designations, "DesignationId", "Name"); // ViewBag.Title = "Create"; // return View(); //} //// POST: Cities/Create //// To protect from overposting attacks, enable the specific properties you want to bind to, for //// more details, see http://go.microsoft.com/fwlink/?LinkId=317598. //[HttpPost] //[ValidateAntiForgeryToken] //public async Task<IActionResult> Create( EmployeeCreateViewModels employee) //{ // if (ModelState.IsValid) // { // string uniqueFileName = ProcessUploadFile(employee); // Employee newEmployee = new Employee // { // Name = employee.Name, // Email = employee.Email, // Contact = employee.Contact, // Address = employee.Address, // DesignationId = employee.DesignationId, // CityId = employee.CityId, // Image = uniqueFileName, // Status = employee.Status // }; // db.Add(newEmployee); // await db.SaveChangesAsync(); // TempData["Message"] = "Data Added Successfully"; // TempData["Status"] = "1"; // return RedirectToAction(nameof(Index)); // } // ViewData["CityId"] = new SelectList(db.Cities, "CityId", "Name", employee.CityId); // ViewData["DesignationId"] = new SelectList(db.Designations, "DesignationId", "Name", employee.DesignationId); // return View(employee); //} // GET: Cities/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var employee = await db.Employees.FindAsync(id); EmployeeEditViewModels employeeEdit = new EmployeeEditViewModels { Name = employee.Name, Email = employee.Email, Contact = employee.Contact, Address = employee.Address, DesignationId = employee.DesignationId, CityId = employee.CityId, ExistingPhotoPath = employee.Image, Status = employee.Status }; if (employee == null) { return(NotFound()); } ViewData["CityId"] = new SelectList(db.Cities, "CityId", "Name", employee.CityId); ViewData["DesignationId"] = new SelectList(db.Designations, "DesignationId", "Name", employee.DesignationId); return(View("Edit", employeeEdit)); }
public ViewResult Edit(int Id) { Employee employee = _employeeRepository.GetEmployeeById(Id); EmployeeEditViewModels employeeEditViewModels = new EmployeeEditViewModels { Id = employee.Id, Name = employee.Name, Address = employee.Address, Department = employee.Department, ExistingPhotoPath = employee.PhotoPath, Salary = employee.Salary }; return(View("../Home/Edit", employeeEditViewModels)); }
public async Task <IActionResult> Edit(EmployeeEditViewModels employee) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadFile(employee); Employee updateEmployee = await db.Employees.FindAsync(employee.Id); updateEmployee.Name = employee.Name; updateEmployee.Email = employee.Email; updateEmployee.Contact = employee.Contact; updateEmployee.Address = employee.Address; updateEmployee.CityId = employee.CityId; updateEmployee.Status = employee.Status; if (employee.Image != null) { if (employee.ExistingPhotoPath != null) { string filePath = Path.Combine(env.WebRootPath + "images" + employee.ExistingPhotoPath); System.IO.File.Delete(filePath); } updateEmployee.Image = ProcessUploadFile(employee); } if (updateEmployee == null) { return(NotFound()); } db.Update(updateEmployee); await db.SaveChangesAsync(); TempData["Message"] = "Data Updated Successfully"; TempData["Status"] = "2"; return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(db.Cities, "CityId", "Name", employee.CityId); ViewData["DesignationId"] = new SelectList(db.Designations, "DesignationId", "Name", employee.DesignationId); return(View(employee)); }
public IActionResult Edit(EmployeeEditViewModels model) { if (ModelState.IsValid) { Employee employee = _employeeRepository.GetEmployeeById(model.Id); employee.Name = model.Name; employee.Address = model.Address; employee.Department = model.Department; employee.Salary = model.Salary; employee.PhotoPath = model.ExistingPhotoPath; if (model.Photo != null) { employee.PhotoPath = NewFile(model); if (model.ExistingPhotoPath != null) { string existingFilePath = Path.Combine(Path.Combine(_hostingEnvironment.WebRootPath, "images"), model.ExistingPhotoPath); System.IO.File.Delete(existingFilePath); } } _employeeRepository.Update(employee); return(RedirectToAction("view", "home", new { id = model.Id })); } return(View()); }