예제 #1
0
        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;
        }
예제 #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;
        }
예제 #3
0
        private static string GetListSingleItemView(CND_Data cndData, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix, string configToken)
        {
            string htmlTextItem = "";
            if (cndData != null)
            {
                #region Retrieve Config Values

                long refTypeId = 0;
                long refId = 0;
                long dataTypeId = 0;
                string dataValueName = "Data";

                bool enableRefTypeId = false;
                bool enableRefId = false;
                bool enableDataTypeId = false;
                bool showRefType = false;
                bool showRefId = false;
                bool showDataType = false;

                bool showItemHeader = false;
                bool showItemEdit = false;
                bool showItemAppend = false;
                string itemAddName = "Add";
                string itemEditName = "Edit";
                string itemAppendName = "Append";
                bool isPublic = false;

                DataView.ProcessConfigToken(configToken, out refTypeId, out refId, out dataTypeId, out dataValueName, out enableRefTypeId, out enableRefId, out enableDataTypeId, out showRefType, out showRefId, out showDataType, out showItemHeader, out showItemEdit, out showItemAppend, out itemAddName, out itemEditName, out itemAppendName, out isPublic);

                #endregion

                string message;

                #region Edit Action

                List<TemplateDataListDetailItem.EditAction> editActionList = new List<TemplateDataListDetailItem.EditAction>();
                if (showItemEdit == true)
                {
                    if ((UtilsSecurity.IsAuthenticated() == true) || (isPublic == true))
                    {
                        if ((cndData.UserID == UtilsSecurity.GetUserId()) || (UtilsSecurity.HaveAdminRole() == true))
                        {
                            editActionList.Add(new TemplateDataListDetailItem.EditAction
                            {
                                Id = cndData.DataID.ToString(),
                                DataIndex = dataIndex.ToString(),
                                PageNo = pageNo.ToString(),
                                ItemsPerPage = itemsPerPage.ToString(),
                                TemplateSuffix = templateSuffix,
                                ConfigToken = configToken,
                                ItemEditName = itemEditName,
                            });
                        }
                        else
                        {
                            showItemEdit = false;
                        }
                    }
                    else
                    {
                        showItemEdit = false;
                    }
                }

                #endregion

                #region Append Action

                List<TemplateDataListDetailItem.AppendAction> appendActionList = new List<TemplateDataListDetailItem.AppendAction>();
                if (showItemAppend == true)
                {
                    if ((UtilsSecurity.IsAuthenticated() == true) || (isPublic ==true))
                    {
                        //Cannot Reply to Yourself, the User has to edit his comment only.
                        if ((cndData.UserID != UtilsSecurity.GetUserId()) || (UtilsSecurity.HaveAdminRole() == true))
                        {
                            appendActionList.Add(new TemplateDataListDetailItem.AppendAction
                            {
                                Id = cndData.DataID.ToString(),
                                DataIndex = dataIndex.ToString(),
                                PageNo = pageNo.ToString(),
                                ItemsPerPage = itemsPerPage.ToString(),
                                TemplateSuffix = templateSuffix,
                                ConfigToken = configToken,
                                ItemAppendName = itemAppendName,
                            });
                        }
                        else
                        {
                            showItemAppend = false;
                        }
                    }
                    else
                    {
                        showItemAppend = false;
                    }
                }

                #endregion

                #region Item Header

                List<TemplateDataListDetailItem.ItemHeaderVisible> itemHeaderVisibleList = new List<TemplateDataListDetailItem.ItemHeaderVisible>();
                if (showItemHeader == true)
                {
                    CNS_DataType cnsDataType = DataCommon.GetCnsDataType(cndData.DataTypeID);
                    string dataTypeName = cnsDataType.DataType;

                    itemHeaderVisibleList.Add(new TemplateDataListDetailItem.ItemHeaderVisible
                    {
                        DataTypeName = dataTypeName,
                        IsInActive = !cndData.IsActive,
                    });
                }

                #endregion
       
                string childHtmlTextItem = "";
                childHtmlTextItem = GetListChildDetailView(cndData, pageNo, itemsPerPage, dataIndex, templateSuffix, configToken);
                
                var templateItem = new TemplateDataListDetailItem
                {
                    ItemHeaderVisibleList = itemHeaderVisibleList,
                    DataValue = cndData.DataValue,
                    CreatedBy = UtilsSecurity.GetUserName(cndData.UserID),
                    CreatedDate = cndData.LastUpdateDate.ToString(UtilsGeneric.DefaultDateFormat),
                    
                    EditActionList = editActionList,
                    AppendActionList = appendActionList,
                    ChildItem = childHtmlTextItem
                };
                htmlTextItem = templateItem.GetFilled(templateSuffix, UtilsGeneric.Validate,
                                                                        UtilsGeneric.ThrowException,
                                                                        out message);

            }
            return htmlTextItem;
        }
