From 456a3917f24d43b7cf9b61571b2dc38f3ead512f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 5 Jan 2021 01:05:57 +0000 Subject: [PATCH] --- server/AyaNova/biz/UnitModelBiz.cs | 19 +++++++++++++++---- server/AyaNova/util/AySchema.cs | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/AyaNova/biz/UnitModelBiz.cs b/server/AyaNova/biz/UnitModelBiz.cs index 69df8931..e08f36b1 100644 --- a/server/AyaNova/biz/UnitModelBiz.cs +++ b/server/AyaNova/biz/UnitModelBiz.cs @@ -73,15 +73,15 @@ namespace AyaNova.Biz } UnitModel newObject = new UnitModel(); CopyObject.Copy(dbObject, newObject, "Wiki"); - string newUniqueName = string.Empty; + string newUniqueModelNumber = string.Empty; bool NotUnique = true; long l = 1; do { - newUniqueName = Util.StringUtil.UniqueNameBuilder(dbObject.Name, l++, 255); - NotUnique = await ct.UnitModel.AnyAsync(z => z.Name == newUniqueName); + newUniqueModelNumber = Util.StringUtil.UniqueNameBuilder(dbObject.Number, l++, 255); + NotUnique = await ct.UnitModel.AnyAsync(z => z.Number == newUniqueModelNumber); } while (NotUnique); - newObject.Name = newUniqueName; + newObject.Number = newUniqueModelNumber; newObject.Id = 0; newObject.Concurrency = 0; await ct.UnitModel.AddAsync(newObject); @@ -135,6 +135,17 @@ namespace AyaNova.Biz AddError(ApiErrorCode.CONCURRENCY_CONFLICT); return null; } + catch (Microsoft.EntityFrameworkCore.DbUpdateException ex) + { + if (ex.InnerException != null && ex.InnerException.Message.Contains("unq_unitmodelnumbervendorid")) + { + AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "number", "Model number plus VendorId combination must be unique"); + return null; + } + + throw; + + } await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObject.Id, BizType, AyaEvent.Modified), ct); await SearchIndexAsync(dbObject, false); await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, dbObject.Tags, SnapshotOfOriginalDBObj.Tags); diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index 0fb806dc..543a17d9 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -23,7 +23,7 @@ namespace AyaNova.Util private const int DESIRED_SCHEMA_LEVEL = 15; internal const long EXPECTED_COLUMN_COUNT = 620; - internal const long EXPECTED_INDEX_COUNT = 174; + internal const long EXPECTED_INDEX_COUNT = 175; //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!! @@ -718,7 +718,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); 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, " + "number text not null, vendorid bigint null references avendor(id), upc text null, lifetimewarranty bool not null, introduceddate timestamp null, " + - "discontinued bool not null, discontinueddate timestamp null, warrantylength integer null, warrantyterms text null " + + "discontinued bool not null, discontinueddate timestamp null, warrantylength integer null, warrantyterms text null, CONSTRAINT UNQ_UnitModelNumberVendorId UNIQUE (number, vendorid) " + ")"); await ExecQueryAsync("CREATE UNIQUE INDEX aunitmodel_name_id_idx ON aunitmodel (id, name);"); await ExecQueryAsync("CREATE INDEX aunitmodel_tags ON aunitmodel using GIN(tags)");