public async virtual Task <EventTeacher> Create(EventTeacher item) { this.Context.Set <EventTeacher>().Add(item); await this.Context.SaveChangesAsync(); this.Context.Entry(item).State = EntityState.Detached; return(item); }
public async void Create() { Mock <ILogger <EventTeacherRepository> > loggerMoc = EventTeacherRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = EventTeacherRepositoryMoc.GetContext(); var repository = new EventTeacherRepository(loggerMoc.Object, context); var entity = new EventTeacher(); entity.SetProperties(default(int), 1, 1); await repository.Create(entity); var records = await context.Set <EventTeacher>().ToListAsync(); records.Count.Should().Be(2); }
public async virtual Task Delete( int id) { EventTeacher record = await this.GetById(id); if (record == null) { return; } else { this.Context.Set <EventTeacher>().Remove(record); await this.Context.SaveChangesAsync(); } }
public async virtual Task Update(EventTeacher item) { var entity = this.Context.Set <EventTeacher>().Local.FirstOrDefault(x => x.Id == item.Id); if (entity == null) { this.Context.Set <EventTeacher>().Attach(item); } else { this.Context.Entry(entity).CurrentValues.SetValues(item); } await this.Context.SaveChangesAsync(); }
public async void Get() { Mock <ILogger <EventTeacherRepository> > loggerMoc = EventTeacherRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = EventTeacherRepositoryMoc.GetContext(); var repository = new EventTeacherRepository(loggerMoc.Object, context); EventTeacher entity = new EventTeacher(); entity.SetProperties(default(int), 1, 1); context.Set <EventTeacher>().Add(entity); await context.SaveChangesAsync(); var record = await repository.Get(entity.Id); record.Should().NotBeNull(); }
public async void Update_Entity_Is_Not_Tracked() { Mock <ILogger <EventTeacherRepository> > loggerMoc = EventTeacherRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = EventTeacherRepositoryMoc.GetContext(); var repository = new EventTeacherRepository(loggerMoc.Object, context); EventTeacher entity = new EventTeacher(); entity.SetProperties(default(int), 1, 1); context.Set <EventTeacher>().Add(entity); await context.SaveChangesAsync(); context.Entry(entity).State = EntityState.Detached; await repository.Update(entity); var records = await context.Set <EventTeacher>().ToListAsync(); records.Count.Should().Be(2); }
public virtual async Task Migrate() { var adminItem1 = new Admin(); adminItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); this.Context.Admins.Add(adminItem1); var eventItem1 = new Event(); eventItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), 1m, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A"); this.Context.Events.Add(eventItem1); var eventStatusItem1 = new EventStatus(); eventStatusItem1.SetProperties(1, "A"); this.Context.EventStatus.Add(eventStatusItem1); var eventStudentItem1 = new EventStudent(); eventStudentItem1.SetProperties(1, 1, 1); this.Context.EventStudents.Add(eventStudentItem1); var eventTeacherItem1 = new EventTeacher(); eventTeacherItem1.SetProperties(1, 1, 1); this.Context.EventTeachers.Add(eventTeacherItem1); var familyItem1 = new Family(); familyItem1.SetProperties(1, "A", "A", "A", "A", "A"); this.Context.Families.Add(familyItem1); var rateItem1 = new Rate(); rateItem1.SetProperties(1, 1m, 1, 1); this.Context.Rates.Add(rateItem1); var spaceItem1 = new Space(); spaceItem1.SetProperties(1, "A", "A"); this.Context.Spaces.Add(spaceItem1); var spaceFeatureItem1 = new SpaceFeature(); spaceFeatureItem1.SetProperties(1, "A"); this.Context.SpaceFeatures.Add(spaceFeatureItem1); var spaceSpaceFeatureItem1 = new SpaceSpaceFeature(); spaceSpaceFeatureItem1.SetProperties(1, 1, 1); this.Context.SpaceSpaceFeatures.Add(spaceSpaceFeatureItem1); var studentItem1 = new Student(); studentItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1); this.Context.Students.Add(studentItem1); var studioItem1 = new Studio(); studioItem1.SetProperties(1, "A", "A", "A", "A", "A", "A", "A"); this.Context.Studios.Add(studioItem1); var teacherItem1 = new Teacher(); teacherItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", 1); this.Context.Teachers.Add(teacherItem1); var teacherSkillItem1 = new TeacherSkill(); teacherSkillItem1.SetProperties(1, "A"); this.Context.TeacherSkills.Add(teacherSkillItem1); var teacherTeacherSkillItem1 = new TeacherTeacherSkill(); teacherTeacherSkillItem1.SetProperties(1, 1, 1); this.Context.TeacherTeacherSkills.Add(teacherTeacherSkillItem1); var userItem1 = new User(); userItem1.SetProperties(1, "A", "A"); this.Context.Users.Add(userItem1); await this.Context.SaveChangesAsync(); }