70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using Step.Model.DatabaseModels;
|
|
using Step.Model.DTOModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Step.Database.Controllers
|
|
{
|
|
public class AlarmsController : IDisposable
|
|
{
|
|
private DatabaseContext dbCtx;
|
|
|
|
public AlarmsController()
|
|
{
|
|
// Initialize database context
|
|
dbCtx = new DatabaseContext();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public List<AlarmOccurrencesModel> GetPaginated(int page, int pageSize)
|
|
{
|
|
Stopwatch st = new Stopwatch();
|
|
st.Start();
|
|
DateTime l = DateTime.Parse("2013/01/01");
|
|
var a = dbCtx.AlarmOccurrences.Include("AlarmDescription").OrderBy(x => x.AlarmOccurrenceId)
|
|
.Where(x => x.TimeStamp < DateTime.Today && x.TimeStamp > l)
|
|
.Skip(page * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
|
|
Console.WriteLine(st.ElapsedMilliseconds);
|
|
|
|
return a;
|
|
}
|
|
|
|
|
|
public List<DTOAlarmHistoricModel> GetPaginatedWithFilter(int page, int pageSize, DateTime startDate, DateTime endDate, List<int> userIds)
|
|
{
|
|
var occurrences = dbCtx.AlarmOccurrences.Include("AlarmDescription").OrderBy(x => x.AlarmOccurrenceId)
|
|
.Where(x =>
|
|
x.TimeStamp >= startDate && x.TimeStamp <= endDate
|
|
// && userIds.Any( y => x.Users.Select(z => z.UserId).Any(z => z == y))
|
|
)
|
|
.Skip(page * pageSize)
|
|
.Take(pageSize)
|
|
.ToList();
|
|
|
|
//var ids = occurrences.Select(x => x.Id).ToList();
|
|
//var users = dbCtx.AlarmUsers.Where(x => ids.Contains(x.AlarmOccurrenceId) && userIds.Contains(x.UserId)).ToList();
|
|
|
|
return occurrences.Select(x => (DTOAlarmHistoricModel)x).ToList();
|
|
}
|
|
|
|
public void InsertList(List<AlarmOccurrencesModel> alarms)
|
|
{
|
|
dbCtx.AlarmOccurrences.AddRange(alarms);
|
|
|
|
dbCtx.SaveChanges();
|
|
}
|
|
}
|
|
}
|