//allows to use the method without creating an instance of this class
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery,
                                                    ISpecifications <TEntity> spec)
        {
            var query = inputQuery;

            if (spec.Criteria != null)
            {
                query = query.Where(spec.Criteria);
            }

            if (spec.OrderBy != null)
            {
                query = query.OrderBy(spec.OrderBy);
            }

            if (spec.OrderByDesceding != null)
            {
                query = query.OrderByDescending(spec.OrderByDesceding);
            }

            if (spec.IsPagingEnabled)
            {
                query = query.Skip(spec.Skip).Take(spec.Take);
            }

            query = spec.Includes.Aggregate(query, (current, include) => current.Include(include));

            return(query);
        }
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpecifications <TEntity> spec)
        {
            var query = inputQuery;

            if (spec.Criteria != null)
            {
                query = query.Where(spec.Criteria);
            }

            if (spec.OrderBy != null)
            {
                query = query.OrderBy(spec.OrderBy);
            }

            if (spec.OrderByDesc != null)
            {
                query = query.OrderByDescending(spec.OrderByDesc);
            }

            // look up on every include then add one by one sequentialy.
            query = spec.Includes.Aggregate(query, (current, include) => current.Include(include));

            if (spec.IsPagingEnable)
            {
                query = query.Skip(spec.Skip).Take(spec.Take);
            }

            return(query);
        }
Exemple #3
0
        public ISpecifications ScalarMultiplySpecifications(ISpecifications specifications, float scalar)
        {
            var specs = specifications as BoxSpecifications;
            var scale = RepairScale(specs.GetScale() * scalar);

            return(new BoxSpecifications(specs.GetBoxNumber(), scale));
        }
 public MemberSerializations(ISpecifications specifications, IMemberSerializations serialization,
                             IContentMembers content)
 {
     _specifications = specifications;
     _serialization  = serialization;
     _content        = content;
 }
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpecifications <TEntity> spec)
        {
            var query = inputQuery;

            if (spec.Criteria != null)
            {
                query = query.Where(spec.Criteria);
            }
            if (spec.OrderBy != null)
            {
                query = query.OrderBy(spec.OrderBy);
            }
            if (spec.OrderByDescending != null)
            {
                query = query.OrderByDescending(spec.OrderByDescending);
            }
            if (spec.isPagingEnabled)
            {
                query = query.Skip(spec.Skip).Take(spec.Take);
            }

            //Here order matters, we want the paging to happen after any filtering or sorting.
            //If we filtering our results early then we wouldnt want to page our results before what knowing what results are we paging.

            query = spec.Includes.Aggregate(query, (current, include) => current.Include(include));
            return(query);
        }
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> sourceData, ISpecifications <TEntity> spec)
        {
            var finalQuery = sourceData;

            if (spec.Criteria != null)
            {
                finalQuery = finalQuery.Where(spec.Criteria);
            }

            if (spec.OrderByDescendingExpression != null)
            {
                finalQuery = finalQuery.OrderByDescending(spec.OrderByDescendingExpression);
            }

            if (spec.OrderByExpression != null)
            {
                finalQuery = finalQuery.OrderBy(spec.OrderByExpression);
            }

            if (spec.IsPaginationActivated)
            {
                finalQuery = finalQuery.Skip(spec.Skip).Take(spec.Take);
            }

            finalQuery = spec.Includes
                         .Aggregate(finalQuery,
                                    (currentQuery, currentIncludeExpression) => currentQuery.Include(currentIncludeExpression));

            return(finalQuery);
        }
Exemple #7
0
        public ISpecifications AddSpecifications(ISpecifications specifications1, ISpecifications specifications2)
        {
            var specs1 = specifications1 as BoxSpecifications;
            var specs2 = specifications2 as BoxSpecifications;
            var scale  = RepairScale(specs1.GetScale() + specs2.GetScale());

            return(new BoxSpecifications(specs1.GetBoxNumber(), scale));
        }