예제 #4
0
        private static string GetListChildAllItemView(CND_Data parentCndData, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix, string configToken)
        {
            string message = "";
            long totalPages = 0;
            long totalItems = 0;
            string htmlTextItemList = "";

            #region Retrieve Config Values

            long refTypeId = 0;
            long refId = 0;
            long dataTypeId = 0;
            string dataValueName = "Data";

            bool enableRefTypeId = false;
            bool enableRefId = false;
            bool enableDataTypeId = false;
            bool showRefType = false;
            bool showRefId = false;
            bool showDataType = false;

            bool showItemHeader = false;
            bool showItemEdit = false;
            bool showItemAppend = false;
            string itemAddName = "Add";
            string itemEditName = "Edit";
            string itemAppendName = "Append";
            bool isPublic = false;

            DataView.ProcessConfigToken(configToken, out refTypeId, out refId, out dataTypeId, out dataValueName, out enableRefTypeId, out enableRefId, out enableDataTypeId, out showRefType, out showRefId, out showDataType, out showItemHeader, out showItemEdit, out showItemAppend, out itemAddName, out itemEditName, out itemAppendName, out isPublic);

            #endregion

            #region Get Fill List

            #region Get Paged Data

            List<CND_Data> cndDataList = DataCommon.GetAllChildCndData(refTypeId, refId, dataTypeId, parentCndData.DataID, pageNo, itemsPerPage, out totalPages, out totalItems);

            #endregion

            if (cndDataList.Count > 0)
            {
                #region Get Pager Details

                string configTokenParam = "'" + configToken + "'";
                string topPagerDetails = UtilsGeneric.GetItemPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, RefreshListFunctionName, configTokenParam, false);
                string bottomPagerDetails = UtilsGeneric.GetLinkPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, totalItems, RefreshListFunctionName, configTokenParam, false);

                #endregion

                #region Append Top Pager

                if (topPagerDetails.Trim().Length > 0)
                {
                    htmlTextItemList += topPagerDetails;
                }

                #endregion

                #region Append Items

                int index = 0;
                for (; index < cndDataList.Count; index++)
                {
                    CND_Data cndData = cndDataList[index];
                    string htmlTextItemTemplate = GetListSingleItemView(cndData, pageNo, itemsPerPage, dataIndex, templateSuffix, configToken);
                    htmlTextItemList += htmlTextItemTemplate;
                }

                #endregion

                #region Append Bottom Pager

                if (bottomPagerDetails.Trim().Length > 0)
                {
                    htmlTextItemList += bottomPagerDetails;
                }

                #endregion
            }

            #endregion

            #region Set Fill List

            if (ShowEmptyChildData ==true)
            {
                TemplateDataListDetailChildEmpty dataListDetailChildEmpty = new TemplateDataListDetailChildEmpty
                {
                    DataIndex = dataIndex.ToString(),
                    PageNo = pageNo.ToString(),
                    ItemsPerPage = itemsPerPage.ToString(),
                    TemplateSuffix = templateSuffix,
                    ConfigToken = configToken,
                    DataAppendName = itemAppendName,
                    DataValueName = dataValueName,
                };
                htmlTextItemList = dataListDetailChildEmpty.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message);
            }
            #endregion

            return htmlTextItemList;
        }
예제 #5
0
        private static string GetListChildDetailView(CND_Data parentCndData, long pageNo, long itemsPerPage, long dataIndex, string templateSuffix, string configToken)
        {
            string htmlListAllItem = GetListChildAllItemView(parentCndData, pageNo, itemsPerPage, dataIndex, templateSuffix, configToken);

            string message;
            if (_childDataIndex == 0){ _childDataIndex = dataIndex; }else{ _childDataIndex++; }
            var templateListDetail = new TemplateDataListDetail
            {
                ListItem = htmlListAllItem,
                DataIndex = _childDataIndex.ToString()
            };
            string htmlListDetail = templateListDetail.GetFilled(templateSuffix, UtilsGeneric.Validate,
                                                                            UtilsGeneric.ThrowException, out message);

            return htmlListDetail;
        }
예제 #6
0
        public static bool UpdateCndData(CND_Data cndData)
        {
            bool ret = false;
          
			 UserInfo userInfo = GetUserInfo();
            cndData.UserID = userInfo.Id;
            cndData.UserGUID = userInfo.Guid;
            cndData.LastUpdateDate = DateTime.UtcNow;
            Database db = HaveDb();
            if (db != null)
            {
                CND_Data cndDataExisting = GetCndData(cndData.DataID, "");
                if (cndDataExisting != null)
                {
					cndData.RevisionNo = GetMaxCndDataRevisionNo() + 1;                      
					using (ITransaction scope = db.GetTransaction())
					{
                        db.Update(cndData);
                        scope.Complete();
                        ret = true;
                    }
                }
            }
            else
            {
                Dictionary<Guid, CND_Data> fileCndDataList = FileSource.LoadCNDDataData();                
                if (fileCndDataList.ContainsKey(cndData.DataGUID) == true)
                {
                    fileCndDataList.Remove(cndData.DataGUID);
                    fileCndDataList.Add(cndData.DataGUID, cndData);
                    FileSource.SaveCNDDataData(fileCndDataList);
                }
            }

            return ret;
        }
예제 #7
0
        public static long InsertCndData(CND_Data cndData)
        {
            long id = 0;
            if (cndData.DataGUID != Guid.Empty) throw new Exception("Cannot Set the GUID for a Insert");
            cndData.DataGUID = Guid.NewGuid();
          
			 UserInfo userInfo = GetUserInfo();
            cndData.UserID = userInfo.Id;
            cndData.UserGUID = userInfo.Guid;
            cndData.CreatedDate = DateTime.UtcNow;
            cndData.LastUpdateDate = DateTime.UtcNow;
            cndData.RevisionNo = GetMaxCndDataRevisionNo() + 1;

            Database db = HaveDb();
            if (db != null)
            {
                using (ITransaction scope = db.GetTransaction())
                {
                    db.Insert(cndData);
                    id = cndData.DataID;
                    scope.Complete();
                }
            }
            else
            {
                Dictionary<Guid, CND_Data> fileCndDataList = FileSource.LoadCNDDataData();
	  			cndData.DataID = GetMaxCndDataId("") + 1;
  
                fileCndDataList.Add(cndData.DataGUID, cndData);
                FileSource.SaveCNDDataData(fileCndDataList);

                id = cndData.DataID;
            }

            return id;
        }