public void ShouldGetGenderList()
        {
            var viewModel = new EmployeeEditViewModel();
            viewModel.Gender = DataDefinition.Gender.Female;

            Assert.AreEqual(DataDefinition.Gender.Female, viewModel.GenderList.SelectedValue);
        }
        public void ShouldGetMartialStatusList()
        {
            var viewModel = new EmployeeEditViewModel();
            viewModel.MaritalStatus = DataDefinition.MartialStatus.UnMarried;

            Assert.AreEqual(DataDefinition.MartialStatus.UnMarried, viewModel.MartialStatusList.SelectedValue);
        }
        public void ShouldGetSalaryTypeList()
        {
            var viewModel = new EmployeeEditViewModel();
            viewModel.SalariedFlag = true;

            Assert.AreEqual(true, viewModel.SalaryTypeList.SelectedValue);
        }
        public ActionResult Edit(EmployeeEditViewModel e, string btnSave)
        {
            if (btnSave == "Save")
            {
                if (!ModelState.IsValid)
                    return RedirectToAction("Index");

                NORTHWNDEntities nwe = new NORTHWNDEntities();
                nwe.Configuration.ProxyCreationEnabled = false;
                Employee original = nwe.Employees.Where(emp => emp.EmployeeID == employeeId).SingleOrDefault();
                CopyPropertyValues(e, original);
                nwe.SaveChanges();

                return View("ProfileView", original);
            }
            else
                return View("Index");
        }
