Пример #1
0
        public override Specification <Country> GetSpecification()
        {
            var spec = new Specification <Country>();

            if (!Ids.IsEmpty())
            {
                int[] ids = ArrayHelpers.StringToIntArray(Ids);
                if (ids != null && ids.Length > 0)
                {
                    spec.And(c => ids.Contains(c.Id));
                }
            }
            if (!Name.IsEmpty())
            {
                spec.And(c => c.Name.StartsWith(Name));
            }
            if (!Abbreviation.IsEmpty())
            {
                spec.And(c => c.Abbreviation.StartsWith(Abbreviation));
            }
            if (!ShowAll)
            {
                spec.And(c => c.Enabled == true);
            }
            return(spec);
        }
Пример #2
0
        public override Specification <Mapping> GetSpecification()
        {
            var spec = new Specification <Mapping>();

            if (!Ids.IsEmpty())
            {
                int[] ids = ArrayHelpers.StringToIntArray(Ids);
                if (ids != null && ids.Length > 0)
                {
                    spec.And(c => ids.Contains(c.Id));
                }
            }
            if (!ProductIds.IsEmpty())
            {
                int[] ids = ArrayHelpers.StringToIntArray(ProductIds);
                if (ids != null && ids.Length > 0)
                {
                    spec.And(c => ids.Contains(c.ProductId));
                }
            }
            if (StoreId.HasValue)
            {
                spec.And(m => m.StoreId.Equals(StoreId.Value));
            }
            if (!Sku.IsEmpty())
            {
                spec.And(m => m.Product.Sku.StartsWith(Sku));
            }
            if (!StoreSku.IsEmpty())
            {
                spec.And(m => m.StoreSku.StartsWith(StoreSku));
            }
            return(spec);
        }
Пример #3
0
        public override Specification <ReportGroupItem> GetSpecification()
        {
            var spec = new Specification <ReportGroupItem>();

            if (!Ids.IsEmpty())
            {
                int[] ids = ArrayHelpers.StringToIntArray(Ids);
                if (ids != null && ids.Length > 0)
                {
                    spec.And(c => ids.Contains(c.Id));
                }
            }
            if (ReportGroupId.HasValue)
            {
                spec.And(i => i.ReportGroupId == ReportGroupId.Value);
            }
            if (!Sku.IsEmpty())
            {
                spec.And(i => i.Product.Sku.StartsWith(Sku));
            }
            if (!Name.IsEmpty())
            {
                spec.And(i => i.Product.Name.Contains(Name));
            }
            return(spec);
        }
        private Specification <Jugador> GetJugadorSpecification()
        {
            Specification <Jugador> specification = Specification <Jugador> .All;

            specification = specification.And(new JugadoresDelanterosSpecification());
            specification = specification.And(new JugadorClubBySpecification("UNIVERSITARIO DE DEPORTES"));
            return(specification);
        }
