示例#1
0
        // GET: OfficeAssignments
        public async Task <ActionResult> Index()
        {
            var officeAssignmentService = new OfficeAssignmentService(new OfficeAssignmentRepository(UniversityContext));

            var officeAssignments = await officeAssignmentService.GetAll();

            var officeAssignmentsDTO = officeAssignments.Select(x => mapper.Map <OfficeAssignmentDTO>(x));

            return(View(officeAssignmentsDTO));
        }
示例#2
0
        public async Task <ActionResult> Create(OfficeAssignmentDTO officeAssignmentDTO)
        {
            var instructorService = new InstructorService(new InstructorRepository(UniversityContext));
            var instructors       = await instructorService.GetAll();

            var instructorsDTO = instructors.Select(x => mapper.Map <InstructorDTO>(x));

            ViewData["Instructors"] = new SelectList(instructorsDTO, "ID", "FullName", officeAssignmentDTO.InstructorID);

            if (ModelState.IsValid)
            {
                var officeAssignmentService = new OfficeAssignmentService(new OfficeAssignmentRepository(UniversityContext));
                var officeAssignment        = mapper.Map <OfficeAssignment>(officeAssignmentDTO);
                officeAssignment = await officeAssignmentService.Insert(officeAssignment);

                return(RedirectToAction("Index", "OfficeAssignments"));
            }

            return(View(officeAssignmentDTO));
        }