Exemple #1
0
 public async Task <ActionResult <CheckValueResult> > CheckForDupes(string table, string field, string value, string narrative = "Title")
 {
     return(await Task.Run(() => {
         try {
             var p = new Dictionary <string, object>();
             p.Add("field", value);
             var sql = $"SELECT {field} AS Value, {narrative} AS ResponseMessage FROM {table} WHERE {field} = @field";
             var result = _context.CollectionFromSql(sql, p).FirstOrDefault();
             if (result != null)
             {
                 return Ok(new CheckValueResult {
                     IsValid = false,
                     Value = value,
                     ResponseMessage = result.ResponseMessage
                 });
             }
         } catch (Exception ex) {
             _logger.LogError($"Error checking for dupes\n{ex.Message}\n\tTable: {table}\n\tField: {field}\n\tValue: {value}\n\tNarrative: {narrative}");
         }
         return Ok(new CheckValueResult {
             Value = value,
             IsValid = true,
             ResponseMessage = "No duplicates found"
         });
     }));
 }