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>()); }
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)); }
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)); }
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)); }
public async Task <LectureModel> GetAsync(string url) { var lecture = await lectureRepository.GetQuery().FirstOrDefaultAsync(x => x.Url == url); return(LectureMap.Map(lecture)); }