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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user