Пример #5
0
 public SaleLead FindOrCreateSaleLead(CustomerDTO cus, int orderNo, EmployeeDTO emp)
 {
     var cusSpec = new Specification<SalePositionLead>(c => c.SaleLead.CustomerId == cus.CustomerId);
     var saleSpec = new Specification<SalePositionLead>(s => s.SaleLead.Sale.OrderNumber == orderNo);
     var cusAndSale = cusSpec.And(saleSpec);
     var lead = _repoSalePositionLead.Find(cusAndSale);
     if (lead == null)
     {
         var cusNameSpec = new Specification<SalePositionLead>(c => c.SaleLead.Customer.Name == cus.CustomerName);
         var cusNameAndSale = cusNameSpec.And(saleSpec);
         lead = _repoSalePositionLead.Find(cusNameAndSale);
         if(lead == null)
         {
             var empSpec = new Specification<SalePositionLead>(x => x.EmployeeInSalePosition.Employee.Id == emp.EmployeeId);
             var otherCusSpec = new Specification<SalePositionLead>(v => v.SaleLead.Customer.Id == cus.CustomerId);
             var otherAndEmp = empSpec.And(otherCusSpec);
             lead = _repoSalePositionLead.Find(otherAndEmp);
             if(lead==null)
             {
                 var cusNameAndEmpSpec = empSpec.And(cusNameSpec);
                 lead = _repoSalePositionLead.Find(cusNameAndEmpSpec);
                 if(lead == null)
                 {
                     var customer = _repoCustomer.Get(cus.CustomerId);
                     var state = _repoSaleLeadState.AsQueryable().FirstOrDefault(x => x.Id > 0);
                     var l = CreateSaleLead(customer.Id, state.Id, 0, DateTime.Now);
                     _repoSaleLead.Add(l);
                     return l;
                 }
                 else
                 {
                     return lead.SaleLead;
                 }
                 
             }
             else
             {
                 return lead.SaleLead;
             }
             
         }
         else
         {
             return lead.SaleLead;
         }
         
     }
     else
     {
         return lead.SaleLead;
     }
 }
        protected override ISpecification <OtherDocumentItemDto> ToSpecification(IWorkItemStrategy workItemStrategy)
        {
            var specification = new Specification <OtherDocumentItemDto>();

            if (!(workItemStrategy is OtherDocumentItemWorkItemStrategy strategy))
            {
                return(specification);
            }

            if (strategy.WithNestedItems)
            {
                if (strategy.NestedItemWorkItemStrategy.WithOneMoreNestedItems)
                {
                    specification.FetchStrategy.Add(w => w.Include(x => x.NestedItemDtos)
                                                    .ThenInclude(x => x.OneMoreNestedItemDtos));
                }
                else
                {
                    specification.FetchStrategy.Add(w => w.Include(x => x.NestedItemDtos));
                }
            }

            if (!strategy.WithDeleted)
            {
                specification.And(OnlyNotDeletedSpecification);
            }

            return(specification);
        }
        public void EfCore_FindAll_With_Include_And_Predicate_In_Specs_LazyLoads_Email()
        {
            var repository = new EfCoreRepository <Contact, string>(dbContext);

            var findAllBySpec = new Specification <Contact>(obj => obj.ContactId == "1")
                                .And(obj => obj.EmailAddresses.Any(m => m.Email == "*****@*****.**"));

            var specification = new Specification <Contact>(obj => obj.Name == "Test User 1");

            findAllBySpec.FetchStrategy = new GenericFetchStrategy <Contact>();
            findAllBySpec.FetchStrategy
            .Include(obj => obj.EmailAddresses);

            // NOTE: This line will erase my FetchStrategy from above
            if (null != specification)
            {
                findAllBySpec = findAllBySpec.And(specification);
            }

            var contact = repository.FindAll(findAllBySpec).First();

            contact.Name.ShouldBe("Test User 1");
            dbContext.QueryLog.Count(filterSelects).ShouldBe(2);
            contact.EmailAddresses.First().Email.ShouldBe("*****@*****.**");
            dbContext.QueryLog.Count(filterSelects).ShouldBe(2);

            repository.FindAll(findAllBySpec).Count().ShouldBe(1);
        }
Пример #8
0
        public IPagingList <ProjectTargetCostDto> GetTargetCosts(ProjectQueryRequest queryRequest)
        {
            var specification = new Specification <VIProjectTargetCost>();

            if (!string.IsNullOrEmpty(queryRequest.Code))
            {
                specification.And(n => n.Code.Contains(queryRequest.Code));
            }
            if (!string.IsNullOrEmpty(queryRequest.Name))
            {
                specification.And(n => n.Name.Contains(queryRequest.Name));
            }
            specification.SetPage(queryRequest);

            return(repository.PagingList(specification).ProjectedAsPagingList <ProjectTargetCostDto>());
        }
Пример #9
0
        private Specification <Employee> GetFindByUsername(string Username)
        {
            Specification <Employee> specification = Specification <Employee> .All;

            specification = specification.And(new FindByUsernameBySpecification(Username));
            return(specification);
        }
Пример #10
0
        private Specification <Employee> GetLogingSpecification(string usu, string clave)
        {
            Specification <Employee> specification = Specification <Employee> .All;

            specification = specification.And(new LoginBySpecification(usu, clave));
            return(specification);
        }
Пример #11
0
        public void And_IsSatisfiedBy_ShouldBeFalseWith(int value)
        {
            var specification = new Specification <int>(v => v > 0);
            var secondSpec    = new Specification <int>(v => v < 10);

            Assert.False(specification.And(secondSpec).IsSatisfiedBy(value));
        }
Пример #12
0
        private Specification <Product> GetLikeSearchByName(string ProductName)
        {
            Specification <Product> specification = Specification <Product> .All;

            specification = specification.And(new LikeSearchByNameSpecification(ProductName));
            return(specification);
        }
