From 0f9ac2600c5ee5b8411d2cad1d93c4d971e92eba Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 4 Oct 2018 00:16:17 +0000 Subject: [PATCH] --- devdocs/todo.txt | 1 + .../AyaNova/Controllers/LocaleController.cs | 8 +++--- server/AyaNova/Controllers/TagController.cs | 16 ++++++----- .../AyaNova/Controllers/TagGroupController.cs | 12 ++++---- server/AyaNova/Controllers/UserController.cs | 14 ++++++---- .../Controllers/UserOptionsController.cs | 4 +-- .../AyaNova/Controllers/WidgetController.cs | 12 ++++---- server/AyaNova/biz/BizObject.cs | 28 +++++++++++++------ server/AyaNova/biz/IBizObject.cs | 12 ++------ server/AyaNova/biz/ImportAyaNova7Biz.cs | 13 +++++---- server/AyaNova/biz/JobOperationsBiz.cs | 11 +++----- server/AyaNova/biz/LocaleBiz.cs | 26 ++++++++--------- server/AyaNova/biz/TagBiz.cs | 12 ++++---- server/AyaNova/biz/TagGroupBiz.cs | 21 +++++++------- server/AyaNova/biz/TagGroupMapBiz.cs | 14 ++++------ server/AyaNova/biz/TagMapBiz.cs | 13 ++++----- server/AyaNova/biz/TrialBiz.cs | 13 +++------ server/AyaNova/biz/UserBiz.cs | 14 ++++------ server/AyaNova/biz/UserOptionsBiz.cs | 19 ++++++------- server/AyaNova/biz/WidgetBiz.cs | 9 ++---- 20 files changed, 127 insertions(+), 145 deletions(-) diff --git a/devdocs/todo.txt b/devdocs/todo.txt index d340b361..a2754d55 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -50,6 +50,7 @@ IMMEDIATE ITEMS: - Delete children in User object: I don't like it this way, the children would all be common to another biz object so instead I would like to see it call the other object, not directly issue sql changes (right now the user deletes the tag maps directly, this is just wrong) - NAMING is it dbObj, o, inObj? Go through and consistivize + - Widgetcontroller and UserController POST, move check for authorized rights into biz object - Auto visible id number assigning code - Give widgets a visible ID number scheme and add to tests diff --git a/server/AyaNova/Controllers/LocaleController.cs b/server/AyaNova/Controllers/LocaleController.cs index a66745ed..62fd9ea2 100644 --- a/server/AyaNova/Controllers/LocaleController.cs +++ b/server/AyaNova/Controllers/LocaleController.cs @@ -187,7 +187,7 @@ namespace AyaNova.Api.Controllers await ct.SaveChangesAsync(); //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, o.Id, AyaType.Locale, AyaEvent.Created), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.Locale, AyaEvent.Created), ct); await ct.SaveChangesAsync(); return CreatedAtAction("GetLocale", new { id = o.Id }, new ApiCreatedResponse(o)); @@ -247,7 +247,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oDbParent.Id, AyaType.Locale, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oDbParent.Id, AyaType.Locale, AyaEvent.Modified), ct); try { @@ -317,7 +317,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oFromDb.Id, AyaType.Locale, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oFromDb.Id, AyaType.Locale, AyaEvent.Modified), ct); try { @@ -387,7 +387,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(biz.Errors)); } //Log - EventLogProcessor.DeleteObject(biz.userId, AyaType.Locale, dbObj.Id, dbObj.Name, ct); + EventLogProcessor.DeleteObject(biz.UserId, AyaType.Locale, dbObj.Id, dbObj.Name, ct); await ct.SaveChangesAsync(); //Delete children / attached objects diff --git a/server/AyaNova/Controllers/TagController.cs b/server/AyaNova/Controllers/TagController.cs index bcadc93d..a7eed5b0 100644 --- a/server/AyaNova/Controllers/TagController.cs +++ b/server/AyaNova/Controllers/TagController.cs @@ -141,8 +141,11 @@ namespace AyaNova.Api.Controllers return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); } + //Instantiate the business object handler + TagBiz biz = new TagBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner - if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, AyaType.Tag)) + if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, TagBiz.BizType)) { return StatusCode(401, new ApiNotAuthorizedResponse()); } @@ -152,8 +155,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } - //Instantiate the business object handler - TagBiz biz = new TagBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + //Create and validate Tag o = await biz.CreateAsync(inObj.Name); @@ -169,7 +171,7 @@ namespace AyaNova.Api.Controllers await ct.SaveChangesAsync(); //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, o.Id, AyaType.Tag, AyaEvent.Created), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.Tag, AyaEvent.Created), ct); await ct.SaveChangesAsync(); return CreatedAtAction("GetTag", new { id = o.Id }, new ApiCreatedResponse(o)); @@ -222,7 +224,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oFromDb.Id, AyaType.Tag, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oFromDb.Id, AyaType.Tag, AyaEvent.Modified), ct); try { @@ -294,7 +296,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oFromDb.Id, AyaType.Tag, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oFromDb.Id, AyaType.Tag, AyaEvent.Modified), ct); try { @@ -407,7 +409,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(biz.Errors)); } //Log - EventLogProcessor.DeleteObject(biz.userId, AyaType.Tag, dbObj.Id, dbObj.Name, ct); + EventLogProcessor.DeleteObject(biz.UserId, AyaType.Tag, dbObj.Id, dbObj.Name, ct); await ct.SaveChangesAsync(); diff --git a/server/AyaNova/Controllers/TagGroupController.cs b/server/AyaNova/Controllers/TagGroupController.cs index 1f24bb61..afe409d2 100644 --- a/server/AyaNova/Controllers/TagGroupController.cs +++ b/server/AyaNova/Controllers/TagGroupController.cs @@ -204,7 +204,7 @@ namespace AyaNova.Api.Controllers await ct.SaveChangesAsync(); //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, o.Id, AyaType.TagGroup, AyaEvent.Created), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.TagGroup, AyaEvent.Created), ct); await ct.SaveChangesAsync(); return CreatedAtAction("GetTagGroup", new { id = o.Id }, new ApiCreatedResponse(o)); @@ -257,7 +257,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oFromDb.Id, AyaType.TagGroup, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oFromDb.Id, AyaType.TagGroup, AyaEvent.Modified), ct); try { @@ -329,7 +329,7 @@ namespace AyaNova.Api.Controllers } //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, oFromDb.Id, AyaType.TagGroup, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, oFromDb.Id, AyaType.TagGroup, AyaEvent.Modified), ct); try { @@ -391,7 +391,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(biz.Errors)); } //Log - EventLogProcessor.DeleteObject(biz.userId, AyaType.TagGroup, dbObj.Id, dbObj.Name, ct); + EventLogProcessor.DeleteObject(biz.UserId, AyaType.TagGroup, dbObj.Id, dbObj.Name, ct); await ct.SaveChangesAsync(); @@ -452,8 +452,8 @@ namespace AyaNova.Api.Controllers //BIZLOG: Not going to log this for now, it's too common an operation and would require bringing in more info. If decide to implement should log the parent object with text of tag instead //and don't forget about import from v7 as well - - return Ok(new ApiOkResponse(l)); + + return Ok(new ApiOkResponse(l)); } } diff --git a/server/AyaNova/Controllers/UserController.cs b/server/AyaNova/Controllers/UserController.cs index d2ad55a1..3037e1c3 100644 --- a/server/AyaNova/Controllers/UserController.cs +++ b/server/AyaNova/Controllers/UserController.cs @@ -80,7 +80,7 @@ namespace AyaNova.Api.Controllers { return NotFound(new ApiErrorResponse(ApiErrorCode.NOT_FOUND)); } - + return Ok(new ApiOkResponse(o)); } @@ -297,6 +297,9 @@ namespace AyaNova.Api.Controllers return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); } + //Instantiate the business object handler + UserBiz biz = UserBiz.GetBiz(ct, HttpContext); + //If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, UserBiz.BizType)) { @@ -308,8 +311,7 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } - //Instantiate the business object handler - UserBiz biz = UserBiz.GetBiz(ct, HttpContext); + //Create and validate User o = await biz.CreateAsync(inObj); @@ -354,6 +356,9 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } + //Instantiate the business object handler + UserBiz biz = UserBiz.GetBiz(ct, HttpContext); + var dbObj = await ct.User.SingleOrDefaultAsync(m => m.Id == id); if (dbObj == null) { @@ -365,8 +370,7 @@ namespace AyaNova.Api.Controllers return StatusCode(401, new ApiNotAuthorizedResponse()); } - //Instantiate the business object handler - UserBiz biz = UserBiz.GetBiz(ct, HttpContext); + if (!biz.Delete(dbObj)) { return BadRequest(new ApiErrorResponse(biz.Errors)); diff --git a/server/AyaNova/Controllers/UserOptionsController.cs b/server/AyaNova/Controllers/UserOptionsController.cs index ec382de9..728c6299 100644 --- a/server/AyaNova/Controllers/UserOptionsController.cs +++ b/server/AyaNova/Controllers/UserOptionsController.cs @@ -136,7 +136,7 @@ namespace AyaNova.Api.Controllers try { //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct); await ct.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) @@ -207,7 +207,7 @@ namespace AyaNova.Api.Controllers try { //Log - EventLogProcessor.AddEntryToContextNoSave(new Event(biz.userId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(biz.UserId, o.Id, AyaType.UserOptions, AyaEvent.Modified), ct); await ct.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) diff --git a/server/AyaNova/Controllers/WidgetController.cs b/server/AyaNova/Controllers/WidgetController.cs index 85430ec1..59c75048 100644 --- a/server/AyaNova/Controllers/WidgetController.cs +++ b/server/AyaNova/Controllers/WidgetController.cs @@ -297,6 +297,9 @@ namespace AyaNova.Api.Controllers return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); } + //Instantiate the business object handler + WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); + //If a user has change roles, or editOwnRoles then they can create, true is passed for isOwner since they are creating so by definition the owner if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, WidgetBiz.BizType)) { @@ -308,9 +311,6 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } - //Instantiate the business object handler - WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); - //Create and validate Widget o = await biz.CreateAsync(inObj); @@ -352,6 +352,9 @@ namespace AyaNova.Api.Controllers return BadRequest(new ApiErrorResponse(ModelState)); } + //Instantiate the business object handler + WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); + var dbObj = await ct.Widget.SingleOrDefaultAsync(m => m.Id == id); if (dbObj == null) { @@ -363,9 +366,6 @@ namespace AyaNova.Api.Controllers return StatusCode(401, new ApiNotAuthorizedResponse()); } - //Instantiate the business object handler - WidgetBiz biz = WidgetBiz.GetBiz(ct, HttpContext); - if (!biz.Delete(dbObj)) { return BadRequest(new ApiErrorResponse(biz.Errors)); diff --git a/server/AyaNova/biz/BizObject.cs b/server/AyaNova/biz/BizObject.cs index e9e0055e..39d4bf91 100644 --- a/server/AyaNova/biz/BizObject.cs +++ b/server/AyaNova/biz/BizObject.cs @@ -16,15 +16,24 @@ namespace AyaNova.Biz public BizObject() { - + } - #region Roles - - public AuthorizationRoles CurrentUserRoles { get; set; } - #endregion roles + + + #region common props + + internal static AyaType BizType { get; set; } + internal AyaNova.Models.AyContext ct { get; set; } + internal long UserId { get; set; } + internal long UserLocaleId { get; set; } + internal AuthorizationRoles CurrentUserRoles { get; set; } + + #endregion + + #region Error handling private readonly List _errors = new List(); @@ -35,7 +44,7 @@ namespace AyaNova.Biz public bool HasErrors => _errors.Any(); - + public void AddvalidationError(ValidationError validationError) { _errors.Add(validationError); @@ -63,9 +72,10 @@ namespace AyaNova.Biz sb.AppendLine("Validation errors:"); foreach (ValidationError e in _errors) { - var msg=e.Message; - if(string.IsNullOrWhiteSpace(msg)){ - msg=e.ErrorType.ToString(); + var msg = e.Message; + if (string.IsNullOrWhiteSpace(msg)) + { + msg = e.ErrorType.ToString(); } sb.AppendLine($"Target: {e.Target} error: {msg}"); } diff --git a/server/AyaNova/biz/IBizObject.cs b/server/AyaNova/biz/IBizObject.cs index a69f9646..52b3d95d 100644 --- a/server/AyaNova/biz/IBizObject.cs +++ b/server/AyaNova/biz/IBizObject.cs @@ -14,14 +14,6 @@ namespace AyaNova.Biz //https://stackoverflow.com/questions/36330981/is-the-validationresult-class-suitable-when-validating-the-state-of-an-object - - /// - /// Roles of current user - /// - /// - AuthorizationRoles CurrentUserRoles { get; set; } - - /// /// Contains list of errors /// @@ -38,7 +30,7 @@ namespace AyaNova.Biz /// bool PropertyHasErrors(string propertyName); - + /// @@ -47,7 +39,7 @@ namespace AyaNova.Biz /// /// /// - void AddError(ValidationErrorType errorType, string propertyName=null, string errorMessage=null); + void AddError(ValidationErrorType errorType, string propertyName = null, string errorMessage = null); /// /// diff --git a/server/AyaNova/biz/ImportAyaNova7Biz.cs b/server/AyaNova/biz/ImportAyaNova7Biz.cs index 50af1628..02f88bf4 100644 --- a/server/AyaNova/biz/ImportAyaNova7Biz.cs +++ b/server/AyaNova/biz/ImportAyaNova7Biz.cs @@ -18,16 +18,17 @@ namespace AyaNova.Biz internal class ImportAyaNova7Biz : BizObject, IJobObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; + // private readonly AyContext ct; + // public readonly long userId; + // private readonly AuthorizationRoles userRoles; - internal ImportAyaNova7Biz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal ImportAyaNova7Biz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.AyaNova7Import; } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/server/AyaNova/biz/JobOperationsBiz.cs b/server/AyaNova/biz/JobOperationsBiz.cs index 8e08f605..8d3dc1f8 100644 --- a/server/AyaNova/biz/JobOperationsBiz.cs +++ b/server/AyaNova/biz/JobOperationsBiz.cs @@ -18,16 +18,13 @@ namespace AyaNova.Biz internal class JobOperationsBiz : BizObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; - - internal JobOperationsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal JobOperationsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType=AyaType.JobOperations; } diff --git a/server/AyaNova/biz/LocaleBiz.cs b/server/AyaNova/biz/LocaleBiz.cs index 1f4ae55a..be640438 100644 --- a/server/AyaNova/biz/LocaleBiz.cs +++ b/server/AyaNova/biz/LocaleBiz.cs @@ -18,16 +18,14 @@ namespace AyaNova.Biz internal class LocaleBiz : BizObject, IImportAyaNova7Object { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; public bool SeedOrImportRelaxedRulesMode { get; set; } - internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal LocaleBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.Locale; SeedOrImportRelaxedRulesMode = false;//default } @@ -55,9 +53,9 @@ namespace AyaNova.Biz //replicate the source to a new dest and save Locale NewLocale = new Locale(); NewLocale.Name = inObj.Name; - NewLocale.OwnerId = this.userId; + NewLocale.OwnerId = UserId; NewLocale.Stock = false; - NewLocale.CjkIndex=false; + NewLocale.CjkIndex = false; foreach (LocaleItem i in SourceLocale.LocaleItems) { NewLocale.LocaleItems.Add(new LocaleItem() { Key = i.Key, Display = i.Display }); @@ -164,12 +162,12 @@ namespace AyaNova.Biz } - //Get the CJKIndex value for the locale specified - internal static async Task GetCJKIndex(long localeId, AyContext ct=null) + //Get the CJKIndex value for the locale specified + internal static async Task GetCJKIndex(long localeId, AyContext ct = null) { - if(ct==null) - ct = ServiceProviderProvider.DBContext; - var ret = await ct.Locale.Where(x => x.Id == localeId).Select(m=>m.CjkIndex).SingleOrDefaultAsync(); + if (ct == null) + ct = ServiceProviderProvider.DBContext; + var ret = await ct.Locale.Where(x => x.Id == localeId).Select(m => m.CjkIndex).SingleOrDefaultAsync(); return ret; } @@ -539,7 +537,7 @@ namespace AyaNova.Biz ct.SaveChanges(); //Log now that we have the Id, note that there is no source created / modified for this so just attributing to current userId - EventLogProcessor.AddEntryToContextNoSave(new Event(userId, l.Id, AyaType.Locale, AyaEvent.Created), ct); + EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, l.Id, AyaType.Locale, AyaEvent.Created), ct); ct.SaveChanges(); } diff --git a/server/AyaNova/biz/TagBiz.cs b/server/AyaNova/biz/TagBiz.cs index 37b7a7ec..b394c228 100644 --- a/server/AyaNova/biz/TagBiz.cs +++ b/server/AyaNova/biz/TagBiz.cs @@ -17,17 +17,15 @@ namespace AyaNova.Biz internal class TagBiz : BizObject, IImportAyaNova7Object { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; public bool SeedOrImportRelaxedRulesMode { get; set; } - internal TagBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal TagBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.Tag; SeedOrImportRelaxedRulesMode = false;//default } @@ -48,7 +46,7 @@ namespace AyaNova.Biz Tag outObj = new Tag() { Name = inObj, - OwnerId = userId + OwnerId = UserId }; diff --git a/server/AyaNova/biz/TagGroupBiz.cs b/server/AyaNova/biz/TagGroupBiz.cs index 513bc83c..4eb96a1f 100644 --- a/server/AyaNova/biz/TagGroupBiz.cs +++ b/server/AyaNova/biz/TagGroupBiz.cs @@ -17,17 +17,18 @@ namespace AyaNova.Biz internal class TagGroupBiz : BizObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; + // private readonly AyContext ct; + // public readonly long userId; + // private readonly AuthorizationRoles userRoles; public bool V7ValidationImportMode { get; set; } - internal TagGroupBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal TagGroupBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType=AyaType.TagGroup; V7ValidationImportMode = false;//default } @@ -48,7 +49,7 @@ namespace AyaNova.Biz TagGroup outObj = new TagGroup() { Name = inObj, - OwnerId = userId + OwnerId = UserId }; @@ -229,16 +230,16 @@ namespace AyaNova.Biz if (TagGroupTags.Count == 0) return ReturnObject; //Tag each one separately via TagMap which handles cases where object is already tagged with that tag etc - var MapBiz = new TagMapBiz(ct, userId, userRoles); + var MapBiz = new TagMapBiz(ct, UserId, CurrentUserRoles); foreach (NameIdItem TagInGroup in TagGroupTags) { - var TagMapItem = await MapBiz.CreateAsync(new TagMapInfo { TagId = TagInGroup.Id, TagToObjectId=inObj.TagToObjectId, TagToObjectType=inObj.TagToObjectType }); + var TagMapItem = await MapBiz.CreateAsync(new TagMapInfo { TagId = TagInGroup.Id, TagToObjectId = inObj.TagToObjectId, TagToObjectType = inObj.TagToObjectType }); ReturnObject.Add(TagInGroup); } await ct.SaveChangesAsync(); return ReturnObject; - + } diff --git a/server/AyaNova/biz/TagGroupMapBiz.cs b/server/AyaNova/biz/TagGroupMapBiz.cs index 4a97e2a1..6608a303 100644 --- a/server/AyaNova/biz/TagGroupMapBiz.cs +++ b/server/AyaNova/biz/TagGroupMapBiz.cs @@ -17,16 +17,14 @@ namespace AyaNova.Biz internal class TagGroupMapBiz : BizObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; + - - internal TagGroupMapBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal TagGroupMapBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.TagGroupMap; } @@ -55,7 +53,7 @@ namespace AyaNova.Biz { TagId = inObj.TagId, TagGroupId = inObj.TagGroupId, - OwnerId = userId + OwnerId = UserId }; diff --git a/server/AyaNova/biz/TagMapBiz.cs b/server/AyaNova/biz/TagMapBiz.cs index 249d7c2c..696fcefa 100644 --- a/server/AyaNova/biz/TagMapBiz.cs +++ b/server/AyaNova/biz/TagMapBiz.cs @@ -17,16 +17,13 @@ namespace AyaNova.Biz internal class TagMapBiz : BizObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; - - internal TagMapBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal TagMapBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.TagMap; } @@ -54,7 +51,7 @@ namespace AyaNova.Biz TagId = inObj.TagId, TagToObjectId = inObj.TagToObjectId, TagToObjectType = inObj.TagToObjectType, - OwnerId = userId + OwnerId = UserId }; diff --git a/server/AyaNova/biz/TrialBiz.cs b/server/AyaNova/biz/TrialBiz.cs index d2374da4..de15f6e3 100644 --- a/server/AyaNova/biz/TrialBiz.cs +++ b/server/AyaNova/biz/TrialBiz.cs @@ -21,17 +21,12 @@ namespace AyaNova.Biz /// internal class TrialBiz : BizObject, IJobObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; - // private readonly ApiServerState serverState; - - internal TrialBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal TrialBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; - //serverState = apiServerState;, ApiServerState apiServerState + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType=AyaType.TrialSeeder; } //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 5f5609ef..78f6f8fa 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -18,19 +18,15 @@ namespace AyaNova.Biz internal class UserBiz : BizObject, IJobObject, IImportAyaNova7Object { - public static AyaType BizType = AyaType.User; - private readonly AyContext ct; - public readonly long UserId; - public readonly long UserLocaleId; - private readonly AuthorizationRoles userRoles; + public bool SeedOrImportRelaxedRulesMode { get; set; } - internal UserBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) + internal UserBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles userRoles) { - ct = dbcontext; + ct = dbcontext; UserId = currentUserId; - UserLocaleId = userLocaleId; - userRoles = UserRoles; + CurrentUserRoles = userRoles; + BizType = AyaType.User; SeedOrImportRelaxedRulesMode = false;//default } diff --git a/server/AyaNova/biz/UserOptionsBiz.cs b/server/AyaNova/biz/UserOptionsBiz.cs index d0d46883..0b9740e6 100644 --- a/server/AyaNova/biz/UserOptionsBiz.cs +++ b/server/AyaNova/biz/UserOptionsBiz.cs @@ -16,16 +16,13 @@ namespace AyaNova.Biz internal class UserOptionsBiz : BizObject { - private readonly AyContext ct; - public readonly long userId; - private readonly AuthorizationRoles userRoles; - - internal UserOptionsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles UserRoles) + internal UserOptionsBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) { ct = dbcontext; - userId = currentUserId; - userRoles = UserRoles; + UserId = currentUserId; + CurrentUserRoles = userRoles; + BizType = AyaType.UserOptions; } @@ -67,10 +64,10 @@ namespace AyaNova.Biz { //Validate Patch is allowed if (!ValidateJsonPatch.Validate(this, objectPatch, "UserId")) return false; - + //Do the patching - objectPatch.ApplyTo(dbObj); - + objectPatch.ApplyTo(dbObj); + ct.Entry(dbObj).OriginalValues["ConcurrencyToken"] = concurrencyToken; Validate(dbObj); if (HasErrors) @@ -95,7 +92,7 @@ namespace AyaNova.Biz if (inObj.OwnerId == 0) AddError(ValidationErrorType.RequiredPropertyEmpty, "OwnerId"); - //OwnerId required + //OwnerId required if (inObj.UserId == 0) AddError(ValidationErrorType.RequiredPropertyEmpty, "UserId"); diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index effb2ca6..e326b139 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -16,19 +16,14 @@ namespace AyaNova.Biz internal class WidgetBiz : BizObject, IJobObject { - public static AyaType BizType = AyaType.Widget; - private readonly AyContext ct; - public readonly long UserId; - public readonly long UserLocaleId; - private readonly AuthorizationRoles userRoles; - internal WidgetBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles UserRoles) { ct = dbcontext; UserId = currentUserId; UserLocaleId = userLocaleId; - userRoles = UserRoles; + CurrentUserRoles = UserRoles; + BizType = AyaType.Widget; } internal static WidgetBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext)