public OperationResult<bool> Save(API.CurrentConsumption item) { return DbServiceHelper.InTryCatch(() => { SaveItem(item, Context.CurrentConsumptions); Context.SaveChanges(); return true; }); }
void SaveItem(API.CurrentConsumption item, IEnumerable<CurrentConsumption> tableItems) { bool isNew = false; var tableItem = tableItems.FirstOrDefault(x => x.UID == item.UID); if (tableItem == null) { tableItem = new CurrentConsumption { UID = item.UID }; isNew = true; } tableItem.AlsUID = item.AlsUID; tableItem.Current = item.Current; tableItem.DateTime = item.DateTime.CheckDate(); if (isNew) Context.CurrentConsumptions.Add(tableItem); }
public OperationResult<List<API.CurrentConsumption>> Get(API.CurrentConsumptionFilter filter) { return DbServiceHelper.InTryCatch(() => { var result = from tableItem in Context.CurrentConsumptions where tableItem.AlsUID == filter.AlsUID && tableItem.DateTime >= filter.StartDateTime && tableItem.DateTime <= filter.EndDateTime select new API.CurrentConsumption { UID = tableItem.UID, AlsUID = tableItem.AlsUID, Current = tableItem.Current, DateTime = tableItem.DateTime }; return result.ToList(); }); }