Exemplo n.º 1
0
        public ViewResult Edit(int id)
        {
            var       emp      = empRepo.GetEmpById(id);
            EmpEditVM emp4Edit = new EmpEditVM
            {
                Id            = emp.Id,
                Name          = emp.Name,
                Department    = emp.Department,
                Email         = emp.Email,
                ExistingPhoto = emp.PhotoName
            };

            return(View(emp4Edit));
        }
Exemplo n.º 2
0
        private string SetupImg(EmpEditVM EmpObj)
        {
            string ImgUniqeName = "";

            if (EmpObj.Photo != null)
            {
                string fileRootPath = Path.Combine(HostEnv.WebRootPath, "img");
                ImgUniqeName = Guid.NewGuid().ToString() + "_" + EmpObj.Photo.FileName;
                string filePath = Path.Combine(fileRootPath, ImgUniqeName);
                using (FileStream PhotoStream = new FileStream(filePath, FileMode.Create))
                {
                    EmpObj.Photo.CopyTo(PhotoStream);
                }
            }

            return(ImgUniqeName);
        }
Exemplo n.º 3
0
 public IActionResult Edit(EmpEditVM EmpObj)
 {
     if (ModelState.IsValid)
     {
         var EditedEmp = empRepo.GetEmpById(EmpObj.Id);
         EditedEmp.Name       = EmpObj.Name;
         EditedEmp.Email      = EmpObj.Email;
         EditedEmp.Department = EmpObj.Department;
         if (EmpObj.Photo != null)
         {
             DelteItemFromRootPath(EmpObj.ExistingPhoto);
             EditedEmp.PhotoName = SetupImg(EmpObj);;
         }
         empRepo.Update(EditedEmp);
         return(RedirectToAction("Details", new { id = EditedEmp.Id }));
     }
     return(View("Views/Home/View.cshtml"));
 }