Ejemplo n.º 1
0
        public ContainerQueryResponse Get(ContainerQuery query)
        {
            var response = new ContainerQueryResponse();

            using (_session)
            {
                try
                {
                    IEnumerable <Container> containers = _session.Query <Container>();

                    if (!string.IsNullOrEmpty(query.SourceFilter))
                    {
                        containers = from c in containers
                                     where c.Source.ToLower().Contains(query.SourceFilter.ToLower())
                                     select c;
                    }
                    if (query.NumberFilter.HasValue && query.NumberFilter > 0)
                    {
                        containers = from c in containers
                                     where c.Number == query.NumberFilter
                                     select c;
                    }
                    if (!string.IsNullOrEmpty(query.DescriptionFilter))
                    {
                        containers = from c in containers
                                     where c.Description.ToLower().Contains(query.DescriptionFilter.ToLower())
                                     select c;
                    }
                    if (query.DatePackedFilter.HasValue && query.DatePackedFilter > DateTime.MinValue)
                    {
                        containers = from c in containers
                                     where c.DatePacked == query.DatePackedFilter
                                     select c;
                    }
                    response.Containers = containers.ToArray();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Get(ContainerQuery): {0}", ex.Message);
                    throw;
                }
            }
            return(response);
        }
Ejemplo n.º 2
0
        public void TestQueryContainerBySource()
        {
            var container1 = new Container
            {
                Number      = 1,
                Description = "Workbench, electronic parts, soldering irons, tools",
                Source      = "Garage",
                Destination = "Garage",
                DatePacked  = new DateTime(2013, 6, 12)
            };
            var container2 = new Container
            {
                Number      = 2,
                Description = "Power tools, chargers, batteries, bits",
                Source      = "Garage",
                Destination = "Garage",
                DatePacked  = new DateTime(2013, 6, 13)
            };
            var response1 = _client.Post <ContainerResponse>(container1);

            container1.Id = response1.Id;
            var response2 = _client.Post <ContainerResponse>(container2);

            container2.Id = response2.Id;

            var queryRequest = new ContainerQuery
            {
                SourceFilter      = "Garage",
                NumberFilter      = null,
                DescriptionFilter = null,
                DatePackedFilter  = null
            };

            var queryResponse = _client.Get <ContainerQueryResponse>(queryRequest);

            Assert.IsNotNull(queryResponse);
            Assert.AreEqual(2, queryResponse.Containers.Length);
            Assert.AreEqual("Garage", queryResponse.Containers[0].Source);
            Assert.AreEqual("Garage", queryResponse.Containers[1].Source);
            Assert.AreNotEqual(container1.Id, container2.Id);

            _client.Delete(container1);
            _client.Delete(container2);
        }
Ejemplo n.º 3
0
        public ContainerQueryResponse Get(ContainerQuery query)
        {
            var response = new ContainerQueryResponse();
            using (_session)
            {
                try
                {
                    IEnumerable<Container> containers = _session.Query<Container>();

                    if (!string.IsNullOrEmpty(query.SourceFilter))
                    {
                        containers = from c in containers
                                     where c.Source.ToLower().Contains(query.SourceFilter.ToLower())
                                     select c;
                    }
                    if (query.NumberFilter.HasValue && query.NumberFilter > 0)
                    {
                        containers = from c in containers
                                     where c.Number == query.NumberFilter
                                     select c;
                    }
                    if (!string.IsNullOrEmpty(query.DescriptionFilter))
                    {
                        containers = from c in containers
                                     where c.Description.ToLower().Contains(query.DescriptionFilter.ToLower())
                                     select c;
                    }
                    if (query.DatePackedFilter.HasValue && query.DatePackedFilter > DateTime.MinValue)
                    {
                        containers = from c in containers
                                     where c.DatePacked == query.DatePackedFilter
                                     select c;
                    }
                    response.Containers = containers.ToArray();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Get(ContainerQuery): {0}", ex.Message);
                    throw;
                }
            }
            return response;
        }
Ejemplo n.º 4
0
        public void TestQueryContainerByDescription()
        {
            var container1 = new Container
            {
                Number = 1,
                Description = "Workbench, electronic parts, soldering irons, tools",
                Source = "Garage",
                Destination = "Garage",
                DatePacked = new DateTime(2013, 6, 12)
            };
            var container2 = new Container
            {
                Number = 2,
                Description = "Power tools, chargers, batteries, bits",
                Source = "Garage",
                Destination = "Garage",
                DatePacked = new DateTime(2013, 6, 13)
            };
            var response1 = _client.Post<ContainerResponse>(container1);
            container1.Id = response1.Id;
            var response2 = _client.Post<ContainerResponse>(container2);
            container2.Id = response2.Id;

            var queryRequest = new ContainerQuery
            {
                SourceFilter = null,
                NumberFilter = null,
                DescriptionFilter = "soldering",
                DatePackedFilter = null
            };

            var queryResponse = _client.Get<ContainerQueryResponse>(queryRequest);
            Assert.IsNotNull(queryResponse);
            Assert.AreEqual(1, queryResponse.Containers.Length);
            Assert.IsTrue(queryResponse.Containers[0].Description.ToLower().Contains("soldering"));

            _client.Delete(container1);
            _client.Delete(container2);
        }