COA.EnterpriseServices/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2020-10-14 01:24:27 +00:00
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace COA.EnterpriseServices.DataAccess.QuickBase
{
2020-10-14 12:35:14 +00:00
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
2020-10-14 01:24:27 +00:00
{
public bool Add(T item)
{
2020-10-14 12:35:14 +00:00
var fieldData = GetFieldData(item);
// use fieldData to create mapped data to push to quickbase API
2020-10-14 03:10:25 +00:00
return true;
2020-10-14 01:24:27 +00:00
}
public bool Update(T item)
{
var fieldData = GetFieldData(item);
2020-10-14 01:24:27 +00:00
return true;
}
2020-10-14 01:24:27 +00:00
public ICollection<T> Get(Expression<Func<T, bool>> query)
{
2020-10-14 12:35:14 +00:00
// we'll never get data from QB
return null;
}
private IEnumerable<KeyValuePair<int, object>> GetFieldData(T item)
{
var properties = item.GetType().GetProperties();
foreach (var property in properties)
{
var fieldId = FieldMapRegistry.GetFieldId(property);
var value = property.GetValue(item);
if (fieldId != null)
{
yield return new KeyValuePair<int, object>(fieldId.Value, value);
}
}
2020-10-14 01:24:27 +00:00
}
}
}