Esempio n. 1
0
        public ActionResult LoadIngredient(string ProductId, string StoreId, int productType)
        {
            IngredientFactory IngFactory            = new IngredientFactory();
            var listProductRecipe                   = _factory.GetListRecipeProduct(ProductId, StoreId, productType, listStoreId);
            RecipeProductIngredientViewModels model = new RecipeProductIngredientViewModels();
            var m_CompanyIds = GetListCompany().Select(x => x.Value).ToList();
            var listIng      = new List <IngredientModel>();

            if (m_CompanyIds.Count > 0)
            {
                listIng = IngFactory.GetIngredient("").Where(x => m_CompanyIds.Contains(x.CompanyId)).ToList();
            }
            else
            {
                listIng = IngFactory.GetIngredient("").ToList();
            }
            listIng = listIng.Where(x => x.IsActive == true).ToList();

            foreach (var item in listIng)
            {
                var ProIngre = new ProductIngredient()
                {
                    BaseUOM = item.BaseUOMName,

                    IngredientId   = item.Id,
                    IngredientName = item.Name,
                    Usage          = listProductRecipe.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() == null
                                                    ? 0 : listProductRecipe.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).Usage,

                    BaseUOMId = listProductRecipe.Where(x => x.IngredientId.Equals(item.Id)).FirstOrDefault() == null
                                                    ? item.BaseUOMId : listProductRecipe.FirstOrDefault(x => x.IngredientId.Equals(item.Id)).UOMId,

                    IsSelect = listProductRecipe.Any(x => x.IngredientId.Equals(item.Id))
                };
                var lstItem = _UOMFactory.GetDataUOMRecipe(item.Id).ToList();
                if (lstItem != null)
                {
                    foreach (UnitOfMeasureModel uom in lstItem)
                    {
                        ProIngre.ListUOM.Add(new SelectListItem
                        {
                            Text     = uom.Name,
                            Value    = uom.Id,
                            Selected = uom.Id.Equals(ProIngre.BaseUOMId) == true ? true : false
                        });
                    }
                }
                model.ListItem.Add(ProIngre);
            }
            model.ListItem = model.ListItem.OrderByDescending(x => x.IsSelect ? 1 : 0).ThenBy(x => x.IngredientName).ToList();
            return(PartialView("_TableChooseIngredient", model));
        }