Exemple #5
0
        public IActionResult Edit(EmployeeEditViewModel model)
        {
            // Check if the provided data is valid, if not rerender the edit view
            // so the user can correct and resubmit the edit form
            if (ModelState.IsValid)
            {
                // Retrieve the employee being edited from the database
                Employee employee = _employeeRepository.GetEmployee(model.Id);
                // Update the employee object with the data in the model object
                employee.Name       = model.Name;
                employee.Email      = model.Email;
                employee.Department = model.Department;

                // If the user wants to change the photo, a new photo will be
                // uploaded and the Photo property on the model object receives
                // the uploaded photo. If the Photo property is null, user did
                // not upload a new photo and keeps his existing photo
                if (model.Photo != null)
                {
                    // If a new photo is uploaded, the existing photo must be
                    // deleted. So check if there is an existing photo and delete
                    if (model.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath,
                                                       "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    // Save the new photo in wwwroot/images folder and update
                    // PhotoPath property of the employee object which will be
                    // eventually saved in the database
                    employee.PhotoPath = ProcessUploadedFile(model);
                }

                // Call update method on the repository service passing it the
                // employee object to update the data in the database table
                Employee updatedEmployee = _employeeRepository.Update(employee);

                return(RedirectToAction("index"));
            }

            return(View(model));
        }
Exemple #6
0
        public async Task <IActionResult> EditAsync(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = _employeeService.GetById(model.Id);
                if (employee == null)
                {
                    return(NotFound());
                }
                employee.EmpId         = model.EmpId;
                employee.FirstName     = model.FirstName;
                employee.LastName      = model.LastName;
                employee.Gender        = model.Gender;
                employee.Email         = model.Email;
                employee.Designation   = model.Designation;
                employee.TFN           = model.TFN;
                employee.DOB           = model.DOB;
                employee.DOJ           = model.DOJ;
                employee.paymentMethod = model.paymentMethod;
                employee.studentLoan   = model.studentLoan;
                employee.Address       = model.Address;
                employee.City          = model.City;
                employee.POcode        = model.POcode;
                employee.Phone         = model.Phone;
                if (model.ImageUrl != null && model.ImageUrl.Length > 0)
                {
                    var uploadDir   = @"images/employee";
                    var fileName    = Path.GetFileNameWithoutExtension(model.ImageUrl.FileName);
                    var extension   = Path.GetExtension(model.ImageUrl.FileName);
                    var webRootPath = _hostingEnvironment.ContentRootPath;
                    fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extension;
                    var path = Path.Combine(webRootPath, uploadDir, fileName);
                    await model.ImageUrl.CopyToAsync(new FileStream(path, FileMode.Create));

                    employee.ImageUrl = "/" + uploadDir + "/" + fileName;
                }
                await _employeeService.UpdateAsync(employee);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            var employee          = GetEmployeeById(id);
            var departmentOptions = GetDepartmentOptions();
            var computerOptions   = AvailableAndAssignedComputers(id);
            var viewModel         = new EmployeeEditViewModel()
            {
                EmployeeId        = employee.Id,
                FirstName         = employee.FirstName,
                LastName          = employee.LastName,
                Email             = employee.Email,
                DepartmentId      = employee.DepartmentId,
                ComputerId        = employee.ComputerId,
                IsSupervisor      = employee.IsSupervisor,
                DepartmentOptions = departmentOptions,
                ComputerOptions   = computerOptions
            };

            return(View(viewModel));
        }
        public ViewResult Edit(int id)
        {
            Employee emp = _employeeRepository.GetEmployee(id);

            if (emp == null)
            {
                return(View("~/Error/NotFound"));
            }

            EmployeeEditViewModel employeeEditViewModel = new EmployeeEditViewModel
            {
                Id                = emp.Id,
                Name              = emp.Name,
                Email             = emp.Email,
                Department        = emp.Department,
                ExistingPhotoPath = emp.PhotoPath
            };

            return(View(employeeEditViewModel));
        }
        public ActionResult DownloadPersonalDetails(int Empcode)
        {
            ViewBag.SideBar = _moduleService.AdminEmployeeDetailsMenu(Empcode);
            EmployeeDetailsViewModel reEmp   = _employeeService.GetEmployeeDetails(Empcode);
            EmployeeEditViewModel    Details = _employeeService.GetEmployeeByID(Empcode);
            IEnumerable <EmployeeFamilyViewModel>   Familydetails = _employeeService.GetEmployeeFamilyByID(Empcode);
            IEnumerable <EmployeePrizeDTO>          res           = _empPrizeService.GetAllPrizeOfEmployee(Empcode);
            IEnumerable <EmployeeSkillViewModel>    skill         = _employeeService.GetEmployeeSkillsByID(Empcode);
            IEnumerable <EmployeeDocumentViewModel> document      = _employeeService.GetEmployeeDocumentsByID(Empcode);
            EmployeeDetailAdminViewModel            EmpDetails    = new EmployeeDetailAdminViewModel();

            reEmp.EmployeeAppointmentDetail = _employeeService.GetEmployeeAppointmentDetails(Empcode);
            EmpDetails.EmpDetails           = reEmp;
            EmpDetails.OtherDetails         = Details;
            EmpDetails.Familydetails        = Familydetails;
            EmpDetails.Prize     = res;
            EmpDetails.Skill     = skill;
            EmpDetails.Documents = document;
            return(View(EmpDetails));
        }
        public IActionResult Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = _emp.getById(model.Id);
                employee.Name       = model.Name;
                employee.Email      = model.Email;
                employee.Department = model.Department;
                if (model.Photo != null)
                {
                    string filePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotopath);
                    System.IO.File.Delete(filePath);
                }
                employee.Photopath = ProcessUploaderFile(model); // To update the updated photo in the model calling common method for edit and create for photopath property

                Employee UpdatedEmployee = _emp.UpdateEmployee(employee);
                return(RedirectToAction("index", new { id = UpdatedEmployee.Id }));
            }
            return(View(model));
        }
