public IEnumerable <IPlan> GetByPredicate(Expression <Func <IPlan, bool> > predicate, QueryParams <IPlan> param) { param = QueryParams <IPlan> .Validate(param, c => c.Id); var set = predicate.GetSinglePredicateSet(); var props = set.Property.Split("&&".ToCharArray()).Where(c => !string.IsNullOrEmpty(c)).ToArray(); Func <XElement, bool> currentPredicate; var value = set.Value.Replace("\"", ""); if (value == "True" || value == "False") { value = value.ToLower(); } if (props.Count() > 1) { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, value) || c.Attribute(props[1]).Value.ApplyToString(set.Method, value); } else { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, value); } var res = Document.Root.Elements().Where(c => currentPredicate.Invoke(c)) .Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlPlan.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); }
public IEnumerable <IPlan> GetByPredicate(Expression <Func <IPlan, bool> > predicate, QueryParams <IPlan> param) { try { param = QueryParams <IPlan> .Validate(param, c => c.Id, 10); using (Container = new ArticleContext()) { var list = Container.Plans.OrderBy(c => c.Id) .Where(predicate) .Skip(param.Skip ?? 0) .Take(param.Take ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Entities.Plan>, IEnumerable <CurrentPlan> >(list.Select(c => c as Plan)); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <Article> GetByTagWithTags(IEnumerable <int> ids, QueryParams <Article> param) { try { param = QueryParams <Article> .Validate(param, c => c.ArticleId, 10); using (Container = new ArticleContext()) { var list = Container.Articles .OrderBy(c => c.ArticleId) .Where(c => c.Tags.Count > 0 && !ids.Except(c.Tags.Select(x => x.Id)).Any()) .Skip(param.Skip ?? 0) .Take(param.Take ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Entities.Article>, IEnumerable <Article> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <ITag> GetAll(QueryParams <ITag> param) { try { param = QueryParams <ITag> .Validate(param, c => c.Id, 10); using (Container = new ArticleContext()) { var list = Container.Tags.OrderBy(c => c.Id).Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var result = Mapper.Map <IEnumerable <Entities.Tag>, IEnumerable <Tag> >(list); //var enumerable = result as IList<Article> ?? result.ToList(); //foreach (var article in enumerable) //{ // article.GroupId = article.ArticleGroup.GroupId; //} return(result.OrderBy(param.Order).ToList()); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <User> GetByPredicate(Expression <Func <User, bool> > predicate, QueryParams <User> param) { try { //var currentPredicate = predicate.Convert<Entities.User, User>(mapper); var anotherPredicate = Mapper.Map <Expression <Func <User, bool> >, Expression <Func <Entities.User, bool> > >(predicate); param = QueryParams <User> .Validate(param, c => c.UserId, 10); using (Container = new ArticleContext()) { var list = Container.Users .OrderBy(c => c.UserId) .Where(anotherPredicate) .Skip(param.Skip ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Entities.User>, IEnumerable <User> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <Article> GetByPredicate(Expression <Func <Article, bool> > predicate, QueryParams <Article> param) { param = QueryParams <Article> .Validate(param, c => c.ArticleId); var set = predicate.GetSinglePredicateSet(); var props = set.Property.Split("&&".ToCharArray()).Where(c => !string.IsNullOrEmpty(c)).ToArray(); Func <XElement, bool> currentPredicate; Expression <Func <XElement, bool> > first; if (props.Count() > 1) { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")) || c.Attribute(props[1]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")); //var collector = new ExpressionCollector<XElement>(); //foreach (var prop in props) //{ // string prop1 = prop; // var replaces = set.Value.Replace("\"", ""); // collector.AddExpression(c => c.Attribute(prop1).Value.ApplyToString(set.Method, replaces), ExpressionType.OrElse); //} //currentPredicate = collector.Collect().Compile(); } else { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")); } var res = Document.Root.Elements().Where(c => currentPredicate.Invoke(c)) .Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlArticle.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); }
public IEnumerable <User> GetAll(QueryParams <User> param) { try { param = QueryParams <User> .Validate(param, c => c.UserId, 10); using (Container = new ArticleContext()) { var list = Container.Users.OrderBy(c => c.UserId).Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var result = Mapper.Map <IEnumerable <Entities.User>, IEnumerable <User> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <Transaction> GetAll(QueryParams <Transaction> param) { try { param = QueryParams <Transaction> .Validate(param, c => c.Id, 10); using (Container = new ArticleContext()) { var list = Container.TransactionLogs.OrderByDescending(c => c.ActionDateTime).Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var result = Mapper.Map <IEnumerable <Entities.TransactionLog>, IEnumerable <Transaction> >(list); return(result); //.OrderBy(param.Order); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }
public IEnumerable <ArticleGroup> GetByPredicate(Expression <Func <ArticleGroup, bool> > predicate, QueryParams <ArticleGroup> param) { param = QueryParams <ArticleGroup> .Validate(param, c => c.GroupId); var set = predicate.GetSinglePredicateSet(); var props = set.Property.Split("&&".ToCharArray()).Where(c => !string.IsNullOrEmpty(c)).ToArray(); Func <XElement, bool> currentPredicate; if (props.Count() > 1) { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")) || c.Attribute(props[1]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")); } else { currentPredicate = c => c.Attribute(props[0]).Value.ApplyToString(set.Method, set.Value.Replace("\"", "")); if (set.Method == "Contains" && set.Property == "Groups") { currentPredicate = c => c.Elements().Select(x => x.Value).Contains(set.Value.Replace("\"", "")); } } var res = Document.Root.Elements().Where(c => currentPredicate.Invoke(c)) .Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlArtcileGroup.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); }
public IEnumerable <ArticleGroup> GetAll(QueryParams <ArticleGroup> param) { if (Document.Root.Elements().Any()) { param = QueryParams <ArticleGroup> .Validate(param, c => c.GroupId); var res = Document.Root.Elements().Skip(param.Skip ?? 0).Take(param.Take ?? 0); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlArtcileGroup.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); } return(null); }
public IEnumerable <IPlan> GetAll(QueryParams <IPlan> param) { Document = XDocument.Load(Path); if (Document.Root.Elements().Any()) { param = QueryParams <IPlan> .Validate(param, c => c.Id); var res = Document.Root.Elements().Skip(param.Skip ?? 0).Take(param.Take ?? 0); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlPlan.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); } return(null); }
public IEnumerable <ArticleGroup> GetAll(QueryParams <ArticleGroup> param) { return(ExecuteWithTry(() => { param = QueryParams <ArticleGroup> .Validate(param, c => c.GroupId, 10); using (Container = new ArticleContext()) { var list = Container.Groups.OrderBy(c => c.GroupId).Skip(param.Skip ?? 0).Take(param.Take ?? 0).ToList(); var result = Mapper.Map <IEnumerable <Group>, IEnumerable <ArticleGroup> >(list); return result.OrderBy(param.Order); } })); }
/// <summary> /// Queries one or more tradecards by arbitari parameters /// </summary> /// <param name="queryParams">The filter parameters</param> /// <returns>ICollection<TradeCardInfoType></returns> public ICollection <TradeCardInfo> QueryTradeCard(QueryParams queryParams) { queryParams.Validate(); var request = BuildRequest <QueryTradeCardsRequest>(); request.QueryParams = queryParams; var response = Request <QueryTradeCardsResponse, QueryTradeCardsRequest>(QUERY_TRADE_CARDS, request); if (response.Result.FuncCode != FunctionCode.ERROR) { return(response.TradeCards); } throw new EKAERException(response.Result); }
public IEnumerable <Article> GetAll(QueryParams <Article> param) { if (Document.Root.Elements().Any()) { param = QueryParams <Article> .Validate(param, c => c.ArticleId); var res = Document.Root.Elements().Skip(param.Skip ?? 0).Take(param.Take ?? 0); var list = res.Select(xElement => new StringReader(xElement.ToString())).Select(XmlArticle.Deserialize).ToList(); return(list.OrderBy(c => param.Order)); //var context = new XmlParserContext(null, null, null, XmlSpace.None); //XmlReader reader = new XmlTextReader(res.ToString(), XmlNodeType.Element, context); //return XmlArticle.DeserializeEnumerable(reader); } return(null); }
public IEnumerable <ArticleGroup> GetByPredicate(Expression <Func <ArticleGroup, bool> > predicate, QueryParams <ArticleGroup> param) { return(ExecuteWithTry(() => { //var currentPredicate = predicate.Convert<Group, ArticleGroup>(mapper); var anotherPredicate = Mapper.Map <Expression <Func <ArticleGroup, bool> >, Expression <Func <Group, bool> > >(predicate); param = QueryParams <ArticleGroup> .Validate(param, c => c.GroupId, 10); using (Container = new ArticleContext()) { var list = Container.Groups .OrderBy(c => c.GroupId) .Where(anotherPredicate) .Skip(param.Skip ?? 0) .Take(param.Take ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Group>, IEnumerable <ArticleGroup> >(list); return result.OrderBy(param.Order); } })); }
public IEnumerable <Article> GetWithTags(string searchString, QueryParams <Article> param) { try { param = QueryParams <Article> .Validate(param, c => c.ArticleId, 10); using (Container = new ArticleContext()) { var list = Container.Articles.OrderBy(c => c.ArticleId) .Where(c => c.ArticleName.ToUpper().Contains(searchString.ToUpper()) || c.AuthorName.ToUpper().Contains(searchString.ToUpper()) || c.InitialText.ToUpper().Contains(searchString.ToUpper()) || c.Tags.FirstOrDefault(x => x.Name.ToUpper().Contains(searchString.ToUpper())) != null) .Skip(param.Skip ?? 0) .Take(param.Take ?? 0) .ToList(); var result = Mapper.Map <IEnumerable <Entities.Article>, IEnumerable <Article> >(list); return(result.OrderBy(param.Order)); } } catch (DbEntityValidationException ex) { foreach (var dbEntityValidationResult in ex.EntityValidationErrors) { foreach (var dbValidationError in dbEntityValidationResult.ValidationErrors) { Console.WriteLine(dbValidationError.ErrorMessage); } } throw ex; } catch (Exception e) { throw e; } }