Exemple #8
0
        public ISpecifications ScalarMultiplySpecifications(ISpecifications specifications, float scalar)
        {
            var specs    = specifications as WheelSpecifications;
            var newScale = RepairScale(specs.GetScale() * scalar);
            var newSpecs = new WheelSpecifications(specs.GetWheelNumber());

            newSpecs.SetScale(newScale);
            return(newSpecs);
        }
Exemple #9
0
        public ISpecifications AddSpecifications(ISpecifications specifications1, ISpecifications specifications2)
        {
            var specs1   = specifications1 as WheelSpecifications;
            var specs2   = specifications2 as WheelSpecifications;
            var newSpecs = new WheelSpecifications(specs1.GetWheelNumber());
            var newScale = RepairScale(specs1.GetScale() + specs2.GetScale());

            newSpecs.SetScale(newScale);
            return(newSpecs);
        }
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpecifications <TEntity> spec)
        {
            var query = inputQuery;

            if (spec.Criteria != null)
            {
                query = query.Where(spec.Criteria);
            }

            query = spec.Includes.Aggregate(query, (current, inclued) => current.Include(inclued));

            return(query);
        }
Exemple #11
0
        public void Mutate(List <IGene> indivizi, float f)
        {
            var operations = new BoxSpecificationsOperations();
            var wheelGenes = indivizi.Select(gene => gene as BoxGene).ToList();
            var minusSpec  = operations
                             .ScalarMultiplySpecifications(wheelGenes[2].Specifications, -1);
            var firstAddSpec = operations.AddSpecifications(minusSpec, wheelGenes[1].Specifications);
            var fSpec        = operations.ScalarMultiplySpecifications(firstAddSpec, f);

            Specifications = operations.AddSpecifications(wheelGenes[3].Specifications, fSpec);
            var temp = Specifications as BoxSpecifications;

            Debug.Log($"Box scale {temp.GetScale()} mass {temp.GetMass()}");
        }
        public void Mutate(List <IGene> indivizi, float f)
        {
            var operations = new CarBodySpecificationsOperations();
            var wheelGenes = indivizi.Select(gene => gene as CarBodyGene).ToList();
            var minusSpec  = operations
                             .ScalarMultiplySpecifications(wheelGenes[2].Specifications, -1);
            var firstAddSpec = operations.AddSpecifications(minusSpec, wheelGenes[1].Specifications);
            var fSpec        = operations.ScalarMultiplySpecifications(firstAddSpec, f);

            Specifications = operations.AddSpecifications(wheelGenes[3].Specifications, fSpec);
            var temp = Specifications as CarBodySpecifications;

            Debug.Log($"Car scale x {temp.GetScale().Item1} y {temp.GetScale().Item2}");
        }
        public ISpecifications ScalarMultiplySpecifications(ISpecifications specifications, float scalar)
        {
            CarBodySpecifications specs = (CarBodySpecifications)specifications;
            var result = new CarBodySpecifications();
            Tuple <float, float> newScale = RepairScale(ScalarMultiplyScale(result, scalar));

            result.SetScale(newScale);
            var frontSpeed  = RepairSpeed(scalar * specs.MotorFrontSpeed);
            var backSpeed   = RepairSpeed(scalar * specs.MotorBackSpeed);
            var frontTorque = RepairTorque(scalar * specs.MotorFrontTorque);
            var backTorque  = RepairTorque(scalar * specs.MotorBackTorque);

            result.MotorBackSpeed   = backSpeed;
            result.MotorBackTorque  = backTorque;
            result.MotorFrontSpeed  = frontSpeed;
            result.MotorFrontTorque = frontTorque;
            return(result);
        }
        public ISpecifications AddSpecifications(ISpecifications specifications1, ISpecifications specifications2)
        {
            CarBodySpecifications carBodySpecifications1 = (CarBodySpecifications)specifications1;
            CarBodySpecifications carBodySpecifications2 = (CarBodySpecifications)specifications2;
            CarBodySpecifications result   = new CarBodySpecifications();
            Tuple <float, float>  newScale = RepairScale(GetScaleSum(carBodySpecifications1, carBodySpecifications2));

            result.SetScale(newScale);
            var frontSpeed =
                RepairSpeed(carBodySpecifications1.MotorFrontSpeed + carBodySpecifications2.MotorFrontSpeed);
            var backSpeed   = RepairSpeed(carBodySpecifications1.MotorBackSpeed + carBodySpecifications2.MotorBackSpeed);
            var frontTorque =
                RepairTorque(carBodySpecifications1.MotorFrontTorque + carBodySpecifications2.MotorFrontTorque);
            var backTorque =
                RepairTorque(carBodySpecifications1.MotorBackTorque + carBodySpecifications2.MotorBackTorque);

            result.MotorBackSpeed   = backSpeed;
            result.MotorBackTorque  = backTorque;
            result.MotorFrontSpeed  = frontSpeed;
            result.MotorFrontTorque = frontTorque;
            return(result);
        }
