Example #1
0
        public void CreateOrUpdateFunc(PermFunc func)
        {
            var dbEntity = dataContext.P_Functions.Where(o => o.FuncCode == func.FuncCode).SingleOrDefault();

            if (dbEntity == null)
            {
                dbEntity          = new P_Function();
                dbEntity.FuncCode = func.FuncCode;
                dataContext.P_Functions.Add(dbEntity);
            }

            dbEntity.FuncName      = func.FuncName;
            dbEntity.AssociateUrls = func.AssociateUrls;
            dbEntity.FuncDesc      = func.FuncDesc;
            if (func.ExtendProperties != null)
            {
                dbEntity.ExtendProperties = this.DictionaryToXml(func.ExtendProperties);
            }
            else
            {
                dbEntity.ExtendProperties = null;
            }
            dataContext.SaveChanges();
        }
Example #2
0
        public List <PermFunc> GetFuncs(bool includeDesc, bool includeExtendProperties)
        {
            // The Linq very difficult to write concat sql string, So here will use four if to implement it;
            // In here, in order to save performance, we are not get all data from databse. We just got the properties which we wanted.
            List <P_Function> list = null;

            if (includeDesc == true && includeExtendProperties == false)
            {
                var query = from o in dataContext.P_Functions
                            select new P_Function()
                {
                    FuncCode      = o.FuncCode,
                    FuncName      = o.FuncName,
                    AssociateUrls = o.AssociateUrls,
                    FuncDesc      = o.FuncDesc
                };
                list = query.ToList();
            }
            else if (includeDesc == false && includeExtendProperties == true)
            {
                var query = from o in dataContext.P_Functions
                            select new P_Function()
                {
                    FuncCode         = o.FuncCode,
                    FuncName         = o.FuncName,
                    AssociateUrls    = o.AssociateUrls,
                    ExtendProperties = o.ExtendProperties
                };
                list = query.ToList();
            }
            else if (includeDesc == false && includeExtendProperties == false)
            {
                var query = from o in dataContext.P_Functions
                            select new P_Function()
                {
                    FuncCode      = o.FuncCode,
                    FuncName      = o.FuncName,
                    AssociateUrls = o.AssociateUrls
                };
                list = query.ToList();
            }
            else
            {
                var query = from o in dataContext.P_Functions
                            select new P_Function()
                {
                    FuncCode         = o.FuncCode,
                    FuncName         = o.FuncName,
                    AssociateUrls    = o.AssociateUrls,
                    FuncDesc         = o.FuncDesc,
                    ExtendProperties = o.ExtendProperties
                };
                list = query.ToList();
            }

            var result = new List <PermFunc>();

            foreach (var dbItem in list)
            {
                var convertedObj = new PermFunc();
                convertedObj.FuncCode      = dbItem.FuncCode;
                convertedObj.FuncName      = dbItem.FuncName;
                convertedObj.AssociateUrls = dbItem.AssociateUrls;
                convertedObj.FuncDesc      = dbItem.FuncDesc;
                if (!string.IsNullOrWhiteSpace(dbItem.ExtendProperties))
                {
                    convertedObj.ExtendProperties = this.XmlToDictionary(dbItem.ExtendProperties);
                }
                result.Add(convertedObj);
            }

            return(result);
        }