Refactoring

* refactoring
* fixes
* messages
* new interface
This commit is contained in:
2019-01-18 23:22:03 +01:00
parent 1246116804
commit b7460cfd78
34 changed files with 746 additions and 665 deletions

View File

@@ -1,7 +1,10 @@
using LinqToDB;
using System;
using System.Linq;
using LinqToDB;
using LinqToDB.Data;
using LinqToDB.DataProvider;
using SeniorAssistant.Models;
using SeniorAssistant.Models.Data;
using SeniorAssistant.Models.Users;
namespace SeniorAssistant.Data
@@ -20,5 +23,37 @@ namespace SeniorAssistant.Data
public ITable<Patient> Patients => GetTable<Patient>();
public ITable<Notification> Notifications => GetTable<Notification>();
public ITable<Message> Messages => GetTable<Message>();
public T[] GetLastMessages<T>(ITable<T> table, string receiver, ref int numNotSeen, int max = 10)
where T : IHasMessage
{
var notSeen = (from t in table
where t.Receiver.Equals(receiver) && t.Seen == default
orderby t.Time descending
select t).Take(max).ToArray();
var messages = new T[max];
numNotSeen = notSeen.Length;
int i;
for (i = 0; i < numNotSeen; i++)
{
messages[i] = notSeen[i];
}
if (numNotSeen < max)
{
var messSeen = (from t in table
where t.Receiver.Equals(receiver) && t.Seen != default
orderby t.Time descending
select t).Take(max - numNotSeen).ToArray();
foreach (var m in messSeen)
{
messages[i] = m;
i++;
}
}
return messages;
}
}
}