Beispiel #1
0
        public ServiceResult Add(string tableName, string dataJson)
        {
            var modelBaseJson = new AutoDataBaseEntity().ToJsons();

            var rsJoinJson = $"{dataJson.TrimEnd('}')},{modelBaseJson.TrimStart('{')}";
            // dynamic object
            var model = LightAppStore.JsonToDynamicObject(rsJoinJson);

            LightAppStore.GetCollection(tableName).InsertOne(model);
            return(ServiceResult.Success);
        }
Beispiel #2
0
        public ServiceResult Update(string tableName, string dataJson, ObjectId id)
        {
            var modelBaseJson = new AutoDataBaseEntity().ToJsons();

            var rsJson = $"{dataJson.TrimEnd('}')},{modelBaseJson.TrimStart('{')}";

            // dynamic object
            var model = LightAppStore.JsonToDynamicObject(rsJson);

            var filter = Builders <dynamic> .Filter.Eq("_id", id);

            LightAppStore.GetCollection(tableName).FindOneAndReplace <dynamic>(filter, model);

            return(ServiceResult.Success);
        }
Beispiel #3
0
        /// <summary>
        ///     按 字段 和 字段值 取List
        ///     fieldName || fieldValue 为空则获取数据表的所有数据.
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="fieldName"></param>
        /// <param name="fieldValue"></param>
        /// <returns></returns>
        public List <dynamic> GetList(string tableName, string fieldName = "", string fieldValue = "")
        {
            // return all data.
            if (fieldName.IsNullOrEmpty() || fieldValue.IsNullOrEmpty())
            {
                return(LightAppStore.GetCollection(tableName).AsQueryable().ToList());
            }

            var dic = new Dictionary <string, string>
            {
                { fieldName, fieldValue }
            };
            var rsList = GetList(tableName, dic).ToList();

            return(rsList);
        }
Beispiel #4
0
        public PagedList <dynamic> GetPagedList(string tableName, object paramater)
        {
            var pageSize   = 0;
            var pageIndex  = 0;
            var dictionary = paramater.DeserializeJson <Dictionary <string, string> >();

            if (dictionary != null)
            {
                var pagedInput = AutoMapping.SetValue <PagedInputDto>(dictionary);
                if (pagedInput != null)
                {
                    pageSize  = (int)pagedInput.PageSize;
                    pageIndex = (int)pagedInput.PageIndex;
                }
            }

            if (pageSize < 1)
            {
                pageSize = 1;
            }

            if (pageIndex < 1)
            {
                pageIndex = 1;
            }

            dictionary.Remove("PageSize");
            dictionary.Remove("PageIndex");

            var listOp = new List <(string Field, Operator op, string Value)>();

            foreach (var item in dictionary)
            {
                var rs = LightAppStore.ComparisonParse(item);
                listOp.Add(rs);
            }

            var filter    = LightAppStore.FilterParser(listOp);
            var fetchList = LightAppStore.GetCollection(tableName).Find(filter)
                            .Skip(pageSize * (pageIndex - 1)).Limit(pageSize)
                            .ToList();
            var totalCount = LightAppStore.GetCollection(tableName).Find(filter).CountDocuments();

            var pagedList = PagedList <dynamic> .Create(fetchList, totalCount, pageSize, pageIndex);

            return(pagedList);
        }
Beispiel #5
0
        public List <dynamic> GetList(string tableName, Dictionary <string, string> query)
        {
            if (tableName.IsNullOrEmpty())
            {
                tableName = query.GetValue("TableName");
                query.Remove("TableName");
            }

            var listOp = new List <(string Field, Operator op, string Value)>();

            foreach (var item in query)
            {
                var rs = LightAppStore.ComparisonParse(item);
                listOp.Add(rs);
            }

            var rsList = LightAppStore.QueryList(tableName, listOp).ToList();

            return(rsList);
        }
Beispiel #6
0
        public ServiceResult Delete(string tableName, ObjectId id)
        {
            var rs = LightAppStore.DeleteOne(tableName, id);

            return(rs ? ServiceResult.Success : ServiceResult.Failed);
        }
Beispiel #7
0
 public long Count(string tableName)
 {
     return(LightAppStore.Count(tableName));
 }
Beispiel #8
0
 public dynamic GetSingle(string tableName, string fieldName, string fieldValue)
 {
     return(LightAppStore.GetSingle(tableName, fieldName, fieldValue));
 }
Beispiel #9
0
 public dynamic GetSingle(string tableName, ObjectId id)
 {
     return(LightAppStore.GetSingle(tableName, "_id", id.ToString()));
 }