public async Task Create(DocumentEntity request) { // This would create a connection, open it, // begin a transaction and put the repositories on // the uow. //using (var uow = new UnitOfWork(connectionString)) //{ // var user = uow.Users.GetByUserName(userName); //} using (var connection = new MySqlConnection(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString)) { await connection.OpenAsync(); //var transaction = connection.BeginTransaction(); // Get the name of the logged in user from the controller. var userName = this.User.Identity.Name; // Get the user id of the logged in user from the database. var user = await new UserRepository(connection).GetByUserName(userName); var userId = user.UserId; // Set the created by to be the current user. request.CreatedBy = userId; // Set the created when to be now. request.CreatedWhen = DateTime.UtcNow; request.Title.ToString(); // Create the new document in the database. await connection.ExecuteAsync(@" INSERT INTO Document (Title, Body, CreatedWhen, CreatedBy) VALUES (@Title, @Body, @CreatedWhen, @CreatedBy); ", request); } }