diff --git a/server/AyaNova/Controllers/TagGroupController.cs b/server/AyaNova/Controllers/TagGroupController.cs index afe409d2..84e96eda 100644 --- a/server/AyaNova/Controllers/TagGroupController.cs +++ b/server/AyaNova/Controllers/TagGroupController.cs @@ -71,7 +71,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); var o = await biz.GetAsync(id); @@ -119,7 +119,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); ApiPagedResponse pr = await biz.GetPickListAsync(Url, nameof(TagGroupPickList), pagingOptions, q); return Ok(new ApiOkWithPagingResponse(pr)); @@ -154,7 +154,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); var l = await biz.GetTagsInGroupPickListAsync(id); return Ok(new ApiOkResponse(l)); @@ -188,7 +188,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); //Create and validate TagGroup o = await biz.CreateAsync(inObj.Name); @@ -249,7 +249,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); if (!biz.Put(oFromDb, oIn)) { @@ -307,7 +307,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); var oFromDb = await ct.TagGroup.SingleOrDefaultAsync(m => m.Id == id); @@ -384,7 +384,7 @@ namespace AyaNova.Api.Controllers } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); if (!biz.Delete(dbObj)) { @@ -413,61 +413,31 @@ namespace AyaNova.Api.Controllers public async Task TagObject([FromBody] TagMapGroupInfo inObj) { if (!serverState.IsOpen) - { return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); - } //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.TagMap)) - { return StatusCode(401, new ApiNotAuthorizedResponse()); - } //Rights to parent taggable object? if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, inObj.TagToObjectType)) - { return StatusCode(401, new ApiNotAuthorizedResponse()); - } if (!ModelState.IsValid) - { return BadRequest(new ApiErrorResponse(ModelState)); - } //Instantiate the business object handler - TagGroupBiz biz = new TagGroupBiz(ct, UserIdFromContext.Id(HttpContext.Items), UserRolesFromContext.Roles(HttpContext.Items)); + TagGroupBiz biz = TagGroupBiz.GetBiz(ct, HttpContext); //Create and return list List l = await biz.TagObject(inObj); - if (l == null) - { - //error return return BadRequest(new ApiErrorResponse(biz.Errors)); - } else - { - //save and success return - await ct.SaveChangesAsync(); - - //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)); - } } - - private bool TagGroupExists(long id) - { - return ct.TagGroup.Any(e => e.Id == id); - } - - - //------------ - - - } -} \ No newline at end of file + }//eoc +}//eons \ No newline at end of file diff --git a/server/AyaNova/biz/TagGroupBiz.cs b/server/AyaNova/biz/TagGroupBiz.cs index 4eb96a1f..a1b43c27 100644 --- a/server/AyaNova/biz/TagGroupBiz.cs +++ b/server/AyaNova/biz/TagGroupBiz.cs @@ -23,17 +23,29 @@ namespace AyaNova.Biz public bool V7ValidationImportMode { get; set; } - internal TagGroupBiz(AyContext dbcontext, long currentUserId, AuthorizationRoles userRoles) + internal TagGroupBiz(AyContext dbcontext, long currentUserId, long userLocaleId, AuthorizationRoles userRoles) { ct = dbcontext; UserId = currentUserId; + UserLocaleId = userLocaleId; CurrentUserRoles = userRoles; - BizType=AyaType.TagGroup; + BizType = AyaType.TagGroup; V7ValidationImportMode = false;//default } + internal static TagGroupBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext) + { + return new TagGroupBiz(ct, UserIdFromContext.Id(httpContext.Items), UserLocaleIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items)); + } + //////////////////////////////////////////////////////////////////////////////////////////////// + //EXISTS + internal async Task ExistsAsync(long id) + { + return await ct.TagGroup.AnyAsync(e => e.Id == id); + } + //////////////////////////////////////////////////////////////////////////////////////////////// //CREATE @@ -238,6 +250,9 @@ namespace AyaNova.Biz } await ct.SaveChangesAsync(); + //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 ReturnObject; }