This commit is contained in:
2021-01-05 01:05:57 +00:00
parent 0786074944
commit 456a3917f2
2 changed files with 17 additions and 6 deletions

View File

@@ -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);

View File

@@ -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)");