// GET: Employees/Edit/5
        public IActionResult Edit(Guid id)
        {
            if (id == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", id.ToString()));
            }

            var employee = _employeeService.GetByid(id);

            if (employee == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", id.ToString()));
            }

            var employeeEdit = new EmployeeEditVm();

            employeeEdit.Id                = employee.Id;
            employeeEdit.FirstName         = employee.FirstName;
            employeeEdit.LastName          = employee.LastName;
            employeeEdit.ExistingPhotoPath = employee.PhotoPath;

            return(View(employeeEdit));
        }
        public IActionResult Edit(Guid id, [Bind("FirstName,LastName,Id,Photo,CreatedDate,UpdatedDate")] EmployeeEditVm employeeVm)
        {
            if (id != employeeVm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var employee = _employeeService.GetByid(id);
                    employee.FirstName = employeeVm.FirstName;
                    employee.LastName  = employeeVm.LastName;


                    string uniqueFileName = null;

                    if (employeeVm.Photo != null)
                    {
                        if (employeeVm.ExistingPhotoPath != null)
                        {
                            var filePathToDelete = Path.Combine(_hostingEnvironment.WebRootPath + "\\images" + employeeVm.ExistingPhotoPath);
                            System.IO.File.Delete(filePathToDelete);
                        }
                        var uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath + "\\images"); //Web root image folder
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + employeeVm.Photo.FileName;   //File Name

                        var filePath = Path.Combine(uploadsFolder, uniqueFileName);                     //Combine above two to create one path
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            employeeVm.Photo.CopyTo(fileStream); // here we can code to copy(upload) on azure storage
                        }
                    }



                    employee.PhotoPath = uniqueFileName;



                    _employeeService.Update(employee);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employeeVm.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(employeeVm));
        }