コード例 #1
0
        public void Add()
        {
            InstructorDTO instructor = new InstructorDTO
            {
                FirstName      = "Seyda",
                LastName       = "Kurtdere",
                MobilePhone    = "05348754962",
                EmailAddress   = "*****@*****.**",
                RecordStatusId = 1,
                CreatedDate    = DateTime.Now,
                CreatedBy      = 1,
            };

            instructor.InstructorCoursList = new System.Collections.Generic.List <InstructorCoursDTO>();
            InstructorCoursDTO instructorCours1 = new InstructorCoursDTO {
                CourseId = 1
            };
            InstructorCoursDTO instructorCours2 = new InstructorCoursDTO {
                CourseId = 2
            };

            instructor.InstructorCoursList.Add(instructorCours1);
            instructor.InstructorCoursList.Add(instructorCours2);

            var result = instructorService.Add(instructor);

            Assert.IsNotNull(result);
        }
コード例 #2
0
        public async Task <ActionResult> Create([Bind(Include = "LastName,FirstMidName,HireDate,OfficeAssignment")] Instructor instructor, string[] selectedCourses)
        {
            if (ModelState.IsValid)
            {
                await UpdateInstructorCourses(instructor, selectedCourses);

                try
                {
                    await _instructorService.Add(instructor);

                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException)
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            await PopulateAssignedCourseData(instructor);

            return(View(instructor));
        }