Exemple #11
0
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            EmployeeEditViewModel viewModel = new EmployeeEditViewModel {
                EmployeeTrainingEditViewModel = new EmployeeTrainingEditViewModel {
                    EnrolledTrainingPrograms          = GetEnrolledTrainingPrograms(id),
                    NotEnrolledTrainingPrograms       = GetNotEnrolledTrainingPrograms(id),
                    EditedEnrolledTrainingPrograms    = null,
                    EditedNotEnrolledTrainingPrograms = null
                },
                EmployeeDataAndDeptEditViewModel = new EmployeeDataAndDeptEditViewModel {
                    Employee    = GetEmployeeById(id),
                    Departments = GetAllDepartments()
                },
                EmployeeComputerEditViewModel = new EmployeeComputerEditViewModel {
                    Computers = GetUnassignedComputers(id)
                }
            };

            return(View(viewModel));
        }
Exemple #12
0
        public IActionResult Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = _employeeRepository.GetEmployee(model.Id);
                employee.Name       = model.Name;
                employee.Email      = model.Email;
                employee.Department = model.Department;
                employee.PhotoPath  = model.ExinstingPhotoPath;
                if (model.Photo != null)
                {
                    employee.PhotoPath = ProceesUploadedFile(model);
                }

                _employeeRepository.Update(employee);
                return(RedirectToAction("Index"));
            }

            return(View()); //View retun ViewResult RedirectToAction RedirectToActionResult both implement from IActionResult
        }
        // GET: Employee/Edit/5
        public ActionResult Edit(int id)
        {
            var employee  = GetEmployeeById(id);
            var viewModel = new EmployeeEditViewModel()
            {
                Employee    = employee,
                Departments = GetAllDepartments(),
            };

            if (employee.Computer != null)
            {
                viewModel.SelectedComputerId = employee.Computer.Id;
                viewModel.Computers          = GetUnassignedComputersAndCurrentEmployeeComputer(id, employee.Computer.Id);
            }
            else
            {
                viewModel.Computers = GetUnassignedComputersAndCurrentEmployeeComputer(id, null);
            }
            return(View(viewModel));
        }
        public async Task <IActionResult> Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = await _employeeRepository.GetEmployeeAsync(model.Id);

                // Update the employee object with the data in the model object
                employee.Name       = model.Name;
                employee.Email      = model.Email;
                employee.Department = model.Department;

                // Call update method on the repository service passing it the
                // employee object to update the data in the database table
                Employee updatedEmployee = await _employeeRepository.UpdateAsync(employee);

                return(RedirectToAction("index"));
            }

            return(View(model));
        }
        //return the FORM
        // GET: Employees/Edit/5
        public ActionResult Edit(int id)
        {
            var employee          = GetEmployeeById(id);
            var DepartmentOptions = GetDepartmentOptions();
            var ComputerOptions   = GetComputerOptions();
            var viewModel         = new EmployeeEditViewModel()
            {
                Id                = employee.Id,
                FirstName         = employee.FirstName,
                LastName          = employee.LastName,
                DepartmentId      = employee.DepartmentId,
                Email             = employee.Email,
                IsSupervisor      = employee.IsSupervisor,
                ComputerId        = employee.ComputerId,
                DepartmentOptions = DepartmentOptions,
                ComputerOptions   = ComputerOptions
            };

            return(View(viewModel));
        }
Exemple #16
0
        // GET: Employee/Edit/5
        public ActionResult Edit(int id)
        {
            //Employee emp = _employeeRepository.GetEmployee(id);
            //if (emp == null)
            //    return NotFound();
            //else
            //return View(emp);

            Employee employee = _employeeRepository.GetEmployee(id);
            EmployeeEditViewModel employeeEditViewModel = new EmployeeEditViewModel
            {
                Id                = employee.Id,
                Name              = employee.Name,
                Salary            = employee.Salary,
                Department        = employee.Departement,
                ExistingPhotoPath = employee.PhotoPath
            };

            return(View(employeeEditViewModel));
        }
