Ejemplo n.º 1
0
        public List <RecipeProductModelEntity> GetRecomendedProducts(int countChildren)
        {
            List <RecipeProductModelEntity> Products = new List <RecipeProductModelEntity>();

            using (var context = new ProyectoMaestriaEntities())
            {
                var result = (
                    from P in context.Product
                    join D in context.Disponibility on P.ID equals D.IDProduct
                    join I in context.Ingredient on P.ID equals I.IDProduct
                    into PI
                    from fd in PI.DefaultIfEmpty()
                    where D.Quantity >= countChildren
                    group new { P, D, fd } by new { P.ProductType, P.ID, P.Code, P.MeasurementUnit, P.Name, P.Preservation, P.Description, D.Quantity, fd.Id } into g
                    select new
                {
                    ID = g.Key.ID,
                    Code = g.Key.Code,
                    MeasurementUnit = g.Key.MeasurementUnit,
                    Name = g.Key.Name,
                    Preservation = g.Key.Preservation,
                    Description = g.Key.Description,
                    ProductType = g.Key.ProductType,
                    leftfd = (long?)g.Key.Id,
                    Quantity = g.Sum(s => s.D.Quantity)
                }).ToList();

                if (result != null)
                {
                    foreach (var temp in result)
                    {
                        if (temp.leftfd == null)
                        {
                            RecipeProductModelEntity product = new RecipeProductModelEntity();
                            product.ID              = temp.ID;
                            product.Code            = temp.Code;
                            product.MeasurementUnit = temp.MeasurementUnit;
                            product.Name            = temp.Name;
                            product.Preservation    = temp.Preservation;
                            product.Description     = temp.Description;
                            product.disponibility   = temp.Quantity;
                            product.ProductType     = temp.ProductType;


                            //  product.Disponibility = temp.Disponibility;

                            Products.Add(product);
                        }
                    }

                    return(Products);
                }
                else
                {
                    return(Products);
                }
            }
        }