Пример #13
0
        private Specification <Product> GetFindByCategory(long Category_id)
        {
            Specification <Product> specification = Specification <Product> .All;

            specification = specification.And(new FindByCategoryBySpecification(Category_id));
            return(specification);
        }
        private Specification <Customer> GetById(long CustomerId)
        {
            Specification <Customer> specification = Specification <Customer> .All;

            specification = specification.And(new GetByIdBySpecification(CustomerId));
            return(specification);
        }
        private Specification <Customer> GetFindByDocumentNumber(string DocumentNumber)
        {
            Specification <Customer> specification = Specification <Customer> .All;

            specification = specification.And(new FindByDocumentNumberBySpecification(DocumentNumber));
            return(specification);
        }
Пример #16
0
        private Specification <Movie> GetMovieSpecification(bool forKidsOnly, bool onCD)
        {
            Specification <Movie> specification = Specification <Movie> .All;

            if (forKidsOnly)
            {
                specification = specification.And(new MovieForKidsSpecification());
            }
            if (onCD)
            {
                specification = specification.And(new AvailableOnCDSpecification());
            }
            specification = specification.And(new MovieDirectedBySpecification("Bill Condon"));
            //spec = new MovieDirectedBySpecification("Marc Webb");
            return(specification);
        }
Пример #17
0
        protected override ISpecification <DocumentDto> ToSpecification(IWorkItemStrategy documentWorkItemStrategy)
        {
            var specification = new Specification <DocumentDto>();

            specification.FetchStrategy.Add(w => w.Include(x => x.OtherDocumentDto));
            // add Inlcude all inherited types..

            if (!(documentWorkItemStrategy is DocumentWorkItemStrategy strategy))
            {
                return(specification);
            }

            if (strategy.WithAttachments)
            {
                specification.FetchStrategy.Add(
                    w => w.Include(x => x.AttachmentLinkDtos)
                    .ThenInclude(x => x.AttachmentDto)
                    );
            }

            if (!strategy.WithDeleted)
            {
                specification.And(OnlyNotDeletedSpecification);
            }

            return(specification);
        }
Пример #18
0
        private Specification <Product> GetById(long ProductId)
        {
            Specification <Product> specification = Specification <Product> .All;

            specification = specification.And(new GetByIdBySpecification(ProductId));
            return(specification);
        }
Пример #19
0
        private Specification <Product> GetFindByName(string ProductName)
        {
            Specification <Product> specification = Specification <Product> .All;

            specification = specification.And(new FindByNameBySpecification(ProductName));
            return(specification);
        }
Пример #20
0
        private Specification <Provider> GetFindByName(string Name)
        {
            Specification <Provider> specification = Specification <Provider> .All;

            specification = specification.And(new FindByNameSpecification(Name));
            return(specification);
        }
        private Specification <Producto> GetProductospecification(bool?all)
        {
            Specification <Producto> specification = Specification <Producto> .All;

            specification = specification.And(new ProductoNameBySpecification("Leche Gloria Deslactosada 400gm"));
            return(specification);
        }
 public override bool IsSatisfiedBy(Order candidate)
 {
     return(domesticOrderSpec
            .And(highValueSpec)
            .And(inStockSpec)
            .And(hazardousSpec.Not())
            .IsSatisfiedBy(candidate));
 }
Пример #23
0
        private void Search()
        {
            Specification <Movie> spec = Specification <Movie> .All;

            if (ForKidsOnly)
            {
                spec = spec.And(new MovieForKidsSpecification());
            }
            if (OnCD)
            {
                spec = spec.And(new AvailableOnCDSpecification());
            }

            Movies = _repository.GetList(spec, MinimumRating);

            Notify(nameof(Movies));
        }
Пример #24
0
 private Pagination <Game> MyGameList(int page, Specification <Game> statusSpec)
 {
     return(_gameRepository.Paginate(
                page, PAGE_SIZE,
                statusSpec.And(new ContainsPlayerSpecification(AuthContext.UserId)),
                new GameIdSort()
                ));
 }
Пример #25
0
        public Specification <TEntity> ValidSpec <TEntity>(Specification <TEntity> spec) where TEntity : class, IEntity, new()
        {
            var nameSpecType = typeof(NameSpec <>).MakeGenericType(typeof(TEntity));
            var nameSpec     = Activator.CreateInstance(nameSpecType);
            //Specification<TEntity> nameSpec = (Specification<TEntity>)(object)new NameSpec<TEntity>();
            var newSpec = nameSpec as Specification <TEntity>;

            return(spec == null ? newSpec : spec.And(newSpec));
        }
