コード例 #1
0
        public ActionResult <SubjectDto> CreateSubject(SubjectDto subjectDto)
        {
            var subjectModel = _mapper.Map <Subject>(subjectDto);


            _repository.Create(subjectModel);
            _repository.SaveChanges();

            var subjectCreatedDto = _mapper.Map <SubjectDto>(subjectModel);

            return(CreatedAtRoute(nameof(GetSubjectById), new { Id = subjectModel.Id }, subjectCreatedDto));
        }
コード例 #2
0
        public ActionResult <RoomDto> CreateRoom(RoomDto roomDto)
        {
            var roomModel = _mapper.Map <Room>(roomDto);


            _repository.Create(roomModel);
            _repository.SaveChanges();

            var roomCreatedDto = _mapper.Map <RoomDto>(roomModel);

            return(CreatedAtRoute(nameof(GetRoomById), new { Id = roomModel.Id }, roomCreatedDto));
        }
コード例 #3
0
        public ActionResult <CourseDto> CreateCourse(CourseDto courseDto)
        {
            var courseModel = _mapper.Map <Course>(courseDto);


            _repository.Create(courseModel);
            _repository.SaveChanges();

            var courseCreatedDto = _mapper.Map <CourseDto>(courseModel);

            return(CreatedAtRoute(nameof(GetCourseById), new { Id = courseModel.Id }, courseCreatedDto));
        }
コード例 #4
0
        public ActionResult <LecturerDto> CreateLecturer(LecturerDto lecturerDto)
        {
            var lecturerModel = _mapper.Map <Lecturer>(lecturerDto);
            var rand          = new Random();

            lecturerModel.EmployeeId = rand.Next(100000, 1000000);

            //TODO EmployeeId Identity

            _repository.Create(lecturerModel);
            _repository.SaveChanges();

            var lecturerCreatedDto = _mapper.Map <LecturerDto>(lecturerModel);

            return(CreatedAtRoute(nameof(GetLecturerById), new { Id = lecturerModel.Id }, lecturerCreatedDto));
        }
コード例 #5
0
        public ActionResult <StudentDto> CreateStudent(StudentDto studentDto)
        {
            var studentModel = _mapper.Map <Student>(studentDto);
            var rand         = new Random();

            studentModel.CardId = rand.Next(100000, 1000000);

            //TODO Identity cardID

            _repository.Create(studentModel);
            _repository.SaveChanges();

            var studentCreatedDto = _mapper.Map <StudentDto>(studentModel);

            return(CreatedAtRoute(nameof(GetStudentById), new { Id = studentModel.Id }, studentCreatedDto));
        }
コード例 #6
0
        public IActionResult Index(object data)
        {
            dynamic parsedData = JObject.Parse(data.ToString());
            int     courseId   = parsedData.courseId;
            int     studentId  = parsedData.studentId;
            //var courseModelFromRepo = _courseRepository.GetById(courseId);
            //if (courseModelFromRepo == null)
            //    return NotFound();

            //var studentModelFromRepo = _studentRepository.GetById(studentId);
            //if (courseModelFromRepo == null)
            //    return NotFound();

            //var studentToCourse = new StudentCourse
            //{
            //    CourseId = courseModelFromRepo.Id,
            //    StudentId = studentModelFromRepo.Id
            //};

            //string json = System.Text.Json.JsonSerializer.Serialize(data);
            //var result = new Regex(@"\d+").Matches(json)
            //    .Cast<Match>()
            //    .Select(m => Int32.Parse(m.Value))
            //    .ToArray();

            //return View("~/Views/StudentCourses/Index.cshtml", data);

            var courseModelFromRepo = _context.Courses.SingleOrDefault(c => c.Id == courseId);

            if (courseModelFromRepo == null)
            {
                return(NotFound());
            }

            var studentModelFromRepo = _context.Students.SingleOrDefault(s => s.Id == studentId);

            if (studentModelFromRepo == null)
            {
                return(NotFound());
            }

            var studentToCourse = new StudentCourse
            {
                CourseId  = courseModelFromRepo.Id,
                StudentId = studentModelFromRepo.Id
            };


            _repository.Create(studentToCourse);
            _repository.SaveChanges();

            return(NoContent());
        }