Example #1
0
        public ActionResult AddEmployee(DashBoard.Models.EmployeeModel model)
        {
            if (ModelState.IsValid)
            {
                DATA.Domains.Employee employee = new DATA.Domains.Employee
                {
                    CellNo       = model.CellNo,
                    CNIC         = model.CNIC,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    DepartmentId = model.DepartmentId,
                    CreatedOn    = DateTime.Now,
                    IsActive     = true,
                    IsDeleted    = false
                };
                employeeProvider.AddEmployee(employee);

                TempData["alert"] = GetAlert("Employee added successfully", "success");
            }
            else
            {
                TempData["alert"] = GetAlert("Employee not added successfully", "error");
            }

            var departments = employeeProvider.GetDepartments();

            TempData["Departments"] = departments;

            return(View());
        }
        /// <summary>
        /// Saves the employee.
        /// </summary>
        /// <param name="profile">The profile.</param>
        /// <returns>a Task</returns>
        private async Task SaveEmployee(IEmployeeProfile profile)
        {
            var tempEmployee = new EmployeeProfile
            {
                FirstName    = profile.FirstName,
                LastName     = profile.LastName,
                Salary       = profile.Salary,
                HoursPerDay  = profile.HoursPerDay,
                DaysPerWeek  = profile.DaysPerWeek,
                WeeksPerYear = profile.WeeksPerYear
            };

            var validator = new EmployeeProfileValidator();
            var results   = validator.Validate(tempEmployee);

            if (results.IsValid)
            {
                SaveButtonEnabled = false;
                var saveSuccess = await EmployeeProvider.AddEmployee(tempEmployee);

                //TODO move to resources
                Message           = saveSuccess == 1 ? "Employee details saved" : "Unable able to save employee details";
                SaveButtonEnabled = true;
            }
            else
            {
                foreach (var error in results.Errors)
                {
                    Message = error.ErrorMessage;
                }
            }
            Message = string.Empty;
        }