Fix B2016-045, B2016-083 & 084: Procedure number hyphen representation, create non-existing annotation type & don’t import if user does not overwrite/copy existing procedure.

Fix B2016-083: Added a method ‘GetByNameOrCreate’ that will create the Annotation type if it doesn’t exist
This commit is contained in:
2016-03-22 14:57:47 +00:00
parent 5ec4b86663
commit 5d8d79e32c
2 changed files with 122 additions and 77 deletions

View File

@@ -602,6 +602,36 @@ namespace VEPROMS.CSLA.Library
throw new DbCslaException("Error on AnnotationType.GetByName", ex);
}
}
// GetByNameOrCreate: gets the AnnotationType by its name, if it exists. If it
// doesn't exist, create it (fix B2016-083)
public static AnnotationType GetByNameOrCreate(string name)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a AnnotationType");
try
{
AnnotationType tmp = GetCachedByName(name);
if (tmp == null)
{
tmp = DataPortal.Fetch<AnnotationType>(new NameCriteria(name));
AddToCache(tmp);
}
// if the type doesn't exist, try to add it
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up AnnotationType
tmp = null;
tmp = AnnotationType.MakeAnnotationType(name, null);
AddToCache(tmp);
AnnotationTypeInfoList.Refresh();
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on AnnotationType.GetByNameOrCreate", ex);
}
}
public static AnnotationType Get(SafeDataReader dr)
{
if (dr.Read()) return new AnnotationType(dr);