public async Task <ActionResult> Index(CreateEmployeeModel employee)
        {
            if (string.IsNullOrWhiteSpace(employee.FirstName))
            {
                return(View());
            }

            var updatedCount = await _employeeOrchestrator.CreateEmployee(new EmployeeViewModel
            {
                FirstName      = employee.FirstName,
                MiddleName     = employee.MiddleName,
                LastName       = employee.LastName,
                BirthDate      = employee.BirthDate,
                HireDate       = employee.HireDate,
                Department     = employee.Department,
                JobTitle       = employee.JobTitle,
                Salary         = employee.Salary,
                SalaryType     = employee.SalaryType,
                EmployeeId     = Guid.NewGuid(),
                AvailableHours = employee.AvailableHours
            });

            ModelState.Clear(); //clear all fields on submit
            return(View());
        }
        public async Task <ActionResult> CreateEmployee(CreateEmployeeModel employee)
        {
            if (string.IsNullOrWhiteSpace(employee.FirstName))
            {
                return(View());
            }

            EmployeeViewModel employeeViewModel = new EmployeeViewModel
            {
                FirstName      = employee.FirstName,
                MiddleName     = employee.MiddleName,
                LastName       = employee.LastName,
                BirthDate      = employee.BirthDate,
                HireDate       = employee.HireDate,
                Department     = employee.Department,
                JobTitle       = employee.JobTitle,
                Salary         = employee.Salary,
                EmployeeId     = employee.EmployeeId,
                AvailableHours = employee.AvailableHours
            };



            await _employeeOrchestrator.CreateEmployee(employeeViewModel);

            return(View());
        }
        public async Task <ActionResult> Create(CreateEmployeeModel employee)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _employeeOrchestrator.CreateEmployee(new EmployeeViewModel
                    {
                        RecordGuid     = Guid.NewGuid(),
                        FirstName      = employee.FirstName,
                        MiddleName     = employee.MiddleName,
                        LastName       = employee.LastName,
                        BirthDate      = employee.BirthDate.Date,
                        HireDate       = employee.HireDate.Date,
                        Department     = employee.Department,
                        JobTitle       = employee.JobTitle,
                        PayRate        = employee.PayRate,
                        SalaryType     = employee.SalaryType,
                        EmployeeId     = employee.EmployeeId,
                        AvailableHours = employee.AvailableHours
                    });

                    System.Web.HttpContext.Current.Response.Write("<script>alert('Employee record created successfully.')</script>");
                    ModelState.Clear();
                    return(View("CreateEmployee"));
                }
                catch (DataException dex)
                {
                    Console.WriteLine(dex);
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
            }
            return(View("CreateEmployee"));
        }
Example #4
0
        public async Task <ActionResult> Create(CreateEmployeeModel employee)
        {
            if (string.IsNullOrWhiteSpace(employee.Name))
            {
                return(View());
            }

            var updatedCount = await _employeeOrchestrator.CreateEmployee(new EmployeeViewModel
            {
                EmployeeId   = Guid.NewGuid(),
                EmployeeName = employee.Name,
                Email        = employee.Email,
                Role         = employee.Role
            });

            return(View());
        }