This commit is contained in:
@@ -345,6 +345,9 @@ namespace AyaNova.Api.Controllers
|
||||
{
|
||||
//save and success return
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
//Only here process save event??
|
||||
EventLogProcessor.AddEntry();
|
||||
return CreatedAtAction("GetWidget", new { id = o.Id }, new ApiCreatedResponse(o));
|
||||
}
|
||||
}
|
||||
|
||||
35
server/AyaNova/biz/EventLogProcessor.cs
Normal file
35
server/AyaNova/biz/EventLogProcessor.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
|
||||
@@ -38,13 +38,44 @@ namespace AyaNova.Biz
|
||||
return null;
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
using (var trans = ct.Database.BeginTransaction())
|
||||
{
|
||||
// try
|
||||
// {
|
||||
//do stuff with widget
|
||||
Widget outObj = inObj;
|
||||
outObj.OwnerId = userId;
|
||||
//SearchHelper(break down text fields, save to db)
|
||||
//TagHelper(collection of tags??)
|
||||
await ct.Widget.AddAsync(outObj);
|
||||
|
||||
//Log creation
|
||||
Event ev = new Event();
|
||||
ev.AyEvent = AyaEvent.Created;
|
||||
ev.AyId = outObj.Id;
|
||||
ev.AyType = AyaType.Widget;
|
||||
ev.OwnerId = outObj.OwnerId;
|
||||
await ct.Event.AddAsync(ev);
|
||||
|
||||
|
||||
// Commit transaction if all commands succeed, transaction will auto-rollback
|
||||
// when disposed if either commands fails
|
||||
trans.Commit();
|
||||
|
||||
return outObj;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// throw ex;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace AyaNova.Models
|
||||
{
|
||||
public partial class AyContext : DbContext
|
||||
{
|
||||
public virtual DbSet<Event> Event { get; set; }
|
||||
public virtual DbSet<User> User { get; set; }
|
||||
public virtual DbSet<License> License { get; set; }
|
||||
public virtual DbSet<Widget> Widget { get; set; }
|
||||
|
||||
47
server/AyaNova/models/Event.cs
Normal file
47
server/AyaNova/models/Event.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using AyaNova.Biz;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AyaNova.Models
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Event log entry
|
||||
/// </summary>
|
||||
public partial class Event
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint ConcurrencyToken { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
[Required]
|
||||
public long OwnerId { get; set; }
|
||||
//-----------------------------------------
|
||||
[Required]
|
||||
public long AyId { get; set; }
|
||||
[Required]
|
||||
public AyaType AyType { get; set; }
|
||||
[Required]
|
||||
public AyaEvent AyEvent { get; set; }
|
||||
public string Textra { get; set; }
|
||||
|
||||
|
||||
public Event()
|
||||
{
|
||||
Created = System.DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public Event(long ownerId, long ayId, AyaType ayType, AyaEvent ayEvent, string textra = null)
|
||||
{
|
||||
Created = System.DateTime.UtcNow;
|
||||
OwnerId = ownerId;
|
||||
AyId = ayId;
|
||||
AyEvent = ayEvent;
|
||||
if (textra != null)
|
||||
{
|
||||
Textra = textra;
|
||||
}
|
||||
}
|
||||
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
@@ -11,7 +11,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
get
|
||||
{
|
||||
return "8.0.0-alpha.2018.6.6";
|
||||
return "8.0.0-alpha.2018.8.23";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user