public async Task <DbCourse> CreateCourseAsync(DbCourse course) { if (course == null || course.Id != 0) { return(null); } _context.Courses.Add(course); await _context.SaveChangesAsync(); return(course); }
public async Task <DbCourse> EditCourseAsync(DbCourse course) { var oldCourse = await _context.Courses .Where(c => c.Id == course.Id) .SingleOrDefaultAsync(); if (oldCourse == null) { return(null); } if (oldCourse.CourseName != course.CourseName) { oldCourse.CourseName = course.CourseName; } if (oldCourse.Details != course.Details) { oldCourse.Details = course.Details; } if (oldCourse.LearningLanguage != course.LearningLanguage) { oldCourse.LearningLanguage = course.LearningLanguage; } if (oldCourse.LearningLanguageTerritory != course.LearningLanguageTerritory) { oldCourse.LearningLanguageTerritory = course.LearningLanguageTerritory; } if (oldCourse.TeachingLanguage != course.TeachingLanguage) { oldCourse.TeachingLanguage = course.TeachingLanguage; } if (oldCourse.TeachingLanguageTerritory != course.TeachingLanguageTerritory) { oldCourse.TeachingLanguageTerritory = course.TeachingLanguageTerritory; } if (oldCourse.Level != course.Level) { oldCourse.Level = course.Level; } _context.Courses.Update(oldCourse); await _context.SaveChangesAsync(); return(course); }