Esempio n. 1
0
        public static long SaveCnsDataRefType(string dataRefType, bool dataRefTypeIsDefault, bool dataRefTypeIsActive, long dataRefTypeId, out string retMessage)
        {
            long   id      = 0;
            string message = "";

            try
            {
                bool validationFail = false;
                if (UtilsSecurity.HaveAdminRole() == false)
                {
                    message        = "Please login as User Having Admin to Save RefType";
                    validationFail = true;
                }

                if (validationFail == false)
                {
                    if (string.IsNullOrEmpty(dataRefType) == true)
                    {
                        message        = "Missing or Empty DataRefType Argument";
                        validationFail = true;
                    }
                }

                if (validationFail == false)
                {
                    CNS_DataRefType cnsDataRefTypeExisting = GetCnsDataRefType(dataRefType);
                    if ((cnsDataRefTypeExisting != null) && (cnsDataRefTypeExisting.DataRefTypeID != dataRefTypeId))
                    {
                        message        = "The DataRefType [" + dataRefType + "] allready exists";
                        validationFail = true;
                    }
                }

                var cnsDataRefType = new CNS_DataRefType();
                if (validationFail == false)
                {
                    if (dataRefTypeId != 0)
                    {
                        cnsDataRefType = GetCnsDataRefType(dataRefTypeId);
                        if (cnsDataRefType == null)
                        {
                            message        = "The DataRefType having ID [" + dataRefTypeId + "] cannot be Retrieved";
                            validationFail = true;
                        }
                    }
                }

                if (validationFail == false)
                {
                    long maxRefTypeId = GetMaxCnsDataRefTypeId() + 1;
                    cnsDataRefType.IsActive = dataRefTypeIsActive;
                    if (dataRefTypeId == 0)
                    {
                        cnsDataRefType.Sequence = maxRefTypeId;
                        cnsDataRefType.IsActive = true;
                        cnsDataRefType.IsSystem = false;
                    }
                    cnsDataRefType.DataRefType = dataRefType;
                    cnsDataRefType.IsDefault   = dataRefTypeIsDefault;


                    DataSource.BeginTransaction();
                    if (cnsDataRefType.IsDefault)
                    {
                        CNS_DataRefType defaultCnsDataRefType = GetDefaultCnsDataRefType();
                        if (defaultCnsDataRefType != null)
                        {
                            if (defaultCnsDataRefType.DataRefTypeID != cnsDataRefType.DataRefTypeID)
                            {
                                defaultCnsDataRefType.IsDefault = false;
                                DataSource.UpdateCnsDataRefType(defaultCnsDataRefType);
                            }
                        }
                    }

                    if (cnsDataRefType.DataRefTypeID == 0)
                    {
                        cnsDataRefType.DataRefTypeID = maxRefTypeId;
                        DataSource.InsertCnsDataRefType(cnsDataRefType);
                        id = cnsDataRefType.DataRefTypeID;
                    }
                    else
                    {
                        DataSource.UpdateCnsDataRefType(cnsDataRefType);
                        id = cnsDataRefType.DataRefTypeID;
                    }
                    DataSource.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                id      = 0;
                message = "DBError:" + ex.Message;
                LogManager.Log(LogLevel.Error, "DataCommon-SaveCnsDataRefType", message);
                DataSource.AbortTransaction();
            }

            retMessage = message;
            return(id);
        }
Esempio n. 2
0
        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);
        }