public async Task <(bool, string)> PostAttachmentToRecord(string magazineCoverUrl, string table, string recordId) { AirtableAttachment attachment = new AirtableAttachment() { Url = magazineCoverUrl }; List <AirtableAttachment> attachmentList = new List <AirtableAttachment> { attachment }; using (AirtableBase airtableBase = new AirtableBase(ApiKey, BaseId)) { var fields = new Fields(); fields.AddField("Cover", attachmentList); var task = airtableBase.UpdateRecord(table, fields, recordId); var response = await task; if (response.Success) { return(true, null); } else if (response.AirtableApiError is AirtableApiException) { return(false, response.AirtableApiError.GetBaseException().Message); } else { return(false, "Unknown error"); } } }
public async Task <AirtableCreateUpdateReplaceRecordResponse> UpdateRecord(RecordUpdateRequest req) { using (AirtableBase airtableBase = new AirtableBase(appKey, baseId)) { var fields = new Fields(); fields.AddField("Title", req.Title); fields.AddField("Priority", req.Priority); fields.AddField("Status", req.Status); fields.AddField("Due Date", req.DueDate); AirtableCreateUpdateReplaceRecordResponse response = await airtableBase.UpdateRecord(tableName, fields, req.Id.ToString()); //var response = await task; if (!response.Success) { string errorMessage = null; if (response.AirtableApiError is AirtableApiException) { errorMessage = response.AirtableApiError.ErrorMessage; } else { errorMessage = "Unknown error"; } // Report errorMessage } else { var record = response.Record; // Do something with your updated record. } return(response); } }
public async Task UpdateWaifus(WaifuObject data) { Fields field = new Fields(); field.AddField("Waifus", data.Waifus); field.AddField("Feeds", data.Feeds); field.AddField("Levels", data.Levels); field.AddField("Lewds", data.Lewds); field.AddField("LastModifiedHour", data.LastModifiedHour); await Base.UpdateRecord(table, field, data.RecordId); }
public async Task UpdateAfk(AfkObject data) { Fields field = new Fields(); field.AddField("isAfk", data.IsAfk); field.AddField("message", data.Message); var result = await Base.UpdateRecord(table, field, data.RecordId); Console.WriteLine($"Update AFK Result: {result.Success}"); Console.WriteLine($"Error: {result.AirtableApiError}"); }
public async Task UpdateCooldowns(CooldownObject data) { Fields field = new Fields(); field.AddField("Daily", data.Daily); field.AddField("Bless", data.Bless); field.AddField("Pluck", data.Pluck); field.AddField("Vote", data.Vote); field.AddField("Work", data.Work); field.AddField("Thievery", data.Thievery); await Base.UpdateRecord(table, field, data.RecordId); }
public static async Task SetFriendCodeAsync(SdlPlayer player, string code) { using (AirtableBase airtableBase = new AirtableBase(Globals.BotSettings.AppKey, Globals.BotSettings.BaseId)) { Fields fields = new Fields(); fields.AddField("Friend Code", code); AirtableCreateUpdateReplaceRecordResponse response = await airtableBase.UpdateRecord("Draft Standings", fields, player.AirtableId, true); if (!response.Success) { Logger.Error(response.AirtableApiError.ErrorMessage); } } }
// public async Task UpdateRecordMethodAsync(AirtableBase airtableBase) { Task <AirtableCreateUpdateReplaceRecordResponse> task = airtableBase.UpdateRecord(tablename, fields, stringID, conversion); var response = await task; OutRecord = response.Record; if (response.AirtableApiError.ErrorMessage != null) { // Error reporting errorMessageString = response.AirtableApiError.ErrorMessage; } else { // Do something with the retrieved 'record' OutRecord = response.Record; } }
public async Task UpdateUserProfile(UserObject data) { Fields field = new Fields(); field.AddField("Disable", data.Disable); field.AddField("balance", data.Balance); field.AddField("xp", data.Xp); field.AddField("level", data.Level); field.AddField("votes", data.Votes); field.AddField("description", data.Description); field.AddField("background", data.Background); field.AddField("birthday", data.Birthday); field.AddField("marry", data.Marry); field.AddField("ownBgName", data.OwnBgNames); field.AddField("ownBgUrl", data.OwnBgUrl); field.AddField("weekly", data.Weekly); await Base.UpdateRecord(table, field, data.RecordId); }
public async Task <bool> UpdateRecord(string recordId, IDictionary <string, object> valuesToUpdate) { _logger.LogTrace($"{GetType()} - BEGIN {nameof(UpdateRecord)}"); using (AirtableBase airtableBase = new AirtableBase(_config.ApiKey, _config.DatabaseId)) { Fields f = new Fields(); foreach (KeyValuePair <string, object> kvp in valuesToUpdate) { f.AddField(kvp.Key, kvp.Value); } AirtableCreateUpdateReplaceRecordResponse res = await airtableBase.UpdateRecord(_config.TableName, f, recordId); if (res.Success) { return(true); } else { _logger.LogError(res.AirtableApiError, $"Une erreur est survenue pendant la mise à jour d'un enregistrement Airtable : {res.AirtableApiError.ErrorName} [{res.AirtableApiError.ErrorCode}] : {res.AirtableApiError.ErrorMessage}"); return(false); } } }
public static async Task PenalizePlayer(ulong discordId, int points, string notes) { AirtableRecord playerRecord = await GetPlayerRecord(discordId); using (AirtableBase airtableBase = new AirtableBase(Globals.BotSettings.AppKey, Globals.BotSettings.BaseId)) { Fields adjustmentsFields = new Fields(); adjustmentsFields.AddField("Player", playerRecord.Id); adjustmentsFields.AddField("Points", -points); adjustmentsFields.AddField("Notes", notes); Task <AirtableCreateUpdateReplaceRecordResponse> createRecordTask = airtableBase.CreateRecord("Adjustments", adjustmentsFields, true); AirtableCreateUpdateReplaceRecordResponse createRecordResponse = await createRecordTask; if (!createRecordResponse.Success) { string errorMessage = createRecordResponse.AirtableApiError != null ? createRecordResponse.AirtableApiError.ErrorMessage : "Unknown error"; SdlAirTableException exception = new SdlAirTableException( errorMessage, SdlAirTableException.AirtableErrorType.CommunicationError); Logger.Error(exception); throw exception; } AirtableRecord record = createRecordResponse.Record; if (!playerRecord.Fields.ContainsKey("Adjustments")) { playerRecord.Fields["Adjustments"] = new JArray(); } IEnumerable <JToken> updatedAdjustmentIds = ((JArray)playerRecord.Fields["Adjustments"]).Append(record.Id); Fields updatePlayerFields = new Fields(); updatePlayerFields.AddField("Adjustments", updatedAdjustmentIds.ToArray()); Task <AirtableCreateUpdateReplaceRecordResponse> updateRecordTask = airtableBase.UpdateRecord("Draft Standings", updatePlayerFields, playerRecord.Id, true); AirtableCreateUpdateReplaceRecordResponse updateRecordResponse = await updateRecordTask; if (!updateRecordResponse.Success) { string errorMessage = updateRecordResponse.AirtableApiError != null ? updateRecordResponse.AirtableApiError.ErrorMessage : "Unknown error"; SdlAirTableException exception = new SdlAirTableException( errorMessage, SdlAirTableException.AirtableErrorType.CommunicationError); Logger.Error(exception); throw exception; } } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string rotation = await new StreamReader(req.Body).ReadToEndAsync(); using (AirtableBase airtableBase = new AirtableBase( Environment.GetEnvironmentVariable("airtableApiKey"), Environment.GetEnvironmentVariable("airtableBaseId"))) { log.LogInformation("Airtable connection initialized."); var rotationNumber = int.Parse(new Regex(@"(^\d+)", RegexOptions.Multiline).Match(rotation).Groups[1].Value); var rotationStartDateString = new Regex(@" (\d{2}[A-Z]{3})").Match(rotation).Groups[1].Value; var rotationStartDate = monthConverter[rotationStartDateString.Substring(2, 3)] + "/" + int.Parse(rotationStartDateString.Substring(0, 2)) + "/" + DateTime.Now.Year; var rotationNumberOfAttendants = new Regex(@"([0-9]+) F\/A").Match(rotation).Groups[1].Value; log.LogInformation($"Parsed rotation #{rotationNumber}-{rotationStartDate}."); // Update rotation log.LogInformation("Updating rotation."); var rotationRecordId = req.Headers["Airtable-Record-Id"][0]; var rotationLookup = airtableBase.RetrieveRecord("Rotations", rotationRecordId).GetAwaiter().GetResult(); if (!rotationLookup.Success) { log.LogError(rotationLookup.AirtableApiError.ErrorMessage); return(new StatusCodeResult(500)); } log.LogInformation("Looked up rotation successfully."); var rotationFields = new Fields(); rotationFields.AddField("Rotation #", rotationNumber); rotationFields.AddField("Date", rotationStartDate); var rotationUpdate = airtableBase.UpdateRecord("People", rotationFields, rotationRecordId).GetAwaiter().GetResult(); if (!rotationUpdate.Success) { log.LogError(rotationUpdate.AirtableApiError.ErrorMessage); return(new StatusCodeResult(500)); } log.LogInformation("Updated rotation successfully."); // Add flight attendants for (int i = 0; i < int.Parse(rotationNumberOfAttendants); i++) { log.LogInformation($"Starting to process flight attendant {i}."); var flightAttendantRecord = new Regex($@"^{Convert.ToChar(65 + i)} 0([0-9]*) ([A-Za-z]*)([A-Za-z ]*)", RegexOptions.Multiline).Match(rotation); var faEmployeeId = int.Parse(flightAttendantRecord.Groups[1].Value); var faLookup = airtableBase.ListRecords("People", null, null, $"{{Employee ID}} = {faEmployeeId}").GetAwaiter().GetResult(); if (!faLookup.Success) { log.LogError(faLookup.AirtableApiError.ErrorMessage); return(new StatusCodeResult(500)); } log.LogInformation($"Looked up flight attendant {faLookup} successfully."); if (!faLookup.Records.Any()) { log.LogInformation("Adding flight attendant."); var fields = new Fields(); fields.AddField("Employee ID", faEmployeeId); fields.AddField("First name", flightAttendantRecord.Groups[2].Value); fields.AddField("Last name", flightAttendantRecord.Groups[3].Value); var result = airtableBase.CreateRecord("People", fields).GetAwaiter().GetResult(); if (!result.Success) { log.LogError(result.AirtableApiError.ErrorMessage); return(new StatusCodeResult(500)); } log.LogInformation("Added flight attendant successfully."); } else { log.LogInformation("Flight attendant already registered."); } } } return((ActionResult) new OkResult()); }