Exemple #15
0
        public static IQueryable <TEntity> GetQueryable(IQueryable <TEntity> inputQuery, ISpecifications <TEntity> spec)
        {
            var query = inputQuery;

            if (spec.Criteria != null)
            {
                query = query.Where(spec.Criteria); // in excutions p => p.ProductTypeId == id (lamda expression )
            }
            // to be as like same Working With this fun .Include(p =>p.ProductBrand)
            //.Include(p =>p.ProductType)
            //?????
            // Aggregate Query one or more query on ISpecifications class
            // this is {current} is  DATABASE instance  [Include] is dotnet freamework fun



            query = spec.Includes.Aggregate(query, (current, include) => current.Include(include));
            return(query);
        }
Exemple #16
0
 public async Task <List <Product> > GetALLproductWithIncude(ISpecifications <Product> spec)
 {
     return(await ApplySpecification(spec).ToListAsync());
 }
Exemple #17
0
 private IQueryable <Product> ApplySpecification(ISpecifications <Product> spec)
 {
     return(SpecificationEvaluator <Product> .GetQuery(_context.Set <Product>().AsQueryable(), spec));
 }
 public CarBodyGene(ISpecifications specifications)
 {
     Specifications = specifications;
 }
 public async Task <T> GetByIdWithSpecifications(ISpecifications <T> specifications)
 {
     return(await ApplySpecification(specifications).FirstOrDefaultAsync());
 }
 public async Task <T> GetEntityWithSpec(ISpecifications <T> spec)
 {
     return(await ApplySpecification(spec).FirstOrDefaultAsync());
 }
Exemple #21
0
 public BoxGene(ISpecifications specifications)
 {
     Specifications = specifications;
 }
 public async Task <int> CountAsync(ISpecifications <T> spec)
 {
     return(await ApplySpecification(spec).CountAsync());
 }
 public async Task <IReadOnlyCollection <T> > GetAllWithSpecifications(ISpecifications <T> specifications)
 {
     return(await ApplySpecification(specifications).ToListAsync());
 }
Exemple #24
0
 public async Task <Product> GetEntityWithSpec(ISpecifications <Product> spec, int id)
 {
     return(await ApplySpecification(spec).FirstOrDefaultAsync());
 }
 public async Task <IReadOnlyList <T> > ListAsync(ISpecifications <T> spec)
 {
     return(await ApplySpecification(spec).ToListAsync());
 }
 public async Task <int> CountNumberOfProducts(ISpecifications <T> specifications)
 {
     return(await ApplySpecification(specifications).CountAsync());
 }
 private IQueryable <T> ApplySpecification(ISpecifications <T> spec)
 {
     return(SpecificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec));
 }
 public WheelGene(ISpecifications specifications)
 {
     Specifications = specifications;
 }