This commit is contained in:
2018-10-04 19:26:39 +00:00
parent 1c0400ca9f
commit 707e24291b
2 changed files with 27 additions and 42 deletions

View File

@@ -71,7 +71,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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); var o = await biz.GetAsync(id);
@@ -119,7 +119,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(TagGroupPickList), pagingOptions, q); ApiPagedResponse<NameIdItem> pr = await biz.GetPickListAsync(Url, nameof(TagGroupPickList), pagingOptions, q);
return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr)); return Ok(new ApiOkWithPagingResponse<NameIdItem>(pr));
@@ -154,7 +154,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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); var l = await biz.GetTagsInGroupPickListAsync(id);
return Ok(new ApiOkResponse(l)); return Ok(new ApiOkResponse(l));
@@ -188,7 +188,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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 //Create and validate
TagGroup o = await biz.CreateAsync(inObj.Name); TagGroup o = await biz.CreateAsync(inObj.Name);
@@ -249,7 +249,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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)) if (!biz.Put(oFromDb, oIn))
{ {
@@ -307,7 +307,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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); var oFromDb = await ct.TagGroup.SingleOrDefaultAsync(m => m.Id == id);
@@ -384,7 +384,7 @@ namespace AyaNova.Api.Controllers
} }
//Instantiate the business object handler //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)) if (!biz.Delete(dbObj))
{ {
@@ -413,61 +413,31 @@ namespace AyaNova.Api.Controllers
public async Task<IActionResult> TagObject([FromBody] TagMapGroupInfo inObj) public async Task<IActionResult> TagObject([FromBody] TagMapGroupInfo inObj)
{ {
if (!serverState.IsOpen) if (!serverState.IsOpen)
{
return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason)); 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 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)) if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, AyaType.TagMap))
{
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
}
//Rights to parent taggable object? //Rights to parent taggable object?
if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, inObj.TagToObjectType)) if (!Authorized.IsAuthorizedToCreate(HttpContext.Items, inObj.TagToObjectType))
{
return StatusCode(401, new ApiNotAuthorizedResponse()); return StatusCode(401, new ApiNotAuthorizedResponse());
}
if (!ModelState.IsValid) if (!ModelState.IsValid)
{
return BadRequest(new ApiErrorResponse(ModelState)); return BadRequest(new ApiErrorResponse(ModelState));
}
//Instantiate the business object handler //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 //Create and return list
List<NameIdItem> l = await biz.TagObject(inObj); List<NameIdItem> l = await biz.TagObject(inObj);
if (l == null) if (l == null)
{
//error return
return BadRequest(new ApiErrorResponse(biz.Errors)); return BadRequest(new ApiErrorResponse(biz.Errors));
}
else 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)); return Ok(new ApiOkResponse(l));
}
} }
private bool TagGroupExists(long id)
{
return ct.TagGroup.Any(e => e.Id == id);
}
//------------ //------------
}//eoc
}//eons
}
}

View File

@@ -23,17 +23,29 @@ namespace AyaNova.Biz
public bool V7ValidationImportMode { get; set; } 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; ct = dbcontext;
UserId = currentUserId; UserId = currentUserId;
UserLocaleId = userLocaleId;
CurrentUserRoles = userRoles; CurrentUserRoles = userRoles;
BizType=AyaType.TagGroup; BizType = AyaType.TagGroup;
V7ValidationImportMode = false;//default 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<bool> ExistsAsync(long id)
{
return await ct.TagGroup.AnyAsync(e => e.Id == id);
}
//////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE //CREATE
@@ -238,6 +250,9 @@ namespace AyaNova.Biz
} }
await ct.SaveChangesAsync(); 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; return ReturnObject;
} }