Exemple #17
0
        public IActionResult EmployeeCreate(EmployeeEditViewModel model)
        {
            var isExistsEmployee = _dbContext.Employees.Any(e => e.Name == model.Name);

            if (isExistsEmployee)
            {
                return(Content($"{model.Name}已经存在"));
            }
            if (!ModelState.IsValid)
            {
                return(Content($"{model.Name}格式不符合标准"));
            }
            var emp = new Employee {
                Name = model.Name
            };

            _dbContext.Employees.Add(emp);
            _dbContext.SaveChanges();
            return(RedirectToAction("EmployeeDetail", new { id = emp.Id }));
        }
        public ViewResult Edit(int id)
        {
            var employee = _employeeRepository.GetEmployee(id);

            if (employee == null)
            {
                return(View("index"));
            }

            var editEmployee = new EmployeeEditViewModel
            {
                Id                = employee.Id,
                Name              = employee.Name,
                Email             = employee.Email,
                Department        = employee.Department,
                ExistingPhotoPath = employee.PhotoPath
            };

            return(View("edit", editEmployee));
        }
Exemple #19
0
        public ViewResult Edit(int id)
        {
            Employee employee = _employeeRepository.GetEmployee(id);

            if (employee == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", id));
            }
            EmployeeEditViewModel employeeEditViewModel = new EmployeeEditViewModel
            {
                Id                = employee.Id,
                Name              = employee.Name,
                Email             = employee.Email,
                Department        = employee.Department,
                ExistingPhotoPath = employee.PhotoPath
            };

            return(View(employeeEditViewModel));
        }
