Example #1
0
        public async Task <IActionResult> AddEmployee(int trainingId)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var companyId = this.departmentService.GetCompanyIdByDepartmentId(user.DepartmentId);
            var users     = this.employeService.EmployeesNotAssignToTraining <EmployeeSelectList>(companyId, trainingId);

            var model = new EmployeeToTrainingViewModel {
                Employees = users, TrainingId = trainingId
            };

            return(this.PartialView("_AddEmployeePartial", model));
        }
Example #2
0
        public async Task <IActionResult> AddEmployee(EmployeeToTrainingViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                if (model.EmployeeId == null)
                {
                    return(await this.AddEmployee(model.TrainingId));
                }

                var employees = new List <EmployeeSelectList>();
                var employee  = this.employeService
                                .GetById <EmployeeSelectList>(model.EmployeeId);
                employees.Add(employee);
                model.Employees = employees;

                return(this.PartialView("_AddEmployeePartial", model));
            }

            await this.trainingService.AddEmployeeToTraining(model.EmployeeId, model.TrainingId);

            return(this.RedirectToAction("Index"));
        }