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); }
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); }
/// <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); }
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); }