Пример #26
0
        public IPagingList <SupplierDto> GetPagingList(SupplierQueryRequest filterRequest)
        {
            Specification <Supplier> specification = new Specification <Supplier>();

            specification.SetPage(filterRequest);
            if (!string.IsNullOrEmpty(filterRequest.Name))
            {
                specification.And(n => n.Name.Contains(filterRequest.Name));
            }
            if (!string.IsNullOrEmpty(filterRequest.ManName))
            {
                specification.And(n => n.ManName.Contains(filterRequest.ManName));
            }
            int total = 0;
            var list  = repository.PageList(specification, ref total);

            return(list.ProjectedAsPagingList <SupplierDto>(total, filterRequest));
        }
Пример #27
0
        public override Expression <Func <T, bool> > ToExpression()
        {
            var notLeftAndRight = _left.Not().And(_right);
            var leftAndNotRight = _left.And(_right.Not());

            var xOr = notLeftAndRight.Or(leftAndNotRight);

            return(xOr.ToExpression());
        }
Пример #28
0
        public override Specification <ReportGroup> GetSpecification()
        {
            var spec = new Specification <ReportGroup>();

            if (!Ids.IsEmpty())
            {
                int[] ids = ArrayHelpers.StringToIntArray(Ids);
                if (ids != null && ids.Length > 0)
                {
                    spec.And(c => ids.Contains(c.Id));
                }
            }
            if (!Name.IsEmpty())
            {
                spec.And(c => c.Name.StartsWith(Name));
            }
            return(spec);
        }
Пример #29
0
        private void Search()
        {
            // Specification<Movie> spec = null;
            // diyemeyiz çünkü alttaki ifadeler spec üzerinde çalışıyorlar.
            Specification <Movie> spec = Specification <Movie> .All;

            if (ForKidsOnly)
            {
                spec = spec.And(new MovieForKidsSpecification());
            }
            if (OnCD)
            {
                spec = spec.And(new AvailableOnCDSpecification());
            }

            Movies = _repository.GetList(spec, MinimumRating);

            Notify(nameof(Movies));
        }
Пример #30
0
        public void InvokeAnd_ReturnAndSpecification()
        {
            var left     = MockComplexSpecification.True();
            var right    = MockComplexSpecification.False();
            var expected = new AndSpecification <object>(left, right);

            var sut = Specification.And(left, right);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
Пример #31
0
 public void AndShouldNotAllowNull()
 {
     // arrange
     ISpecification<string> other = null;
     var target = new Specification<string>( s => true );
     
     // act
     var ex = Assert.Throws<ArgumentNullException>( () => target.And( other ) );
     
     // assert
     Assert.Equal( "other", ex.ParamName );
 }
Пример #32
0
        public void AndShouldReturnCombinedSpecification()
        {
            // arrange
            var s1 = new Specification<string>( s => true );
            var s2 = new Specification<string>( s => false );

            // act
            var actual = s1.And( s2 );

            // assert
            Assert.NotNull( actual );
        }
        public void It_should_return_zero_entities_not_matching_any_specifications()
        {
            //	ARRANGE
            var repository = Fixture.CreateRepository();
            var nonExistingAge = -999;
            var existingLastName = "Tran";

            //	ACT
            var over30Match = new Specification<Customer>(p => p.Age == nonExistingAge);
            var lastNameMatch = new Specification<Customer>(p => p.LastName == existingLastName);
            var entities = repository.FindAll<Customer>(over30Match.And(lastNameMatch)).ToList();

            //	ASSERT
            Assert.AreEqual(0, entities.Count);
        }
        public void It_should_return_entities_matching_all_specifications()
        {
            //	ARRANGE
            var repository = Fixture.CreateRepository();
            var existingAge = 40;
            var existingLastName = "Tran";

            //	ACT
            var over30Match = new Specification<Customer>(p => p.Age > existingAge);
            var lastNameMatch = new Specification<Customer>(p => p.LastName == existingLastName);
            var entities = repository.FindAll<Customer>(over30Match.And(lastNameMatch)).ToList();

            //	ASSERT
            Assert.AreEqual(1, entities.Count);
            Assert.AreEqual("Peter Tran", entities[0].GetFullName());
        }
Пример #35
0
 public void Should_return_itself_on_adding_and_operator_when_other_specification_is_null()
 {
     var expected = new Specification<string>(s => s.Contains("a"));
     var target = expected.And(null);
     Assert.That(target, Is.SameAs(expected));
 }