Exemple #20
0
        public IActionResult Edit(EmployeeEditViewModel employeeEditViewModel)
        {
            if (ModelState.IsValid)
            {
                Employee employee = this.employeeRepository.GetEmployee(employeeEditViewModel.Id);
                employee.Name         = employeeEditViewModel.Name;
                employee.Email        = employeeEditViewModel.Email;
                employee.IdDepartment = employeeEditViewModel.IdDepartment;

                if (employeeEditViewModel.Photo != null)
                {
                    if (employeeEditViewModel.ExistingPhotoPath != null)
                    {
                        string filePath     = Path.Combine(hostingEnviroment.WebRootPath, "Images", employeeEditViewModel.ExistingPhotoPath);
                        bool   canBeDeleted = true;

                        foreach (var item in this.employeeRepository.GetAllEmployees())
                        {
                            if (item.PhotoPath == employeeEditViewModel.ExistingPhotoPath)
                            {
                                canBeDeleted = false;
                                break;
                            }
                        }

                        if (canBeDeleted)
                        {
                            System.IO.File.Delete(filePath);
                        }
                    }

                    employee.PhotoPath = ProcessUploadPhoto(employeeEditViewModel);
                }

                this.employeeRepository.Update(employee);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemple #21
0
        public IActionResult Edit(EmployeeEditViewModel emp)
        {
            if (ModelState.IsValid)
            {
                var input = _empRepository.GetEmployee(emp.Id);
                input.Name       = emp.Name;
                input.EmailId    = emp.Email;
                input.Department = (EmployeeManagement.DataAccess.Dept)emp.Department;

                //If the user has uploaded a new picture, update the details
                if (emp.Photo != null)
                {
                    //Delete the old picture if the user uploads a new picture
                    if (emp.ExistingPhotoPath != null)
                    {
                        string filePath = Path.Combine(hostingEnvironment.WebRootPath, "Images", emp.ExistingPhotoPath);
                        System.IO.File.Delete(filePath);
                    }
                    string uniqueFilename = ProcessPhoto(emp);
                    input.PhotoPath = uniqueFilename;
                }

                var updatedEmp = _empRepository.Update(input);


                //DataAccess.Repository.EmployeeModel --> EmployeeEditViewModel
                var model = new EmployeeEditViewModel
                {
                    Id                = updatedEmp.Id,
                    Name              = updatedEmp.Name,
                    Email             = updatedEmp.EmailId,
                    Department        = (KudVenvat1.Models.Dept)updatedEmp.Department,
                    ExistingPhotoPath = updatedEmp.PhotoPath
                };
                return(RedirectToAction("Details", new { id = model.Id }));
            }
            else
            {
                return(View());
            }
        }
Exemple #22
0
        public async Task <IActionResult> Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                int decryptedId;
                int y;
                if (int.TryParse(model.Id, out y))
                {
                    decryptedId = y;
                }
                else
                {
                    decryptedId = Convert.ToInt32(protector.Unprotect(model.Id));
                }
                Employee employee = await employeeService.GetEmployee(decryptedId);

                employee.FirstName     = model.FirstName;
                employee.LastName      = model.LastName;
                employee.Phone         = model.Phone;
                employee.LevelId       = model.LevelId;
                employee.LeaveRequests = model.LeaveRequests;
                employee.DepartmentId  = model.DepartmentId;
                employee.DateCreated   = model.DateCreated;
                employee.DateModified  = model.DateModified;
                employee.Email         = model.Email;

                try
                {
                    await employeeService.UpdateEmployee(employee);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message + "\n" + "  Ensure both department and level Ids are correct");
                }
                return(View(model));
            }

            return(View(model));
        }
        public ActionResult Edit(int id, [FromForm] EmployeeEditViewModel employee)
        //public ActionResult Edit(int id, Employee employee)
        {
            try
            {
                using (SqlConnection conn = Connection)
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"UPDATE Employee
                                            SET FirstName = @firstName,
                                            LastName = @lastName, 
                                            DepartmentId = @departmentId,
                                            ComputerId = @computerId
                                          
                                            WHERE Id = @id";

                        cmd.Parameters.Add(new SqlParameter("@lastName", employee.LastName));
                        cmd.Parameters.Add(new SqlParameter("@firstName", employee.FirstName));
                        cmd.Parameters.Add(new SqlParameter("@departmentid", employee.DepartmentId));
                        cmd.Parameters.Add(new SqlParameter("@computerid", employee.ComputerId));
                        //cmd.Parameters.Add(new SqlParameter("@isSupervisor", employee.IsSupervisor));
                        cmd.Parameters.Add(new SqlParameter("@id", id));

                        var rowsAffected = cmd.ExecuteNonQuery();

                        if (rowsAffected < 1)
                        {
                            return(NotFound());
                        }
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Exemple #24
0
        public ActionResult Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = _employeeRepository.GetEmployeeById(model.ID);
                employee.Name       = model.Name;
                employee.Department = model.Department;

                if (model.Photos != null && model.Photos.Count > 0)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        System.IO.File.Delete(Path.Combine(hostEnvironment.WebRootPath, "images", model.ExistingPhotoPath));
                    }
                    employee.PhotoPath = ProcessUploadFiles(model);
                }
                Employee updatedEmployee = _employeeRepository.Update(employee);
                return(RedirectToAction("index"));
            }
            return(View(model));
        }
Exemple #25
0
        public ViewResult EditView(int id)
        {
            MEmployee emp = _emp_repository.GetEmployee(id);

            if (emp == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFoundView", id));
            }

            EmployeeEditViewModel empeditvm = new EmployeeEditViewModel
            {
                EmpID             = emp.EmpID,
                Name              = emp.Name,
                Email             = emp.Email,
                Dept              = emp.Dept,
                ExistingPhotoPath = emp.PhotoPath
            };

            return(View(empeditvm));
        }
        public IActionResult Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee exEmployee = _employeeRepositry.GetEmployee(model.Id);
                exEmployee.Name       = model.Name;
                exEmployee.Email      = model.Email;
                exEmployee.Department = model.Department;
                exEmployee.Mobile     = model.Mobile;
                if (model.ExistingPhotoPath != null)
                {
                    string FilePath = Path.Combine(hostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                    System.IO.File.Delete(FilePath);
                }
                exEmployee.PhotoPath = ProcessUploadFile(model);
                _employeeRepositry.Update(exEmployee);
                return(RedirectToAction("index", new { id = exEmployee.Id }));
            }

            return(View());
        }
