public IngredientModel GetDetail(string id) { try { IngredientModel model = _factory.GetIngredientById(id); if (!string.IsNullOrEmpty(model.CompanyId)) { model.CompanyName = lstCompany.Where(z => z.Value.Equals(model.CompanyId)).FirstOrDefault().Text; } else { model.CompanyName = "None"; } model.GetFillData(CurrentUser.ListOrganizationId); //============= var ListIngUOM = _IngredientUOMFactory.GetDataForIngredient(model.Id); for (int i = 0; i < ListIngUOM.Count; i++) { var IngUOM = ListIngUOM[i]; model.ListIngUOM.Add(new IngredientUOMModels { Id = IngUOM.Id, OffSet = i, UOMId = IngUOM.UOMId, ReceivingQty = IngUOM.ReceivingQty, UOMName = IngUOM.UOMName }); } var ListIngSup = _IngredientSupplierFactory.GetDataForIngredient(model.Id, model.CompanyId); var lstSupplierItem = _SupplierFactory.GetData(); lstSupplierItem = lstSupplierItem.Where(x => x.CompanyId.Equals(model.CompanyId)).ToList(); if (lstSupplierItem != null) { foreach (SupplierModels supplier in lstSupplierItem) { model.ListIngSupplier.Add(new Ingredients_SupplierModel { Id = supplier.Id, SupplierName = supplier.Name, SupplierAddress = supplier.Address, SupplierPhone = supplier.Phone1 + " - " + supplier.Phone2, //IsCheck = false, IsActived = ListIngSup.Any(x => x.Equals(supplier.Id)), CompanyId = supplier.CompanyId }); } model.ListIngSupplier = model.ListIngSupplier.OrderBy(oo => oo.SupplierName).ToList(); } //model.ListIngSupplier.ForEach(x => //{ // x.IsCheck = ListIngSup.Any(z => z.Equals(x.Id)); //}); model.ListIngSupplier = model.ListIngSupplier.Where(x => x.IsActived).OrderByDescending(x => x.IsActived ? 1 : 0).ThenBy(x => x.IngredientName).ToList(); return(model); } catch (Exception ex) { _logger.Error("IngredienDetail: " + ex); return(null); } }