예제 #1
0
        public ActionResult Create([Bind(Include = "Id,Name,StartingDate,EndingDate,DurationInHours,Price")] TrainingCourse trainingCourse, object[] Employees, object[] TrainedSkills, object[] CheckUpReportsFinished, object[] CheckUpReportsWished)
        {
            if (ModelState.IsValid && TrainedSkills != null)
            {
                List <Skill>    skills    = _SkillService.FindManyByIdExcludes(TrainedSkills);
                List <Employee> employees = Employees != null?_employeeService.FindManyByIdExcludes(Employees) : null;

                List <CheckUpReport> checkUpReportsFinished = CheckUpReportsFinished != null?_CheckUpReportService.FindManyByIdExcludes(CheckUpReportsFinished) : null;

                List <CheckUpReport> checkUpReportsWished = CheckUpReportsWished != null?_CheckUpReportService.FindManyByIdExcludes(CheckUpReportsWished) : null;

                trainingCourse.TrainedSkills     = skills;
                trainingCourse.EnrolledEmployees = employees;
                trainingCourse.ReportsFinished   = checkUpReportsFinished;
                trainingCourse.ReportsWished     = checkUpReportsWished;
                _TrainingCourseService.SaveCrypted(trainingCourse);
                return(RedirectToAction("Index"));
            }
            ViewBag.ErrorMessage = "";
            foreach (var key in ModelState.Keys)
            {
                foreach (var error in ModelState[key].Errors)
                {
                    ViewBag.ErrorMessage += error.ErrorMessage + "<br/>";
                }
            }
            if (TrainedSkills == null)
            {
                ViewBag.ErrorMessage = "At least one skill must be selected";
            }

            ViewBag.Employees              = new MultiSelectList(_employeeService.GetAllExcludes(), "Id", "Name", null);
            ViewBag.TrainedSkills          = new MultiSelectList(_SkillService.GetAllExcludes(), "Id", "Description", null);
            ViewBag.CheckUpReportsFinished = new MultiSelectList(_CheckUpReportService.GetAllExcludes(), "Id", "Content", null);
            ViewBag.CheckUpReportsWished   = ViewBag.CheckUpReportsFinished;
            return(View(trainingCourse));
        }