//ITEM COMPLETION PERCENT //public double GetProductCompletionPercent(int prodId) //{ // double result = 0; // using (var context = new RestaurantDBEntities()) // { // result = GetProductCompletionPercent(context.Products.Single(x => x.Id == prodId)); // } // return result; //} //public double GetProductCompletionPercent(Product p) //{ // double totalConditionsCount = 1;//category // double passedConditions = 0; // if (p.CategoryId != null) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.Description)) passedConditions++; // if (p.ProductType == ProductType.FinishedGoods) // { // totalConditionsCount += 3; // if (p.Code > 0) passedConditions++; // if (p.SalePrice > 0) passedConditions++; // if (p.Ingredients.Count > 0) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.ProductionProcess)) passedConditions++; // } // else if (p.ProductType == ProductType.WorkInProcess) // { // totalConditionsCount += 1; // if (p.Ingredients.Count > 0) passedConditions++; // //if (p.Outgredients.Count > 0) passedConditions++; // //if (!string.IsNullOrWhiteSpace(p.ProductionProcess)) passedConditions++; // } // else if (p.ProductType == ProductType.RawMaterials) // { // totalConditionsCount += 2; // if (p.ArbitraryCost > 0) passedConditions++; // //if (p.EdiblePart < 1) passedConditions++; // if (p.Outgredients.Count > 0) passedConditions++; // } // else if (p.ProductType == ProductType.CompraVenta) // { // totalConditionsCount += 3; // if (p.Code > 0) passedConditions++; // if (p.SalePrice > 0) passedConditions++; // if (p.ArbitraryCost > 0) passedConditions++; // } // return passedConditions * 100 / totalConditionsCount; //} #endregion #region Category List public void CreateCategoryList(IUnitOfWork unitOfWork, ObservableCollection <CategoryRowViewModel> targetList, NamingModes mode = NamingModes.SimpleName, Predicate <Category> filter = null) { if (targetList == null) { throw new ArgumentException("targetList"); } //targetList.Clear(); //start with root categories var query = from c in unitOfWork.CategoryRepository.Get(x => x.ParentCategory_Id == null) orderby c.Name select c; foreach (var item in query) { if (filter != null && !filter(item)) { continue; } CategoryRowViewModel crvm = new CategoryRowViewModel(); crvm.Id = item.Id; crvm.Name = item.Name; crvm.Level = 0; targetList.Add(crvm); AddChildrenList(targetList, filter, 1, mode, crvm, item); } }
private void AddChildrenList(ObservableCollection <CategoryRowViewModel> targetList, Predicate <Category> filter, int deep, NamingModes mode, CategoryRowViewModel parentRow, Category source) { foreach (var item in source.ChildrenCategories.OrderBy(x => x.Name)) { if (filter != null && !filter(item)) { continue; } CategoryRowViewModel crvm = new CategoryRowViewModel(); crvm.Id = item.Id; crvm.Level = parentRow.Level + 1; switch (mode) { case NamingModes.FullName: crvm.Name = parentRow.Name + ":" + item.Name; break; case NamingModes.SimpleName: crvm.Name = item.Name; break; default: break; } targetList.Add(crvm); AddChildrenList(targetList, filter, deep + 1, mode, crvm, item); } }