示例#1
0
        public async Task <object> MakeGlue(string code)
        {
            if (code == null || code == string.Empty)
            {
                return(new IngredientDto());
            }
            var item = await(from a in _context.GlueIngredient
                             join b in _context.Glues on a.GlueID equals b.ID
                             join c in _context.Ingredients on a.IngredientID equals c.ID
                             select new GlueIngredientDto
            {
                ID         = a.GlueID,
                Name       = b.Name,
                Code       = b.Code,
                Ingredient = c,
                Percentage = a.Percentage
            }).FirstOrDefaultAsync(x => x.Code.Contains(code));
            var list  = new List <IngredientDto>();
            var glues = new GlueDto();

            glues.ID   = item.ID;
            glues.Name = item.Name;
            glues.Code = item.Code;

            list.Add(new IngredientDto
            {
                ID         = item.Ingredient.ID,
                Name       = item.Ingredient.Name,
                Percentage = item.Percentage,
                Code       = item.Ingredient.Code,
            });
            glues.Ingredients = list;
            return(glues);
        }
示例#2
0
        public async Task <object> GetGlueWithIngredientByGlueID(int glueid)
        {
            var model2 = await(from a in _context.GlueIngredient
                               join b in _context.Glues on a.GlueID equals b.ID
                               join c in _context.Ingredients on a.IngredientID equals c.ID
                               select new GlueIngredientDto
            {
                ID         = a.GlueID,
                Name       = b.Name,
                Code       = b.Code,
                Ingredient = c,
                Percentage = a.Percentage,
                Position   = a.Position,
                Allow      = a.Allow
            }).ToListAsync();
            var glues = new GlueDto();
            var list  = new List <IngredientDto>();

            foreach (var item in model2)
            {
                if (item.ID.Equals(glueid))
                {
                    glues.ID   = item.ID;
                    glues.Name = item.Name;
                    glues.Code = item.Code;

                    list.Add(new IngredientDto
                    {
                        ID         = item.Ingredient.ID,
                        Name       = item.Ingredient.Name,
                        Percentage = item.Percentage,
                        Code       = item.Ingredient.Code,
                        MaterialNO = item.Ingredient.MaterialNO,
                        Position   = item.Position,
                        Allow      = item.Allow
                    });
                }
            }
            glues.Ingredients = list.OrderBy(x => x.Position).ToList();
            return(glues);
        }
示例#3
0
        public async Task <object> GetGlueWithIngredientByGlueName(string glueName)
        {
            var model2 = await(from a in _context.GlueIngredient
                               join b in _context.Glues on a.GlueID equals b.ID
                               join c in _context.Ingredients on a.IngredientID equals c.ID
                               select new GlueIngredientDto
            {
                ID         = a.GlueID,
                Name       = b.Name,
                Code       = b.Code,
                Ingredient = c,
                Percentage = a.Percentage
            }).ToListAsync();
            var glues = new GlueDto();
            var list  = new List <IngredientDto>();

            foreach (var item in model2)
            {
                if (item.Name.Equals(glueName))
                {
                    glues.ID   = item.ID;
                    glues.Name = item.Name;
                    glues.Code = item.Code;

                    list.Add(new IngredientDto
                    {
                        ID         = item.Ingredient.ID,
                        Name       = item.Ingredient.Name,
                        Percentage = item.Percentage,
                        Code       = item.Ingredient.Code,
                    });
                }
            }
            glues.Ingredients = list.DistinctBy(x => x.Name).ToList();
            return(glues);
        }
示例#4
0
        public async Task <object> MakeGlue(int glueid)
        {
            var model2 = await(from a in _context.GlueIngredient
                               join b in _context.Glues on a.GlueID equals b.ID
                               join c in _context.Ingredients on a.IngredientID equals c.ID
                               select new GlueIngredientDto
            {
                ID         = a.GlueID,
                Name       = b.Name,
                Code       = b.Code,
                Ingredient = c,
                Percentage = a.Percentage
            }).ToListAsync();
            var glues = new GlueDto();
            var list  = new List <IngredientDto>();

            foreach (var item in model2)
            {
                if (item.ID == glueid)
                {
                    glues.ID   = item.ID;
                    glues.Name = item.Name;
                    glues.Code = item.Code;

                    list.Add(new IngredientDto
                    {
                        ID         = item.Ingredient.ID,
                        Name       = item.Ingredient.Name,
                        Percentage = item.Percentage,
                        Code       = item.Ingredient.Code,
                    });
                }
            }
            glues.Ingredients = list;
            return(glues);
        }