Ejemplo n.º 1
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     base.OnModelCreating(modelBuilder);
     _ = new TeacherMap(modelBuilder.Entity <Teacher>());
     _ = new StudentMap(modelBuilder.Entity <Student>());
     _ = new LectureMap(modelBuilder.Entity <Lecture>());
     _ = new CourseMap(modelBuilder.Entity <Course>());
     _ = new EnrollmentMap(modelBuilder.Entity <Enrollment>());
     _ = new SemesterMap(modelBuilder.Entity <Semester>());
 }
Ejemplo n.º 2
0
        public async Task <LectureModel> RemoveAsync(Guid id)
        {
            var lecture = await lectureRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == id);

            if (lecture == null)
            {
                throw new ApplicationException("Объект не найден.");
            }

            lectureTagBinder.ResetTags(lecture);
            lectureRepository.Remove(lecture);

            await dataContext.SaveChangesAsync();

            return(LectureMap.Map(lecture));
        }
Ejemplo n.º 3
0
        public async Task <LectureModel> CreateAsync(LectureModel model)
        {
            var lecture = new Lecture
            {
                Name    = model.Name,
                Url     = model.Url,
                Content = model.Content,
                Preview = model.Preview,
                Section = model.Section,
            };

            lectureRepository.Add(lecture);

            await dataContext.SaveChangesAsync();

            lecture = await lectureTagBinder.BindTags(lecture, model.Tags);

            return(LectureMap.Map(lecture));
        }
Ejemplo n.º 4
0
        public async Task <LectureModel> UpdateAsync(LectureModel model)
        {
            var lecture = await lectureRepository.GetQuery().FirstOrDefaultAsync(x => x.Id == model.Id);

            if (lecture == null)
            {
                throw new ApplicationException("Объект не найден.");
            }

            lecture.Name    = model.Name;
            lecture.Preview = model.Preview;
            lecture.Url     = model.Url;
            lecture.Content = model.Content;
            lecture.Section = model.Section;

            await dataContext.SaveChangesAsync();

            lecture = await lectureTagBinder.BindTags(lecture, model.Tags);

            return(LectureMap.Map(lecture));
        }
Ejemplo n.º 5
0
        public async Task <LectureModel> GetAsync(string url)
        {
            var lecture = await lectureRepository.GetQuery().FirstOrDefaultAsync(x => x.Url == url);

            return(LectureMap.Map(lecture));
        }