Пример #1
0
        public List <Order> Get(Order order)
        {
            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(order.Code))
            {
                sb.AppendLine("\"Code\":\"" + order.Code + "\",");
            }
            if (!string.IsNullOrEmpty(order.ClientId))
            {
                sb.AppendLine("\"ClientId\":\"" + order.ClientId + "\",");
            }
            if (order.Status != null && order.Status != 0)
            {
                sb.AppendLine("\"Status\":" + (int)order.Status + ",");
            }
            if (!string.IsNullOrEmpty(order.Client))
            {
                sb.AppendLine("\"Client\":/" + order.Client + "/i,");
            }

            if (order.CreateAt.HasValue)
            {
                var dateQuery = new StringBuilder();

                if (order.CreateAt.HasValue)
                {
                    dateQuery.AppendLine($"$gte:ISODate(\"{order.CreateAt.Value.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz")}\"),");
                }

                dateQuery.Remove(dateQuery.Length - 2, 1);

                sb.AppendLine(String.Concat("CreateAt:{", dateQuery.ToString(), "},"));
            }

            if (sb.ToString() == string.Empty)
            {
                return(_mongoClient.FindAll <Order>(collection));
            }
            else
            {
                sb.Remove(sb.Length - 3, 2);
                sb.AppendLine("}");
                return(_mongoClient.Find <Order>(collection, "{" + sb.ToString()));
            }
        }
Пример #2
0
        public List <Client> Get(Client client)
        {
            StringBuilder sb = new StringBuilder();

            if (client.Document != null)
            {
                sb.AppendLine("\"Document\":" + client.Document + ",");
            }
            if (!string.IsNullOrEmpty(client.Name))
            {
                sb.AppendLine("\"Name\":/" + client.Name + "/i,");
            }

            if (sb.ToString() == string.Empty)
            {
                return(_mongoClient.FindAll <Client>(collection));
            }
            else
            {
                sb.Remove(sb.Length - 3, 2);
                sb.AppendLine("}");
                return(_mongoClient.Find <Client>(collection, "{" + sb.ToString()));
            }
        }