Ejemplo n.º 1
0
        private static Task <List <MapPinData> > LoadMapData(
            IEnumerable <Discount> discountsTable,
            IEnumerable <Contact> contactsTable,
            IReadOnlyCollection <DiscountCategory> discountCategoriesTable,
            IReadOnlyCollection <DiscountsStrings> discountsStringsTable,
            IReadOnlyCollection <LangString> langStringsTable)
        {
            var result = new List <MapPinData>();

            var contactList = contactsTable.Join(discountsTable, i => i.DiscountId, i => i.Id,
                                                 (c, d) => new
            {
                d.Id,
                c.DocumentId,
                PartnerId = d.DocumentId,
                c.Latitude,
                c.Longitude,
                d.PercentValue,
                d.DiscountType
            });

            foreach (var contactRec in contactList)
            {
                var categories = discountCategoriesTable.Where(i => i.DiscountId == contactRec.Id)
                                 .Join(AppData.Discount.CategoryCollection, i => i.CategoryId, i => i.DocumentId, (dc, c) => c)
                                 .ToList();

                var mapPinData = new MapPinData
                {
                    Id              = contactRec.DocumentId,
                    PartnerId       = contactRec.PartnerId,
                    Discount        = contactRec.PercentValue,
                    DiscountType    = contactRec.DiscountType.GetDiscountTypeName(),
                    Latitude        = contactRec.Latitude,
                    Longitude       = contactRec.Longitude,
                    CategoryList    = categories,
                    PrimaryCategory = categories.FirstOrDefault()
                };

                var nameList = discountsStringsTable
                               .Where(i => i.OwnerId == contactRec.Id && i.Appointment == StrAppointmentTitle)
                               .Join(langStringsTable, i => i.LangStringId, i => i.Id, (ds, ls) => ls);

                foreach (var nameRec in nameList)
                {
                    mapPinData.SetName(nameRec.LanguageCode, nameRec.Text);
                }

                result.Add(mapPinData);
            }

            return(Task.FromResult(result));
        }
Ejemplo n.º 2
0
        public void LoadMapData()
        {
            AppData.Discount.MapPinCollection.Clear();

            var contactList = from co in database.Table <Contact>()
                              from d in database.Table <Discount>()
                              where co.DiscountId == d.Id
                              select new
            {
                d.Id,
                DocumentId = co.DocumentId,
                PartnerId  = d.DocumentId,
                co.Latitude,
                co.Longitude,
                d.PercentValue,
            };

            foreach (var contactRec in contactList)
            {
                MapPinData mapPinData = new MapPinData();
                mapPinData.Id        = contactRec.DocumentId;
                mapPinData.PartnerId = contactRec.PartnerId;
                mapPinData.Discount  = contactRec.PercentValue;
                mapPinData.Latitude  = contactRec.Latitude;
                mapPinData.Longitude = contactRec.Longitude;


                var categoryList = from c in database.Table <Categorie>()
                                   where c.DiscountId == contactRec.Id
                                   select c;
                foreach (var categoryrec in categoryList)
                {
                    mapPinData.CategorieList.Add(new CategorieData {
                        TypeCode = categoryrec.TypeCode
                    });
                }

                if (mapPinData.CategorieList.Count > 0)
                {
                    mapPinData.PrimaryCategory = mapPinData.CategorieList[0];
                }
                else
                {
                    mapPinData.PrimaryCategory = new CategorieData {
                        TypeCode = -1
                    }
                };

                var nameList = (from ds in database.Table <DiscountsStrings>()
                                from ls in database.Table <LangString>()
                                where ds.LangStringId == ls.Id
                                where ds.OwnerId == contactRec.Id
                                where ds.Appointment == StrAppointmentTitle
                                select new { ls.Text, ls.LanguageCode }).ToList();

                foreach (var nameRec in nameList)
                {
                    mapPinData.SetName(nameRec.LanguageCode, nameRec.Text);
                }

                AppData.Discount.MapPinCollection.Add(mapPinData);
            }
        }