Refactoring
* refactoring * fixes * messages * new interface
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user