static public async Task <EDeliveryProduct> GetByID(string id) { using var context = new SMySQLContext(); EDeliveryProduct eDeliveryProduct = await context.DeliveryProducts.SingleOrDefaultAsync(x => x.id == id); if (!string.IsNullOrEmpty(eDeliveryProduct.option1ParentGroupID)) { eDeliveryProduct.option1ParentGroupName = SDeliveryProductsOptions.GetByID(eDeliveryProduct.option1ParentGroupID).name; } if (!string.IsNullOrEmpty(eDeliveryProduct.option2ParentGroupID)) { eDeliveryProduct.option2ParentGroupName = SDeliveryProductsOptions.GetByID(eDeliveryProduct.option2ParentGroupID).name; } if (!string.IsNullOrEmpty(eDeliveryProduct.addon1ParentGroupID)) { eDeliveryProduct.addon1ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon1ParentGroupID).name; } if (!string.IsNullOrEmpty(eDeliveryProduct.addon2ParentGroupID)) { eDeliveryProduct.addon2ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon2ParentGroupID).name; } if (!string.IsNullOrEmpty(eDeliveryProduct.addon3ParentGroupID)) { eDeliveryProduct.addon3ParentGroupName = SDeliveryProductsAddons.GetByID(eDeliveryProduct.addon3ParentGroupID).name; } return(eDeliveryProduct); }
static public List <EDeliveryProduct> GetAll(string companyID, int listCount = -1, int pageNumber = 0, string orderBy = "name asc") { using var context = new SMySQLContext(); List <EDeliveryProduct> list = null; if (listCount == -1) { list = context.DeliveryProducts.Where(x => x.companyID == companyID).OrderBy(orderBy).ToList(); } else { list = context.DeliveryProducts.Where(x => x.companyID == companyID).OrderBy(orderBy).Skip(pageNumber * listCount).Take(listCount).ToList(); } foreach (EDeliveryProduct eProduct in list) { if (!string.IsNullOrEmpty(eProduct.option1ParentGroupID)) { eProduct.option1ParentGroupName = SDeliveryProductsOptions.GetInternalNameIfAvailable(eProduct.option1ParentGroupID); } if (!string.IsNullOrEmpty(eProduct.option2ParentGroupID)) { eProduct.option2ParentGroupName = SDeliveryProductsOptions.GetInternalNameIfAvailable(eProduct.option2ParentGroupID); } if (!string.IsNullOrEmpty(eProduct.addon1ParentGroupID)) { eProduct.addon1ParentGroupName = SDeliveryProductsAddons.GetByID(eProduct.addon1ParentGroupID).name; } } //EList eList = new EList {items = list.Cast<object>().ToList(), totalListCount = context.DeliveryProducts.Count(x=>x.companyID==companyID)}; return(list); }