public static bool SaveCNDDataData(Dictionary <Guid, CND_Data> cndDataList) { bool ret = false; if (cndDataList.Count > 0) { List <CND_Data> cndDataValueList = new List <CND_Data>(); CND_Data[] cndDataArray = new CND_Data[cndDataList.Values.Count]; cndDataList.Values.CopyTo(cndDataArray, 0); cndDataValueList.AddRange(cndDataArray); ret = JsonStore <CND_Data> .SaveData(cndDataValueList, true); } return(ret); }
public static bool DeleteCndData(long dataId, out string retMessage) { bool ret = false; string message = ""; try { bool validationFail = false; if ((UtilsSecurity.HaveAuthorRole() == false) && (UtilsSecurity.HaveAdminRole() == false)) { message = "Please login as User having Author Role to Delete Data"; validationFail = true; } if (validationFail == false) { if (dataId == 0) { message = "Missing or Empty Data ID Argument"; validationFail = true; } } if (validationFail == false) { CND_Data cndDataExisting = GetCndData(dataId); if (cndDataExisting == null) { message = "The Data with ID [" + dataId.ToString(CultureInfo.InvariantCulture) + "] does not exist"; validationFail = true; } else if (cndDataExisting.UserID != UtilsSecurity.GetUserId()) { if (UtilsSecurity.HaveAdminRole() == false) { message = "You cannot Delete Data of Another User Unless you have Admin Role"; validationFail = true; } } if (cndDataExisting != null) { if (HaveChildCndData(cndDataExisting.DataID) == true) { message = "You cannot Delete this Data Unless you delete all the Child Data of this Data"; validationFail = true; } } } if (validationFail == false) { DataSource.BeginTransaction(); DataSource.DeleteCndData(dataId); DataSource.CompleteTransaction(); ret = true; } } catch (Exception ex) { message = "DBError:" + ex.Message; LogManager.Log(LogLevel.Error, "DataCommon-DeleteCndData", message); } retMessage = message; return(ret); }
public static long SaveCndData(long parentDataId, long dataRefId, long dataRefTypeId, long dataTypeId, string dataValue, bool dataIsActive, bool isPublic, long dataId, out string retMessage) { long id = 0; string message = ""; try { bool validationFail = false; if (isPublic == false) { if ((UtilsSecurity.HaveAdminRole() == false) && (UtilsSecurity.HaveAuthorRole() == false)) { message = "Please login as User Having Admin/Author Role to Save Data"; validationFail = true; } } if (validationFail == false) { if ((dataRefTypeId == 0) || (dataTypeId == 0) || (string.IsNullOrEmpty(dataValue) == true)) { message = "Missing or Empty Data Argument"; validationFail = true; } } CND_Data cndData = new CND_Data(); if (validationFail == false) { if (dataId != 0) { cndData = GetCndData(dataId); if (cndData == null) { message = "The Data having ID [" + dataId + "] cannot be Retrieved"; validationFail = true; } else { if ((cndData.UserID != UtilsSecurity.GetUserId()) && (UtilsSecurity.HaveAdminRole() == false)) { message = "The Data having ID [" + dataId + "] can be edited only the User who created it"; validationFail = true; } } } } Guid parentDataGuid = Guid.Empty; if (validationFail == false) { if (parentDataId != 0) { CND_Data cndDataParent = GetCndData(parentDataId); if (cndDataParent == null) { message = "The Parent Data having ID [" + parentDataId + "] cannot be Retrieved"; validationFail = true; } else { parentDataGuid = cndDataParent.DataGUID; } } } CNS_DataType cnsDataType = GetCnsDataType(dataTypeId); if (validationFail == false) { if (cnsDataType == null) { message = "The DataType [" + dataTypeId + "] does not exist"; validationFail = true; } } CNS_DataRefType cnsDataRefType = GetCnsDataRefType(dataRefTypeId); if (validationFail == false) { if (cnsDataRefType == null) { message = "The DataRefType [" + dataRefTypeId + "] does not exist"; validationFail = true; } } if (validationFail == false) { cndData.IsActive = dataIsActive; if (dataId == 0) { cndData.Sequence = GetMaxCndDataId() + 1; cndData.IsActive = true; } cndData.DataTypeID = cnsDataType.DataTypeID; cndData.DataTypeGUID = cnsDataType.DataTypeGUID; cndData.DataRefTypeID = cnsDataRefType.DataRefTypeID; cndData.DataRefTypeGUID = cnsDataRefType.DataRefTypeGUID; cndData.DataRefID = dataRefId; cndData.DataValue = dataValue; if (parentDataId > 0) { cndData.ParentDataID = parentDataId; cndData.ParentDataGUID = parentDataGuid; } DataSource.BeginTransaction(); if (cndData.DataID == 0) { DataSource.InsertCndData(cndData); id = cndData.DataID; } else { DataSource.UpdateCndData(cndData); id = cndData.DataID; } DataSource.CompleteTransaction(); } } catch (Exception ex) { id = 0; message = "DBError:" + ex.Message; LogManager.Log(LogLevel.Error, "DataCommon-SaveCndData", message); DataSource.AbortTransaction(); } retMessage = message; return(id); }