Exemple #27
0
        public async Task <EmployeeEditViewModel> GetEmployeeToEdit(int?id)
        {
            var query = await _context.Employees
                        .Include(x => x.Dependents)
                        .FirstOrDefaultAsync(y => y.EmployeeId == id);

            if (query != null)
            {
                var employeeToEdit = new EmployeeEditViewModel
                {
                    EmployeeId = query.EmployeeId,
                    FirstName  = query.FirstName,
                    LastName   = query.LastName,
                    Dependents = query.Dependents
                };

                return(employeeToEdit);
            }

            return(null);
        }
Exemple #28
0
 public ViewResult EditGet(int id)
 {
     try
     {
         Employee employee = _employeeRepository.GetEmployee(id);
         EmployeeEditViewModel employeeEditViewModel = new EmployeeEditViewModel {
             Id                = employee.Id,
             Name              = employee.Name,
             Email             = employee.Email,
             Department        = employee.Department,
             ExistingPhotoPath = employee.PhotoPath
         };
         return(View(employeeEditViewModel));
     }
     catch (Exception ex)
     {
         ViewBag.ErrorTitle       = ex.Message;
         ViewBag.ErrorDescription = ex.StackTrace;
         return(View("Error"));
     }
 }
Exemple #29
0
        public ViewResult Edit(int id)
        {
            var employee = _employeeRepository.GetEmployee(id);

            if (employee == null)
            {
                Response.StatusCode = 404;
                return(View("EmployeeNotFound", id));
            }
            EmployeeEditViewModel model = new EmployeeEditViewModel()
            {
                Id                = employee.Id,
                Name              = employee.Name,
                Email             = employee.Email,
                Department        = employee.Department,
                ExistingPhotoPath = employee.PhotoPath
            };

            ViewBag.Path = _storageSrvices.Getpath(employee.PhotoPath);
            return(View(model));
        }
        /*
         * Author: Ricky Bruner
         * Purpose: To GET all of the neccessary data from the database and render the Edit View to the user. The "computer" logic below accounts for whether or not the specified employee has been assigned a computer.
         */
        // GET: Employee/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            List <Department> allDepartments = await GetAllDepartments();

            List <Computer> allActiveComputers = await GetAllAvailableComputers();

            List <TrainingProgram> employeeTrainingPrograms = await GetEmployeeTrainingPrograms(id.Value);

            List <TrainingProgram> allTrainingPrograms = await GetAllTrainingPrograms();

            Employee employee = await GetById(id.Value);

            Computer computer = await GetEmployeeComputer(id.Value);

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

            EmployeeEditViewModel viewmodel = new EmployeeEditViewModel
            {
                Employee                 = employee,
                AllDepartments           = allDepartments,
                AllComputers             = allActiveComputers,
                EmployeeTrainingPrograms = employeeTrainingPrograms,
                AllTrainingPrograms      = allTrainingPrograms
            };

            if (computer != null)
            {
                viewmodel.Computer = computer;
            }

            return(View(viewmodel));
        }
