예제 #1
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();
        }
예제 #2
0
        public async Task UpdateDiscount(DeserializeBranchItem branchItem)
        {
            NumberFormatInfo format = new NumberFormatInfo();
            format.NumberGroupSeparator = ",";
            format.NumberDecimalSeparator = ".";

            Discount discountDBData = database.Table<Discount>().FirstOrDefault(x => x.DocumentId == branchItem.PartnerId);
            if (discountDBData == null)
                return;

            database.BeginTransaction();

            if (!String.IsNullOrWhiteSpace(branchItem.Image))
            {
                string imgFileName = discountDBData.DocumentId + PostfixImgFileName;
                await SaveImage(imgFileName, branchItem.Image);
                discountDBData.ImageFileName = imgFileName;
                discountDBData.IsFullDescription = true;
                database.Update(discountDBData);

                var discount = AppData.Discount.DiscountCollection.FirstOrDefault<DiscountData>(x => x.DocumentId == discountDBData.DocumentId);
                if (discount != null)
                    discount.IsFullDescription = true;
            }

            Contact contactDBData = database.Table<Contact>().FirstOrDefault(x => x.DiscountId == discountDBData.Id && x.DocumentId == branchItem.Id);

            if (contactDBData == null)
            {
                contactDBData = new Contact();
                database.Insert(contactDBData);
            }

            contactDBData.DiscountId = discountDBData.Id;
            contactDBData.DocumentId = branchItem.Id;
            contactDBData.Latitude = Double.Parse(branchItem.Location.Coordinates.Latitude, format);
            contactDBData.Longitude = Double.Parse(branchItem.Location.Coordinates.Longitude, format);

            if (branchItem.Address != null)
                foreach (var address in branchItem.Address)
                {
                    LangString langStringRec = new LangString { LanguageCode = address.Lan.ToUpper(), Text = address.LocText };
                    database.Insert(langStringRec);

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

            if (branchItem.Phones != null)
            {
                if (branchItem.Phones.Count > 0)
                    contactDBData.Phone1 = branchItem.Phones[0].Number;

                if (branchItem.Phones.Count > 1)
                    contactDBData.Phone2 = branchItem.Phones[1].Number;
            }

            database.Update(contactDBData);

            database.Commit();
        }