This commit is contained in:
@@ -73,10 +73,10 @@ namespace AyaNova.Biz
|
|||||||
long l = 1;
|
long l = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255);
|
newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Serial, l++, 255);
|
||||||
NotUnique = await ct.Unit.AnyAsync(z => z.Name == newUniqueName);
|
NotUnique = await ct.Unit.AnyAsync(z => z.Serial == newUniqueName);
|
||||||
} while (NotUnique);
|
} while (NotUnique);
|
||||||
newObject.Name = newUniqueName;
|
newObject.Serial = newUniqueName;
|
||||||
newObject.Id = 0;
|
newObject.Id = 0;
|
||||||
newObject.Concurrency = 0;
|
newObject.Concurrency = 0;
|
||||||
await ct.Unit.AddAsync(newObject);
|
await ct.Unit.AddAsync(newObject);
|
||||||
@@ -159,7 +159,7 @@ namespace AyaNova.Biz
|
|||||||
return false;
|
return false;
|
||||||
ct.Unit.Remove(dbObject);
|
ct.Unit.Remove(dbObject);
|
||||||
await ct.SaveChangesAsync();
|
await ct.SaveChangesAsync();
|
||||||
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Name, ct);
|
await EventLogProcessor.DeleteObjectLogAsync(UserId, BizType, dbObject.Id, dbObject.Serial, ct);
|
||||||
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
await Search.ProcessDeletedObjectKeywordsAsync(dbObject.Id, BizType, ct);
|
||||||
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
await TagBiz.ProcessDeleteTagsInRepositoryAsync(ct, dbObject.Tags);
|
||||||
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
|
await FileUtil.DeleteAttachmentsForObjectAsync(BizType, dbObject.Id, ct);
|
||||||
@@ -202,9 +202,16 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
searchParams.AddText(obj.Notes)
|
searchParams.AddText(obj.Notes)
|
||||||
.AddText(obj.Name)
|
.AddText(obj.Serial)
|
||||||
.AddText(obj.Wiki)
|
.AddText(obj.Wiki)
|
||||||
.AddText(obj.Tags)
|
.AddText(obj.Tags)
|
||||||
|
.AddText(obj.Receipt)
|
||||||
|
.AddText(obj.Description)
|
||||||
|
.AddText(obj.WarrantyTerms)
|
||||||
|
.AddText(obj.Text1)
|
||||||
|
.AddText(obj.Text2)
|
||||||
|
.AddText(obj.Text3)
|
||||||
|
.AddText(obj.Text4)
|
||||||
.AddCustomFields(obj.CustomFields);
|
.AddCustomFields(obj.CustomFields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,22 +226,23 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
bool isNew = currentObj == null;
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
//Name required
|
//Serial required
|
||||||
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
if (string.IsNullOrWhiteSpace(proposedObj.Serial))
|
||||||
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Serial");
|
||||||
|
|
||||||
|
|
||||||
//If name is otherwise OK, check that name is unique
|
//If serial is otherwise OK, check that serial is unique for that unitmodelid (this is to catch dupes)
|
||||||
if (!PropertyHasErrors("Name"))
|
//(two different manufacturers products could have the same serial easily, but it's less likely for two different units of the same unitmodel)
|
||||||
|
//
|
||||||
|
if (!PropertyHasErrors("Serial"))
|
||||||
{
|
{
|
||||||
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||||
if (await ct.Unit.AnyAsync(z => z.Name == proposedObj.Name && z.Id != proposedObj.Id))
|
if (await ct.Unit.AnyAsync(z => z.Serial == proposedObj.Serial && z.UnitModelId == proposedObj.UnitModelId && z.Id != proposedObj.Id))
|
||||||
{
|
{
|
||||||
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Serial", "no two units can have the same serial and same unitmodel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Any form customizations to validate?
|
//Any form customizations to validate?
|
||||||
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.Unit.ToString());
|
var FormCustomization = await ct.FormCustom.AsNoTracking().SingleOrDefaultAsync(z => z.FormKey == AyaType.Unit.ToString());
|
||||||
if (FormCustomization != null)
|
if (FormCustomization != null)
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ namespace AyaNova.Models
|
|||||||
[AUSESBANKING] [bit] NOT NULL,
|
[AUSESBANKING] [bit] NOT NULL,
|
||||||
[ACONTRACTID] [uniqueidentifier] NULL,
|
[ACONTRACTID] [uniqueidentifier] NULL,
|
||||||
[ACONTRACTEXPIRES] [datetime] NULL,
|
[ACONTRACTEXPIRES] [datetime] NULL,
|
||||||
[ALASTWORKORDERID] [uniqueidentifier] NULL,
|
[ALASTWORKORDERID] [uniqueidentifier] NULL,//dropped case 3536
|
||||||
[ALASTSERVICEDATE] [datetime] NULL,
|
[ALASTSERVICEDATE] [datetime] NULL,//dropped case 3536
|
||||||
[ADEFAULTSERVICETEMPLATEID] [uniqueidentifier] NULL,
|
[ADEFAULTSERVICETEMPLATEID] [uniqueidentifier] NULL,
|
||||||
[ACONTACTNOTES] [ntext] NULL,
|
[ACONTACTNOTES] [ntext] NULL,
|
||||||
[ACONTACT] [nvarchar](500) NULL,
|
[ACONTACT] [nvarchar](500) NULL,
|
||||||
|
|||||||
@@ -15,14 +15,35 @@ namespace AyaNova.Models
|
|||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public uint Concurrency { get; set; }
|
public uint Concurrency { get; set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Name { get; set; }
|
|
||||||
public bool Active { get; set; }
|
public bool Active { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public string Wiki { get; set; }
|
public string Wiki { get; set; }
|
||||||
public string CustomFields { get; set; }
|
public string CustomFields { get; set; }
|
||||||
public List<string> Tags { get; set; }
|
public List<string> Tags { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string Serial { get; set; }
|
||||||
|
[Required]
|
||||||
|
public long CustomerId { get; set; }
|
||||||
|
public long? ParentUnitId { get; set; }
|
||||||
|
public long? UnitModelId { get; set; }
|
||||||
|
public bool UnitHasOwnAddress { get; set; }
|
||||||
|
public bool BoughtHere { get; set; }
|
||||||
|
public long? PurchasedFromVendorId { get; set; }
|
||||||
|
public string Receipt { get; set; }
|
||||||
|
public DateTime? PurchasedDate { get; set; }
|
||||||
|
public string Description { get; set; }
|
||||||
|
public long? ReplacedByUnitId { get; set; }
|
||||||
|
public bool OverrideModelWarranty { get; set; }
|
||||||
|
public int? WarrantyLength { get; set; }
|
||||||
|
public string WarrantyTerms { get; set; }
|
||||||
|
public bool UsesBanking { get; set; }
|
||||||
|
public bool Metered { get; set; }
|
||||||
|
public bool LifeTimeWarranty { get; set; }
|
||||||
|
public string Text1 { get; set; }
|
||||||
|
public string Text2 { get; set; }
|
||||||
|
public string Text3 { get; set; }
|
||||||
|
public string Text4 { get; set; }
|
||||||
|
|
||||||
public Unit()
|
public Unit()
|
||||||
{
|
{
|
||||||
@@ -32,6 +53,63 @@ namespace AyaNova.Models
|
|||||||
[NotMapped, JsonIgnore]
|
[NotMapped, JsonIgnore]
|
||||||
public AyaType AyaType { get => AyaType.Unit; }
|
public AyaType AyaType { get => AyaType.Unit; }
|
||||||
|
|
||||||
|
//convenience links
|
||||||
|
[JsonIgnore]
|
||||||
|
public Customer Customer { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public UnitModel UnitModel { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public Unit ParentUnit { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public Vendor PurchasedFromVendor { get; set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public Unit ReplacedByUnit { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}//eoc
|
}//eoc
|
||||||
|
|
||||||
}//eons
|
}//eons
|
||||||
|
/*
|
||||||
|
|
||||||
|
CREATE TABLE [dbo].[AUNIT](
|
||||||
|
[AID] [uniqueidentifier] NOT NULL,
|
||||||
|
[ACREATED] [datetime] NOT NULL,
|
||||||
|
[AMODIFIED] [datetime] NOT NULL,
|
||||||
|
[AACTIVE] [bit] NOT NULL,
|
||||||
|
[ACREATOR] [uniqueidentifier] NOT NULL,
|
||||||
|
[AMODIFIER] [uniqueidentifier] NOT NULL,
|
||||||
|
[ASERIAL] [nvarchar](255) NOT NULL,// MIGRATE: Can't make this unique, but *can* make it unique with the model id UNIQUE(aserial,aunitmodelid) to catch dupes
|
||||||
|
[ANOTES] [ntext] NULL,
|
||||||
|
[ACLIENTID] [uniqueidentifier] NULL,
|
||||||
|
[APARENTUNITID] [uniqueidentifier] NULL,
|
||||||
|
[AUNITMODELID] [uniqueidentifier] NULL,
|
||||||
|
[AUNITHASOWNADDRESS] [bit] NOT NULL,//do we need this? it only ever drove the UI, but I guess that's still valid
|
||||||
|
[ABOUGHTHERE] [bit] NOT NULL,
|
||||||
|
[APURCHASEDFROMID] [uniqueidentifier] NULL,
|
||||||
|
[ARECEIPT] [nvarchar](255) NULL,
|
||||||
|
[APURCHASEDDATE] [datetime] NULL,
|
||||||
|
[ADESCRIPTION] [nvarchar](255) NULL,
|
||||||
|
[AREPLACEDBYUNITID] [uniqueidentifier] NULL,
|
||||||
|
[AOVERRIDEMODELWARRANTY] [bit] NOT NULL,
|
||||||
|
[AWARRANTYTERMS] [nvarchar](255) NULL,
|
||||||
|
[ACUSTOM2] [ntext] NULL,
|
||||||
|
[ACUSTOM3] [ntext] NULL,
|
||||||
|
[ACUSTOM4] [ntext] NULL,
|
||||||
|
[ACUSTOM5] [ntext] NULL,
|
||||||
|
[ACUSTOM6] [ntext] NULL,
|
||||||
|
[ACUSTOM7] [ntext] NULL,
|
||||||
|
[ACUSTOM8] [ntext] NULL,
|
||||||
|
[ACUSTOM9] [ntext] NULL,
|
||||||
|
[ACUSTOM0] [ntext] NULL,
|
||||||
|
[ACUSTOM1] [ntext] NULL,
|
||||||
|
[AUSESBANKING] [bit] NOT NULL,
|
||||||
|
[AMETERED] [bit] NOT NULL,
|
||||||
|
[ALIFETIMEWARRANTY] [bit] NOT NULL,
|
||||||
|
[AWARRANTYLENGTH] [int] NULL,
|
||||||
|
[ALASTWORKORDERID] [uniqueidentifier] NULL,//MIGRATE: DROP as per case 3536, will determine live from query instead if necessary
|
||||||
|
[ALASTSERVICEDATE] [datetime] NULL,//MIGRATE: DROP case 3536
|
||||||
|
[ATEXT1] [nvarchar](255) NULL,
|
||||||
|
[ATEXT2] [nvarchar](255) NULL,
|
||||||
|
[ATEXT3] [nvarchar](255) NULL,
|
||||||
|
[ATEXT4] [nvarchar](255) NULL,
|
||||||
|
*/
|
||||||
@@ -352,15 +352,15 @@ BEGIN
|
|||||||
when 23 then aytable = 'apmtemplate';
|
when 23 then aytable = 'apmtemplate';
|
||||||
when 24 then aytable = 'apmtemplateitem';
|
when 24 then aytable = 'apmtemplateitem';
|
||||||
when 25 then aytable = 'aproject';
|
when 25 then aytable = 'aproject';
|
||||||
when 26 then aytable = 'apurchaseorder'; aynamecolumn ='serial';
|
when 26 then aytable = 'apurchaseorder'; aynamecolumn = 'serial';
|
||||||
when 27 then aytable = 'aquote'; aynamecolumn ='serial';
|
when 27 then aytable = 'aquote'; aynamecolumn = 'serial';
|
||||||
when 28 then aytable = 'aquoteitem';
|
when 28 then aytable = 'aquoteitem';
|
||||||
when 29 then aytable = 'aquotetemplate';
|
when 29 then aytable = 'aquotetemplate';
|
||||||
when 30 then aytable = 'aquotetemplateitem';
|
when 30 then aytable = 'aquotetemplateitem';
|
||||||
when 31 then aytable = 'aunit';
|
when 31 then aytable = 'aunit'; aynamecolumn = 'serial';
|
||||||
when 32 then aytable = 'aunitmodel'; aynamecolumn = 'number';
|
when 32 then aytable = 'aunitmodel'; aynamecolumn = 'number';
|
||||||
when 33 then aytable = 'avendor';
|
when 33 then aytable = 'avendor';
|
||||||
when 34 then aytable = 'aworkorder'; aynamecolumn ='serial';
|
when 34 then aytable = 'aworkorder'; aynamecolumn = 'serial';
|
||||||
when 35 then return 'LT:WorkOrderItem';
|
when 35 then return 'LT:WorkOrderItem';
|
||||||
when 36 then return 'LT:WorkOrderItemExpense';
|
when 36 then return 'LT:WorkOrderItemExpense';
|
||||||
when 37 then return 'LT:WorkOrderItemLabor';
|
when 37 then return 'LT:WorkOrderItemLabor';
|
||||||
@@ -715,11 +715,20 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
|||||||
await ExecQueryAsync("ALTER TABLE auser add FOREIGN KEY (vendorid) REFERENCES avendor(id)");
|
await ExecQueryAsync("ALTER TABLE auser add FOREIGN KEY (vendorid) REFERENCES avendor(id)");
|
||||||
|
|
||||||
//UNIT
|
//UNIT
|
||||||
await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text not null unique, active bool, " +
|
await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active bool, " +
|
||||||
"notes text, wiki text, customfields text, tags varchar(255) ARRAY )");
|
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
|
||||||
await ExecQueryAsync("CREATE UNIQUE INDEX aunit_name_id_idx ON aunit (id, name);");
|
"serial text not null, customerid bigint not null references acustomer(id), parentunitid bigint null references aunit(id), " +
|
||||||
|
"unitmodelid bigint null references aunitmodel(id), unithasownaddress bool, boughthere bool, purchasedfromvendorid bigint null references avendor(id), " +
|
||||||
|
"receipt text null, purchaseddate timestamp null, description text null, replacedbyunitid bigint null references aunit(id), " +
|
||||||
|
"overridemodelwarranty bool, warrantylength integer null, warrantyterms text null, usesbanking bool, metered bool, lifetimewarranty bool, " +
|
||||||
|
"text1 text null, text2 text null, text3 text null, text4 text null " +
|
||||||
|
" )");
|
||||||
|
|
||||||
|
|
||||||
|
// await ExecQueryAsync("CREATE UNIQUE INDEX aunit_name_id_idx ON aunit (id, name);");
|
||||||
await ExecQueryAsync("CREATE INDEX aunit_tags ON aunit using GIN(tags)");
|
await ExecQueryAsync("CREATE INDEX aunit_tags ON aunit using GIN(tags)");
|
||||||
|
|
||||||
|
|
||||||
//UNITMODEL
|
//UNITMODEL
|
||||||
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text null, active bool, " +
|
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text null, active bool, " +
|
||||||
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
|
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
|
||||||
|
|||||||
Reference in New Issue
Block a user