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

52 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace COA.EnterpriseServices.DataAccess.QuickBase
{
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
{
public bool Add(T item)
{
var fieldData = GetFieldData(item);
// use fieldData to create mapped data to push to quickbase API
return true;
}
public bool Update(T item)
{
throw new NotImplementedException();
}
public T Get(int id)
{
// we'll never get data from QB
return null;
}
public ICollection<T> Get(Expression<Func<T, bool>> query)
{
// 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);
}
}
}
}
}