public void LoadDiscount() { AppData.Discount.DiscountCollection.Clear(); foreach (var discountRec in database.Table <Discount>()) { DiscountData discountData = new DiscountData(); discountData.DocumentId = discountRec.DocumentId; discountData.DiscountPercent = discountRec.PercentValue; discountData.IsFullDescription = discountRec.IsFullDescription; discountData.LogoFileName = discountRec.LogoFileName; var categoryList = from c in database.Table <Categorie>() where c.DiscountId == discountRec.Id select c; foreach (var categoryrec in categoryList) { discountData.CategorieList.Add(new CategorieData { TypeCode = categoryrec.TypeCode }); } var nameList = (from ds in database.Table <DiscountsStrings>() from ls in database.Table <LangString>() where ds.LangStringId == ls.Id where ds.OwnerId == discountRec.Id where ds.Appointment == StrAppointmentTitle select new { ls.Text, ls.LanguageCode }).ToList(); foreach (var nameRec in nameList) { discountData.SetName(nameRec.LanguageCode, nameRec.Text); } var descrList = (from ds in database.Table <DiscountsStrings>() from ls in database.Table <LangString>() where ds.LangStringId == ls.Id where ds.OwnerId == discountRec.Id where ds.Appointment == StrAppointmentDescription select new { ls.Text, ls.LanguageCode }).ToList(); foreach (var descrRec in descrList) { discountData.SetDescription(descrRec.LanguageCode, descrRec.Text); } AppData.Discount.DiscountCollection.Add(discountData); } }
private static Task <List <DiscountData> > LoadDiscounts( IEnumerable <Discount> discountsTable, IReadOnlyCollection <DiscountCategory> discountCategoriesTable, IReadOnlyCollection <DiscountsStrings> discountsStringsTable, IReadOnlyCollection <LangString> langStringsTable) { var result = new List <DiscountData>(); foreach (var discount in discountsTable) { var categories = discountCategoriesTable.Where(i => i.DiscountId == discount.Id) .Join(AppData.Discount.CategoryCollection, i => i.CategoryId, i => i.DocumentId, (dc, c) => c) .ToList(); var discountData = new DiscountData { DocumentId = discount.DocumentId, DiscountPercent = discount.PercentValue, DiscountType = discount.DiscountType.GetDiscountTypeName(), LogoFileName = discount.LogoFileName, CategoryList = categories, ModifiedDate = discount.Modified ?? DateTime.MinValue }; var nameList = discountsStringsTable .Where(i => i.OwnerId == discount.Id && i.Appointment == StrAppointmentTitle) .Join(langStringsTable, i => i.LangStringId, i => i.Id, (ds, ls) => ls); foreach (var nameRec in nameList) { discountData.SetName(nameRec.LanguageCode, nameRec.Text); } var descrList = discountsStringsTable .Where(i => i.OwnerId == discount.Id && i.Appointment == StrAppointmentDescription) .Join(langStringsTable, i => i.LangStringId, i => i.Id, (ds, ls) => ls); foreach (var descrRec in descrList) { discountData.SetDescription(descrRec.LanguageCode, descrRec.Text); } result.Add(discountData); } return(Task.FromResult(result)); }
public void LoadDiscounts( IEnumerable <Discount> discountsTable, IReadOnlyCollection <DiscountCategory> discountCategoriesTable, IReadOnlyCollection <DiscountsStrings> discountsStringsTable, IReadOnlyCollection <LangString> langStringsTable) { var discountCollection = new List <DiscountData>(); foreach (var discount in discountsTable) { var categories = discountCategoriesTable.Where(i => i.DiscountId == discount.Id) .Join(AppData.Discount.CategoryCollection, i => i.CategoryId, i => i.DocumentId, (dc, c) => c) .ToList(); var discountData = new DiscountData { DocumentId = discount.DocumentId, DiscountPercent = discount.PercentValue, DiscountType = discount.DiscountType.GetDiscountTypeName(), LogoFileName = discount.LogoFileName, CategoryList = categories }; var nameList = discountsStringsTable .Where(i => i.OwnerId == discount.Id && i.Appointment == StrAppointmentTitle) .Join(langStringsTable, i => i.LangStringId, i => i.Id, (ds, ls) => ls); foreach (var nameRec in nameList) { discountData.SetName(nameRec.LanguageCode, nameRec.Text); } var descrList = discountsStringsTable .Where(i => i.OwnerId == discount.Id && i.Appointment == StrAppointmentDescription) .Join(langStringsTable, i => i.LangStringId, i => i.Id, (ds, ls) => ls); foreach (var descrRec in descrList) { discountData.SetDescription(descrRec.LanguageCode, descrRec.Text); } discountCollection.Add(discountData); } AppData.Discount.DiscountCollection = discountCollection; }