This commit is contained in:
@@ -15,7 +15,7 @@ using System.Collections.Generic;
|
|||||||
namespace AyaNova.Biz
|
namespace AyaNova.Biz
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class TagGroupBiz : BizObject, IImportAyaNova7Object
|
internal class TagGroupBiz : BizObject
|
||||||
{
|
{
|
||||||
private readonly AyContext ct;
|
private readonly AyContext ct;
|
||||||
public readonly long userId;
|
public readonly long userId;
|
||||||
@@ -241,181 +241,6 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
/// IMPORT v7 implementation
|
|
||||||
public async Task<bool> ImportV7Async(JObject j, List<ImportAyaNova7MapItem> importMap, Guid jobId)
|
|
||||||
{
|
|
||||||
//NO TASK TYPE, IT'S ALL THE SAME, KEEPING THIS FOR POSSIBLE FUTURE PURPOSES LIKE APPENDING OBJECT TYPE OR SOMETHING
|
|
||||||
string SourceType = j["V7_TYPE"].Value<string>();
|
|
||||||
switch (SourceType)
|
|
||||||
{
|
|
||||||
case "GZTW.AyaNova.BLL.Region":
|
|
||||||
case "GZTW.AyaNova.BLL.UnitModelCategory":
|
|
||||||
case "GZTW.AyaNova.BLL.UnitServiceType":
|
|
||||||
case "GZTW.AyaNova.BLL.WorkorderItemType":
|
|
||||||
case "GZTW.AyaNova.BLL.ClientGroup":
|
|
||||||
case "GZTW.AyaNova.BLL.WorkorderCategory":
|
|
||||||
case "GZTW.AyaNova.BLL.PartCategory":
|
|
||||||
case "GZTW.AyaNova.BLL.DispatchZone":
|
|
||||||
case "GZTW.AyaNova.BLL.ScheduleableUserGroup":
|
|
||||||
{
|
|
||||||
switch (j["IMPORT_TASK"].Value<string>())
|
|
||||||
{
|
|
||||||
case "main":
|
|
||||||
{
|
|
||||||
#region main import task
|
|
||||||
var NewTagGroupName = j["Name"].Value<string>();
|
|
||||||
|
|
||||||
var ShortTypeName = string.Empty;
|
|
||||||
switch (SourceType)
|
|
||||||
{
|
|
||||||
case "GZTW.AyaNova.BLL.Region":
|
|
||||||
ShortTypeName = "rgn";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.UnitModelCategory":
|
|
||||||
ShortTypeName = "unitmdlctgry";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.UnitServiceType":
|
|
||||||
ShortTypeName = "unitsvtyp";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.WorkorderItemType":
|
|
||||||
ShortTypeName = "woitemtyp";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.ClientGroup":
|
|
||||||
ShortTypeName = "clntgrp";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.WorkorderCategory":
|
|
||||||
ShortTypeName = "woctgry";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.PartCategory":
|
|
||||||
ShortTypeName = "prtctgry";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.DispatchZone":
|
|
||||||
ShortTypeName = "dspchzn";
|
|
||||||
break;
|
|
||||||
case "GZTW.AyaNova.BLL.ScheduleableUserGroup":
|
|
||||||
ShortTypeName = "schdusrgrp";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NewTagGroupName += "." + ShortTypeName;
|
|
||||||
var OldV7Id = new Guid(j["ID"].Value<string>());
|
|
||||||
|
|
||||||
//Ensure it follows the rules
|
|
||||||
NewTagGroupName = CleanTagGroupName(NewTagGroupName);
|
|
||||||
|
|
||||||
//There might already be a TagGroup of the same name since so many different types of V7 objects are becoming TagGroups
|
|
||||||
//Weighed the pros and cons of uniquifying by object type versus just using the same name for different object types:
|
|
||||||
//it seems to me at this point that people might desire the same exact name because if they used it that way they probably
|
|
||||||
//intended it that way, so decision is to check if it already exists and then use that ID in the importMap instead
|
|
||||||
//for matching other objects imported to TagGroups
|
|
||||||
|
|
||||||
//Already present?
|
|
||||||
var ExistingTagGroup = ct.TagGroup.Where(m => m.Name == NewTagGroupName).FirstOrDefault();
|
|
||||||
if (ExistingTagGroup != null)
|
|
||||||
{
|
|
||||||
//map it to the existing TagGroup of same name
|
|
||||||
var mapItem = new ImportAyaNova7MapItem(OldV7Id, AyaType.TagGroup, ExistingTagGroup.Id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
TagGroup o = await CreateAsync(NewTagGroupName);
|
|
||||||
if (HasErrors)
|
|
||||||
{
|
|
||||||
//If there are any validation errors, log in joblog and move on
|
|
||||||
JobsBiz.LogJob(jobId, $"TagGroupBiz::ImportV7Async -> import object \"{NewTagGroupName}\" of type \"{SourceType}\" source id {OldV7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await ct.SaveChangesAsync();
|
|
||||||
var mapItem = new ImportAyaNova7MapItem(OldV7Id, AyaType.TagGroup, o.Id);
|
|
||||||
importMap.Add(mapItem);
|
|
||||||
await ImportAyaNova7Biz.LogEventCreatedModifiedEvents(j, importMap, AyaType.TagGroup, ct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "scheduleableusergroupTagGroups":
|
|
||||||
{
|
|
||||||
#region attribute sched user group TagGroups
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
"ID": "871e77b2-979a-4f26-930b-46f7c05fc19f",
|
|
||||||
"Created": "08/30/2018 08:12 AM",
|
|
||||||
"Modified": "08/30/2018 08:13 AM",
|
|
||||||
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"Name": "Yet another test group",
|
|
||||||
"Active": true,
|
|
||||||
"Description": "More testing yay!",
|
|
||||||
"ScheduleableUsers": [
|
|
||||||
{
|
|
||||||
"Created": "08/30/2018 08:13 AM",
|
|
||||||
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"Modified": "08/30/2018 08:13 AM",
|
|
||||||
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"ID": "676475be-8301-47d0-bd54-af9dbd1fe7eb",
|
|
||||||
"ScheduleableUserID": "1d859264-3f32-462a-9b0c-a67dddfdf4d3",
|
|
||||||
"ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Created": "08/30/2018 08:13 AM",
|
|
||||||
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"Modified": "08/30/2018 08:13 AM",
|
|
||||||
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"ID": "173499c3-a616-42a0-b08c-74008f8fa352",
|
|
||||||
"ScheduleableUserID": "42b282bb-100b-4b31-aa14-5c831d7cda66",
|
|
||||||
"ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Created": "08/30/2018 08:13 AM",
|
|
||||||
"Creator": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"Modified": "08/30/2018 08:13 AM",
|
|
||||||
"Modifier": "2ecc77fc-69e2-4a7e-b88d-bd0ecaf36aed",
|
|
||||||
"ID": "19c9b3d6-eeb2-44ac-be4e-6ec93d15b02a",
|
|
||||||
"ScheduleableUserID": "e6ff9bc6-a550-4242-8c41-857f740e2841",
|
|
||||||
"ScheduleableUserGroupID": "871e77b2-979a-4f26-930b-46f7c05fc19f"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
var V7Id = new Guid(j["ID"].Value<string>());
|
|
||||||
var RavenTagGroupId = importMap.Where(m => m.V7ObjectId == V7Id).First().NewObjectAyaTypeId.ObjectId;
|
|
||||||
|
|
||||||
foreach (JToken t in j["ScheduleableUsers"])
|
|
||||||
{
|
|
||||||
var techId = new Guid(t["ScheduleableUserID"].Value<String>());
|
|
||||||
var RavenUserId = importMap.Where(m => m.V7ObjectId == techId).First().NewObjectAyaTypeId.ObjectId;
|
|
||||||
var Creator = importMap.Where(m => m.V7ObjectId == new Guid(t["Creator"].Value<string>())).First().NewObjectAyaTypeId.ObjectId;
|
|
||||||
|
|
||||||
TagGroupMap tm = new TagGroupMap();
|
|
||||||
tm.TagGroupToObjectId = RavenUserId;
|
|
||||||
tm.TagGroupToObjectType=AyaType.User;
|
|
||||||
tm.TagGroupId = RavenTagGroupId;
|
|
||||||
tm.OwnerId = Creator;
|
|
||||||
ct.TagGroupMap.Add(tm);
|
|
||||||
}
|
|
||||||
ct.SaveChanges();
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//this is the equivalent of returning void for a Task signature with nothing to return
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ namespace AyaNova.Biz
|
|||||||
TagGroupMap outObj = new TagGroupMap()
|
TagGroupMap outObj = new TagGroupMap()
|
||||||
{
|
{
|
||||||
TagId = inObj.TagId,
|
TagId = inObj.TagId,
|
||||||
TagToObjectId = inObj.TagToObjectId,
|
TagGroupId = inObj.TagGroupId,
|
||||||
TagToObjectType = inObj.TagToObjectType,
|
|
||||||
OwnerId = userId
|
OwnerId = userId
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -67,40 +66,6 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal async Task<List<NameIdItem>> GetTagsOnObjectListAsync(AyaTypeId tid)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
|
|
||||||
NOTES: This will be a bit of a "hot" path as every fetch of any main object will involve this
|
|
||||||
for now, just make it work and later can improve performance
|
|
||||||
|
|
||||||
Also is sort going to be adequate, it's supposed to be based on invariant culture
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
List<NameIdItem> l = new List<NameIdItem>();
|
|
||||||
|
|
||||||
//Get the list of tags on the object
|
|
||||||
var TagGroupMapsOnObject = await ct.TagGroupMap
|
|
||||||
.Where(m => m.TagToObjectId == tid.ObjectId && m.TagToObjectType == tid.ObjectType)
|
|
||||||
.Select(m => m.TagId)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
foreach (long tagId in TagGroupMapsOnObject)
|
|
||||||
{
|
|
||||||
var tagFromDb = await ct.Tag.SingleOrDefaultAsync(m => m.Id == tagId);
|
|
||||||
if (tagFromDb != null)
|
|
||||||
{
|
|
||||||
l.Add(new NameIdItem() { Id = tagFromDb.Id, Name = tagFromDb.Name });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return the list sorted alphabetically
|
|
||||||
//Note if this is commonly required then maybe make a helper / extension for it
|
|
||||||
return (l.OrderBy(o => o.Name).ToList());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//DELETE
|
//DELETE
|
||||||
@@ -118,17 +83,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//DELETE ALL TagGroupMapS FOR OBJECT
|
|
||||||
//
|
|
||||||
|
|
||||||
static internal bool DeleteAllForObject(AyaTypeId parentObj, AyContext ct)
|
|
||||||
{
|
|
||||||
//Be careful in future, if you put ToString at the end of each object in the string interpolation
|
|
||||||
//npgsql driver will assume it's a string and put quotes around it triggering an error that a string can't be compared to an int
|
|
||||||
ct.Database.ExecuteSqlCommand($"delete from aTagGroupMap where tagtoobjectid={parentObj.ObjectId} and tagtoobjecttype={parentObj.ObjectTypeAsInt}");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
13
server/AyaNova/models/dto/TagGroupMapInfo.cs
Normal file
13
server/AyaNova/models/dto/TagGroupMapInfo.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using AyaNova.Biz;
|
||||||
|
|
||||||
|
namespace AyaNova.Models
|
||||||
|
{
|
||||||
|
|
||||||
|
public class TagGroupMapInfo
|
||||||
|
{
|
||||||
|
public long TagId { get; set; }
|
||||||
|
public long TagGroupId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user