2020-10-15 17:47:44 +00:00
|
|
|
|
using COA.PartnerApis.QuickBase;
|
|
|
|
|
using System;
|
2020-10-14 01:24:27 +00:00
|
|
|
|
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
|
|
|
|
{
|
2020-10-15 17:47:44 +00:00
|
|
|
|
private readonly QuickBaseApiClient client;
|
|
|
|
|
|
|
|
|
|
public QuickBaseDataAccess(QuickBaseApiClient client)
|
|
|
|
|
{
|
|
|
|
|
this.client = client;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-14 01:24:27 +00:00
|
|
|
|
public bool Add(T item)
|
|
|
|
|
{
|
2020-10-16 02:03:30 +00:00
|
|
|
|
var record = RecordMapRegistry.GetRecord(item);
|
2020-10-15 17:47:44 +00:00
|
|
|
|
|
2020-10-16 02:03:30 +00:00
|
|
|
|
var result = client.AddRecord(record.Table, record.FieldIds);
|
2020-10-14 12:35:14 +00:00
|
|
|
|
|
2020-10-16 00:50:55 +00:00
|
|
|
|
return result.Success;
|
2020-10-14 01:24:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Update(T item)
|
|
|
|
|
{
|
2020-10-16 02:03:30 +00:00
|
|
|
|
var record = RecordMapRegistry.GetRecord(item);
|
2020-10-16 00:47:32 +00:00
|
|
|
|
|
2020-10-16 02:03:30 +00:00
|
|
|
|
var result = client.EditRecord(item.Id, record.Table, record.FieldIds);
|
2020-10-16 00:50:55 +00:00
|
|
|
|
|
|
|
|
|
return result.Success;
|
2020-10-15 11:07:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-10-16 03:05:21 +00:00
|
|
|
|
|
|
|
|
|
public ICollection<T> Raw(string command, params object[] parameters)
|
|
|
|
|
{
|
|
|
|
|
// not supported
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2020-10-14 01:24:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|