Files
raven/server/AyaNova/biz/EventLogProcessor.cs
2018-08-28 00:03:06 +00:00

86 lines
2.7 KiB
C#

using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Util;
namespace AyaNova.Biz
{
internal static class EventLogProcessor
{
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("EventLogProcessor");
/// <summary>
/// Add an entry to the log
/// </summary>
/// <param name="newEvent"></param>
/// <param name="ct"></param>
/// <returns></returns>
internal static void AddEntry(Event newEvent, AyContext ct)
{
ct.Event.Add(newEvent);
ct.SaveChanges();
}
/// <summary>
/// Handle delete
/// remove all prior entries for object, add one deleted entry
/// </summary>
/// <param name="userId"></param>
/// <param name="ayType"></param>
/// <param name="ayId"></param>
/// <param name="textra"></param>
/// <param name="ct"></param>
internal static void DeleteObject(long userId, AyaType ayType, long ayId, string textra, AyContext ct)
{
ct.Database.ExecuteSqlCommand($"delete from aevent where aytype = {ayType} and ayid={ayId}");
ct.Event.Add(new Event(userId, ayId, ayType, AyaEvent.Deleted, textra));
ct.SaveChanges();
}
/// <summary>
/// Get the event log for a specified object
/// </summary>
/// <param name="ayId"></param>
/// <param name="userLocaleId"></param>
/// <param name="ct"></param>
/// <returns></returns>
internal static async Task<string> GetLogForObject(long ayId, long userLocaleId, AyContext ct)
{
var items = await ct.Event
.Where(m => m.AyId == ayId)
.OrderBy(m => m.Created)
.ToListAsync();
AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param = new Api.Controllers.LocaleController.LocaleSubsetParam();
param.LocaleId = userLocaleId;
param.Keys.AddRange(new string[] { "CommonCreated", "Delete","Modified","Retrieved" });
var LT = LocaleBiz.GetSubsetStatic(param);
//Have list of locales
return null;
}
internal static Task<string> GetLogForUser(long ayId, long userLocaleId, AyContext ct)
{
throw new NotImplementedException();
}
/////////////////////////////////////////////////////////////////////
}//eoc
}//eons