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");
///
/// Add an entry to the log
///
///
///
///
internal static void AddEntry(Event newEvent, AyContext ct)
{
ct.Event.Add(newEvent);
ct.SaveChanges();
}
///
/// Handle delete
/// remove all prior entries for object, add one deleted entry
///
///
///
///
///
///
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();
}
///
/// Get the event log for a specified object
///
///
///
///
///
internal static async Task GetLogForObject(long ayId, long userLocaleId, AyContext ct)
{
var items = await ct.Event
.Where(m => m.AyId == ayId)
.OrderBy(m => m.Created)
.ToListAsync();
if (items.Count == 0)
{
return "";
}
AyaNova.Api.Controllers.LocaleController.LocaleSubsetParam param = new Api.Controllers.LocaleController.LocaleSubsetParam();
param.LocaleId = userLocaleId;
param.Keys.AddRange(new string[] { "CommonCreated", "Delete", "Modified", "Retrieved" });
//TODO: add all the keys from all the events in AyaEvent
//Attachment, Created instead of AttachmentCreate, or is it attached?
var LT = await LocaleBiz.GetSubsetStatic(param);
//Have list of locales and list of ops, now make it into a readable text display and return it
System.Text.StringBuilder SbReturn = new System.Text.StringBuilder();
foreach (Event ev in items)
{
SbReturn.AppendLine(BuildLogEntry(ev, LT));
}
return SbReturn.ToString();
}
internal static Task GetLogForUser(long ayId, long userLocaleId, AyContext ct)
{
throw new NotImplementedException();
}
internal static string BuildLogEntry(Event ev, List> lt)
{
return ":";
}
/////////////////////////////////////////////////////////////////////
}//eoc
}//eons