Ejemplo n.º 1
0
        async public Task<bool> GetDiscounts()
        {
            bool isSuccess = false;
            
            try
            {
                AppData.Discount.DiscountCollection.Clear();

                var token = await Get(RequestDiscounts);
                var branchList = JsonConvert.DeserializeObject<List<Object>>(token);

                foreach (var item in branchList)
                {
                    var deserializeBranch = JsonConvert.DeserializeObject<DeserializeBranchItem>(item.ToString());
                    DiscountData discountData = new DiscountData(deserializeBranch);
                    //AppData.Discount.DiscountCollection.Add(discountData);

                    await AppData.Discount.DB.SaveDiscount(discountData);
                }

                isSuccess = true;
            }
            catch (Exception ex)
            {
                isSuccess = false;
            }

            return isSuccess;
        }
Ejemplo n.º 2
0
        public async Task SaveDiscount(DiscountData discount)
        {
            database.BeginTransaction();
            string logoFileName = discount.DocumentId + PostfixLogoFileName;
            
            await SaveImage(logoFileName, discount.Icon);

            Discount discountDBData = new Discount 
            { 
                UrlAddress = discount.UrlAddress, 
                IsFullDescription = false,
                DocumentId = discount.DocumentId,
                LogoFileName = logoFileName
            };
            discountDBData.PercentValue = discount.DiscountPercent;

            database.Insert(discountDBData);

            //name
            foreach (var name in discount.NameList)
            {
                LangString langStringRec = new LangString { LanguageCode = LanguageHelper.LangEnumToCode(name.Key).ToUpper(), Text = name.Value };
                database.Insert(langStringRec);

                DiscountsStrings discountsStringsRec = new DiscountsStrings {Appointment = StrAppointmentTitle, OwnerId = discountDBData.Id, LangStringId = langStringRec.Id };
                database.Insert(discountsStringsRec);
            }

            //description
            foreach (var name in discount.DescriptionList)
            {
                LangString langStringRec = new LangString { LanguageCode = LanguageHelper.LangEnumToCode(name.Key).ToUpper(), Text = name.Value };
                database.Insert(langStringRec);

                DiscountsStrings discountsStringsRec = new DiscountsStrings { Appointment = StrAppointmentDescription, OwnerId = discountDBData.Id, LangStringId = langStringRec.Id };
                database.Insert(discountsStringsRec);
            }

            //categories
            foreach (var categorie in discount.CategorieList)
            {
                Categorie categorieRec = new Categorie { DiscountId = discountDBData.Id, TypeCode = categorie.TypeCode };
                database.Insert(categorieRec);
            }

            database.Commit();
        }
Ejemplo n.º 3
0
            async public Task<bool> LoadFullDescription(DiscountData discountData)
            {
                bool isSuccess = false;
                
                try
                {
                    if (discountData.IsFullDescription)
                        isSuccess = true;
                    else
                        if ((isConnected) && (discountData != null))
                            isSuccess = await ServiceProvider.GetPartnerDetail(discountData);
                }
                catch (Exception)
                {
                    //TODO: Handling exception

                    isSuccess = false;
                }

                return isSuccess;
            }
Ejemplo n.º 4
0
        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);
            }
        }
        async private void OpenPage(DiscountData discountData)
        {
            try
            {
                IsOpenning = true;

                if (Device.OS != TargetPlatform.Android)
                    (ViewPage as DiscountPage).DiscountListView.HideAnimation();

                try
                {
                    IsLoadActivity = true;
                    await AppData.Discount.LoadFullDescription(discountData);
                }
                finally
                {
                    IsLoadActivity = false;
                }

                await ViewPage.Navigation.PushAsync(new DiscountDetailPage(discountData.DocumentId), true);
            }
            finally
            {
                IsOpenning = false;
            }
        }
Ejemplo n.º 6
0
        async public Task<bool> GetPartnerDetail(DiscountData discountData)
        {
            bool isSuccess = false;

            try
            {
                var token = await Get(String.Format(RequestPartnerDetail, discountData.DocumentId));
                var branchList = JsonConvert.DeserializeObject<List<Object>>(token);

                foreach (var item in branchList)
                {
                    var deserializeBranch = JsonConvert.DeserializeObject<DeserializeBranchItem>(item.ToString());
                    await AppData.Discount.DB.UpdateDiscount(deserializeBranch);
                }

                isSuccess = true;
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return isSuccess;
        }