Exemple #31
0
        public ActionResult Setup(int?id)
        {
            EmployeeEditViewModel vm = null;

            if (!id.HasValue)
            {
                ViewBag.Title = EmployeeStrings.Create_Title;
                vm            = new EmployeeEditViewModel()
                {
                    JoiningDate = _userHelper.Get().DayOpenClose.SystemDate,
                    IsActive    = true
                };

                if (_userHelper.Get().IsHeadOffice)
                {
                    vm.BranchId = _userHelper.Get().BranchId;
                }
            }
            else
            {
                ViewBag.Title = EmployeeStrings.Edit_Title;
                vm            = _employeeService.GetEmployeeById(id.Value);
            }

            if (vm == null)
            {
                SystemMessages.Add(CommonStrings.No_Record, true, true);
                return(RedirectToAction("Index"));
            }

            ViewBag.GenderDropDown       = new SelectList(_genderService.GetGenderDropDown(), "Value", "Text");
            ViewBag.EmployeeTypeDropDown = new SelectList(_employeeTypeService.GetEmployeeTypeDropDown(), "Value", "Text");

            if (_userHelper.Get().IsHeadOffice)
            {
                ViewBag.BranchDropDown = new SelectList(_branchService.GetBranchDropDown(), "Value", "Text");
            }

            return(View("Setup", vm));
        }
        public async Task <IActionResult> Create(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                EmployeeUser user = new EmployeeUser()
                {
                    FirstName    = model.FirstName,
                    MiddleName   = model.MiddleName,
                    LastName     = model.LastName,
                    UserName     = model.Email,
                    Email        = model.Email,
                    PhoneNumber  = model.PhoneNumber,
                    EGN          = model.EGN,
                    Hired        = DateTime.Now,
                    Reservations = new List <Reservation>(),
                    IsActive     = true
                };

                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Assign role
                    EmployeeUser createdUser = await _userManager.FindByEmailAsync(user.Email);

                    await _userManager.AddToRoleAsync(createdUser, WebConstants.EmployeeRole);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = _employeeService.GetById(model.Id);

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

                employee.EmployeeNumber          = model.EmployeeNumber;
                employee.FirstName               = model.FirstName;
                employee.MiddleName              = model.MiddleName;
                employee.LastName                = model.LastName;
                employee.Gender                  = model.Gender;
                employee.Email                   = model.Email;
                employee.Phone                   = model.Phone;
                employee.DOB                     = model.DOB;
                employee.DateJoined              = model.DateJoined;
                employee.Designation             = model.Designation;
                employee.NationalInsuranceNumber = model.NationalInsuranceNumber;
                employee.PaymentMethod           = model.PaymentMethod;
                employee.UnionMember             = model.UnionMember;
                employee.StudentLoan             = model.StudentLoan;
                employee.Address                 = model.Address;
                employee.City                    = model.City;
                employee.PostCode                = model.PostCode;

                if (model.ImageUrl != null && model.ImageUrl.Length > ConstantsKeys.LENGTH_0)
                {
                    employee.ImageUrl = await SaveImageOnServer(model.ImageUrl);
                }

                await _employeeService.UpdateAsync(employee);

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        public async Task <IActionResult> Edit(EmployeeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                Employee employee = new Employee
                {
                    Id          = model.Id,
                    Username    = model.Username,
                    Password    = model.Password,
                    Email       = model.Email,
                    Firstname   = model.Firstname,
                    Lastname    = model.Lastname,
                    USN         = model.USN,
                    Address     = model.Address,
                    PhoneNumber = model.PhoneNumber,
                    Role        = model.Role
                };

                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(ListEmployees)));
            }

            return(View(model));
        }
        public ActionResult Create(EmployeeEditViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View(viewModel);
                }

                var employee = Mapper.Map<Employee>(viewModel);
                viewModel.NewSkills.ForEach(x => employee.Skills.Add(_skillService.GetById(x)));

                _employeeService.Add(employee);

                return RedirectToAction("Index");
            }
            catch(Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return View(viewModel);
            }
        }
        public ActionResult Edit(int id, EmployeeEditViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View(viewModel);
                }

                // Different mapping format for Many-to-Many update.
                var employee = Mapper.Map(viewModel, _employeeService.GetById(viewModel.Id));
                viewModel.NewSkills.ForEach(x => employee.Skills.Add(_skillService.GetById(x)));

                _employeeService.Update(employee);

                return RedirectToAction("Index");
            }
            catch(Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return View(viewModel);
            }
        }
 // GET: Employee/Create
 public ActionResult Create()
 {
     var viewModel = new EmployeeEditViewModel();
     return View(viewModel);
 }