public List <RFilterCategoryModel> GetAllCategoriesForReport(CategoryApiRequestModel request) { var lstData = new List <RFilterCategoryModel>(); var lstResult = new List <RFilterCategoryModel>(); try { var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.GetCategoryReport, null, request); if (result.Success) { dynamic data = result.Data; var ListCate = data["ListCategories"]; RFilterCategoryModel obj = null; foreach (var item in ListCate) { obj = new RFilterCategoryModel(); obj.Id = item["Id"]; obj.Name = item["Name"]; obj.StoreId = item["StoreId"]; obj.StoreName = item["StoreName"]; obj.ParentId = item["ParentId"]; if (CommonHelper.IsPropertyExist(data, "Seq")) { obj.Seq = item["Seq"]; } lstData.Add(obj); //lstData.Add(new RFilterCategoryModel //{ // Id = item["Id"], // Name = item["Name"], // StoreId = item["StoreId"], // StoreName = item["StoreName"], // ParentId = item["ParentId"], // Seq = item["Seq"], //}); } var lstParentOrNotChild = lstData.Where(ww => string.IsNullOrEmpty(ww.ParentId)).OrderBy(ww => ww.Seq).ThenBy(aa => aa.Name).ToList(); var lstChilds = lstData.Where(ww => !string.IsNullOrEmpty(ww.ParentId)).ToList(); foreach (var item in lstParentOrNotChild) { lstResult.Add(GetCategoryModel(item, lstChilds)); } } lstResult = lstResult.OrderBy(oo => oo.StoreName).ToList(); return(lstResult); } catch (Exception e) { _logger.Error("GetCate Report: " + e); return(lstData); } }
public List <RFilterCategoryModel> GetListModifier(List <string> lstStoreIds, int typeId = 2) { List <RFilterCategoryModel> data = new List <RFilterCategoryModel>(); List <RFilterCategoryModel> results = new List <RFilterCategoryModel>(); CategoryApiRequestModel request = new CategoryApiRequestModel(); if (typeId == 1) { var lstCompany = new List <SelectListItem>(); for (int i = 0; i < lstStoreIds.Count; i++) { SelectListItem obj = new SelectListItem() { Value = lstStoreIds[i] }; lstCompany.Add(obj); } var lstStores = _storeFactory.GetListStore(lstCompany); lstStoreIds = lstStores.Select(ss => ss.Value).ToList(); } request.ListStoreIds = lstStoreIds; request.Type = (int)Commons.EProductType.Modifier; ProductFactory _factoryPro = new ProductFactory(); RFilterCategoryModel objt = null; var result = _factoryPro.GetListProduct(null, (byte)Commons.EProductType.Modifier, CurrentUser.ListOrganizationId); if (result != null && result.Count > 0) { result = result.Where(x => x.IsActive).ToList(); foreach (var item in result) { objt = new RFilterCategoryModel(); objt.Id = item.ID; objt.Name = item.Name; objt.StoreId = item.StoreID; objt.StoreName = item.StoreName; objt.ParentId = item.ParentID; data.Add(objt); } var lstParentOrNotChild = data.Where(ww => string.IsNullOrEmpty(ww.ParentId)).OrderBy(ww => ww.Seq).ThenBy(aa => aa.Name).ToList(); var lstChilds = data.Where(ww => !string.IsNullOrEmpty(ww.ParentId)).ToList(); foreach (var item in lstParentOrNotChild) { results.Add(GetCategoryModel(item, lstChilds)); } } return(results); }
private RFilterCategoryModel GetCategoryModel(RFilterCategoryModel item, List <RFilterCategoryModel> listFull, int count = 0) { count++; var lstGrandChilds = listFull.Where(ww => ww.ParentId == item.Id && ww.StoreId == item.StoreId).OrderBy(ww => ww.Seq).ToList(); if (lstGrandChilds.Count > 0) { foreach (var child in lstGrandChilds) { item.ListChilds.Add(GetCategoryModel(child, listFull, count)); } } return(item); }