From 40c0265dcb03ab95fbfd995a61f92e0937f9f822 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 26 Sep 2018 19:47:02 +0000 Subject: [PATCH] --- server/AyaNova/Controllers/UserController.cs | 6 +--- .../AyaNova/Controllers/WidgetController.cs | 12 +++---- server/AyaNova/biz/UserBiz.cs | 9 ++++- server/AyaNova/biz/WidgetBiz.cs | 34 +++++++++++++++---- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/server/AyaNova/Controllers/UserController.cs b/server/AyaNova/Controllers/UserController.cs index 1b4578d1..70b720ac 100644 --- a/server/AyaNova/Controllers/UserController.cs +++ b/server/AyaNova/Controllers/UserController.cs @@ -76,15 +76,11 @@ namespace AyaNova.Api.Controllers UserBiz biz = UserBiz.GetBiz(ct, HttpContext); var o = await biz.GetAsync(id); - if (o == null) { return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); } - - //Log - EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, UserBiz.BizType, AyaEvent.Retrieved), ct); - ct.SaveChanges(); + return Ok(new ApiOkResponse(o)); } diff --git a/server/AyaNova/Controllers/WidgetController.cs b/server/AyaNova/Controllers/WidgetController.cs index ca2d2ab1..350e3afb 100644 --- a/server/AyaNova/Controllers/WidgetController.cs +++ b/server/AyaNova/Controllers/WidgetController.cs @@ -85,9 +85,7 @@ namespace AyaNova.Api.Controllers return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); } - //Log - EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, WidgetBiz.BizType, AyaEvent.Retrieved), ct); - ct.SaveChanges(); + return Ok(new ApiOkResponse(o)); } @@ -209,7 +207,7 @@ namespace AyaNova.Api.Controllers try { //Log - EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct); + EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct); await ct.SaveChangesAsync(); Search.ProcessUpdatedObjectKeywords(ct, UserLocaleIdFromContext.Id(HttpContext.Items), o.Id, WidgetBiz.BizType, o.Name, o.Notes, o.Name); } @@ -286,7 +284,7 @@ namespace AyaNova.Api.Controllers try { //Log - EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct); + EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Modified), ct); await ct.SaveChangesAsync(); //this will save the context as part of it's operations @@ -354,7 +352,7 @@ namespace AyaNova.Api.Controllers await ct.SaveChangesAsync(); //Log now that we have the Id - EventLogProcessor.AddEntry(new Event(biz.userId, o.Id, WidgetBiz.BizType, AyaEvent.Created), ct); + EventLogProcessor.AddEntry(new Event(biz.UserId, o.Id, WidgetBiz.BizType, AyaEvent.Created), ct); await ct.SaveChangesAsync(); //this will save the context as part of it's operations @@ -412,7 +410,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.DeleteObject(biz.userId, WidgetBiz.BizType, dbObj.Id, dbObj.Name, ct); + EventLogProcessor.DeleteObject(biz.UserId, WidgetBiz.BizType, dbObj.Id, dbObj.Name, ct); await ct.SaveChangesAsync(); //This will directly execute and is not part of context for saving purposes diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 629d26a7..e5252076 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -100,7 +100,14 @@ namespace AyaNova.Biz internal async Task GetAsync(long fetchId) { //This is simple so nothing more here, but often will be copying to a different output object or some other ops - return await ct.User.SingleOrDefaultAsync(m => m.Id == fetchId); + var ret = await ct.User.SingleOrDefaultAsync(m => m.Id == fetchId); + if (ret != null) + { + //Log + EventLogProcessor.AddEntry(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct); + ct.SaveChanges(); + } + return ret; } //get many (paged) diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index ca014d4d..c79aede7 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -18,7 +18,7 @@ namespace AyaNova.Biz { public static AyaType BizType = AyaType.Widget; private readonly AyContext ct; - public readonly long userId; + public readonly long UserId; public readonly long UserLocaleId; private readonly AuthorizationRoles userRoles; @@ -26,7 +26,8 @@ namespace AyaNova.Biz internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) { ct = dbcontext; - userId = currentUserId; + UserId = currentUserId; + UserLocaleId = userLocaleId; userRoles = UserRoles; } @@ -52,10 +53,24 @@ namespace AyaNova.Biz { //do stuff with widget Widget outObj = inObj; - outObj.OwnerId = userId; + outObj.OwnerId = UserId; + - //TagHelper(collection of tags??) await ct.Widget.AddAsync(outObj); + + //save to get Id + await ct.SaveChangesAsync(); + + //Handle child and associated items + + //Log event + EventLogProcessor.AddEntry(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct); + await ct.SaveChangesAsync(); + + //SEARCH INDEXING + Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name); +HERE + return outObj; } @@ -67,8 +82,15 @@ namespace AyaNova.Biz //Get one internal async Task GetAsync(long fetchId) { - //This is simple so nothing more here, but often will be copying to a different output object or some other ops - return await ct.Widget.SingleOrDefaultAsync(m => m.Id == fetchId); + //This is simple so nothing more here, but often will be copying to a different output object or some other ops + var ret = await ct.Widget.SingleOrDefaultAsync(m => m.Id == fetchId); + if (ret != null) + { + //Log + EventLogProcessor.AddEntry(new Event(UserId, fetchId, BizType, AyaEvent.Retrieved), ct); + ct.SaveChanges(); + } + return ret; } //get many (paged)