public async Task <IActionResult> GetAllWithDividers(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc") { List <EDeliveryProduct> list = SDeliveryProducts.GetAll(companyID, listCount, pageNumber, orderBy); List <EDeliveryProduct> returnList = new List <EDeliveryProduct>(); list = list.OrderBy(x => x.categoryID).ToList(); for (int i = 0; i < list.Count; i++) { var eProduct = list.ElementAt(i); string categoryName = ""; if (!string.IsNullOrEmpty(eProduct.categoryID)) { var eCategory = await SDeliveryProductsCategories.GetByID(eProduct.categoryID); categoryName = eCategory.name; } if (!returnList.Any()) { returnList.Add(new EDeliveryProduct { categoryID = eProduct.categoryID, isCategory = true, categoryName = categoryName }); } else if (returnList.Last().categoryID != eProduct.categoryID) { returnList.Add(new EDeliveryProduct { categoryID = eProduct.categoryID, isCategory = true, categoryName = categoryName }); } returnList.Add(eProduct); } return(Ok(returnList)); }
//todo recolocar [RestXInPeaceGet(1, "List<List<EDeliveryProduct>> GetAllDividedByCategory(segment string companyID, optional int listCount=-1, optional int pageNumber=0,optional string orderBy='name asc')")] public IActionResult GetAllDividedByCategory(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc") { List <EDeliveryProduct> list = SDeliveryProducts.GetAll(companyID, listCount, pageNumber, orderBy); List <List <EDeliveryProduct> > returnList = new List <List <EDeliveryProduct> >(); list = list.OrderBy(x => x.categoryID).ToList(); returnList = list.GroupBy(item => item.categoryID) .Select(group => group.ToList()) .ToList(); return(Ok(returnList)); }
public async Task <IActionResult> GetAll(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc") { var list = SDeliveryProducts.GetAll(companyID, listCount, pageNumber, orderBy); foreach (EDeliveryProduct eDeliveryProduct in list) { if (string.IsNullOrEmpty(eDeliveryProduct.categoryID)) { continue; } var eCategory = await SDeliveryProductsCategories.GetByID(eDeliveryProduct.categoryID); eDeliveryProduct.categoryName = eCategory.name; } return(Ok(list)); }