public CrashCourseDomain Add(string title, string description) { var model = new CrashCourseModel { Title = title, Description = description, CreatedAt = _clockService.Now }; using (var connection = new SqliteConnection(_configuration.GetConnectionString("cnx"))) { connection.Open(); var row = connection.Execute($"INSERT INTO {_tableName} (title, description, createdAt) Values (@Title, @Description, @CreatedAt);", model); } return(model.To()); }
public CrashCourseDomain Add(string title, string description) { var model = new CrashCourseModel { Title = title, Description = description, CreatedAt = _clockService.Now }; // At the end of the bracket DOTNET will // dispose the connection automaticly using (var dbContext = new CrashCourseDBContext(_configuration.GetConnectionString("cnx"))) { dbContext.Database.EnsureCreated(); dbContext.Add(model); dbContext.SaveChanges(); } return(model.To()); }