示例#1
0
        public IList <Product> ApplyOfferToProducts(ProductType productName)
        {
            IOfferStratergy offerStratergy = OfferFactory.GetOfferStratergyFor(productName);
            IList <Product> products       = _productRepository.FindAllByType(productName);

            products.ApplyPromoOffers(offerStratergy);
            return(products);
        }
        internal static Policy AlreadyTerminatedPolicy()
        {
            var offer = OfferFactory.NewOfferValidUntil(DateTime.Now.AddDays(5));

            var policy = offer.Buy(PolicyHolderFactory.Abc());

            var terminationResult = policy.Terminate(DateTime.Now.AddDays(3));

            return(policy);
        }
示例#3
0
        static void Main(string[] args)
        {
            Console.Write("CREATE USER");
            SMServiceConfig.Instance.Refresh();
            User     testUser;
            DateTime value = new DateTime(1990, 1, 1);

            Task.Run(async() =>
            {
                // Create A User
                testUser = await UserFactory.createUser(generateID(), RandomString(6) + "@example.com", UserFactory.UserGender.f, value.ToString("yyyy-MM-dd"), "127.0.0.1");
                // Fetch User
                testUser = await UserFactory.getUserByExternalId(testUser.external_id);
                // When the User does Something Send an Event to SessionM Server
                Console.WriteLine("SEND BUY EVENT/EVENTS");
                var events = new ActivityEvents <String, int>();
                events.Add("buy_something", 1);
                bool added = await EventFactory.sendEventByExternalId(testUser.external_id, events);
                // Fetch User And Get Updated Points
                testUser = await UserFactory.getUserByExternalId(testUser.external_id);
                Console.WriteLine("USER POINTS : " + testUser.available_points);
                // Create an Order For the Rewards Offers
                Console.WriteLine("FETCH ALL OFFERS");
                List <Offer> allOffers = new List <Offer>(await OfferFactory.getAllOffers());
                Console.WriteLine("CREATE A NEW ORDER");
                Order myOrder1 = await OrderFactory.createOrderByExternalId(allOffers.First().id.ToString(), "127.0.0.1", testUser.external_id);
                // Fetch User And Get Updated Points
                testUser = await UserFactory.getUserByExternalId(testUser.external_id);
                Console.WriteLine("USER POINTS : " + testUser.available_points);
                // Send code via SMS
                testUser.phoneNumber      = "111-111-1111";
                testUser.message          = "{{code}}";
                Verification verification = await UserFactory.validateViaSMS(testUser);
                Console.WriteLine("SMS Verfication Response: " + verification);
                // Validate an image
                string imageBase64String          = GenerateBase64String(@"path/to/image.jpg");
                List <ImageValidationItem> images = new List <ImageValidationItem>();
                images.Add(new ImageValidationItem(imageBase64String, "image/jpg"));
                ImageValidation imageValidation       = new ImageValidation();
                imageValidation.validationType        = models.enums.ImageValidationTypeEnum.receipt.ToString();
                imageValidation.campaignId            = 385;
                imageValidation.placementId           = 53421;
                imageValidation.images                = images;
                ImageValidation imageValidationResult = await ImageValidationFactory.validateImage(testUser, imageValidation);
                Console.WriteLine("Image URL: " + imageValidationResult.images.First().Url);
                // Get a Skills Test Question
                Challenge challenge = await ChallengeFactory.getChallengeQuestion(testUser);
                Console.WriteLine("Skills Test Question: " + challenge.skillsTestQuestion.question);
            }).Wait();
        }
        private static List <Shop> ParseShops(IEnumerable <XElement> xml)
        {
            List <Shop> listOfShops = new List <Shop>();

            foreach (var shopXml in xml)
            {
                string shopName = shopXml.Element("name").Value;

                string shopCompany = shopXml.Element("company").Value;

                string shopUrl = shopXml.Element("url").Value;

                var Currencies = shopXml.Element("currencies").Elements();

                List <Currency> curList = new List <Currency>();
                foreach (var currency in Currencies)
                {
                    curList.Add(
                        new Currency(currency.Attribute("id").Value, Convert.ToDouble(currency.Attribute("rate").Value),
                                     Convert.ToDouble(currency.Attribute("plus").Value)));
                }

                var Categories = shopXml.Element("categories").Elements();

                List <Category> catList = new List <Category>();
                foreach (var category in Categories)
                {
                    catList.Add(new Category(Convert.ToInt32(category.Attribute("id").Value),
                                             (category.Attributes().SingleOrDefault(atr => atr.Name == "parentId") != null) ? Convert.ToInt32(category.Attribute("parentId").Value) : 0,
                                             category.Value));
                }

                double shopLocalDeliveryCost = Convert.ToDouble(shopXml.Element("local_delivery_cost").Value);

                var Offers = shopXml.Element("offers").Elements();

                List <Offer> offList = new List <Offer>();
                foreach (var offer in Offers)
                {
                    int categoryId = Convert.ToInt32(offer.Element("categoryId").Value);
                    mFactory = setFactoryByCategoryId(categoryId, catList);
                    Offer newOffer = mFactory.Create(offer);
                    offList.Add(newOffer);
                }

                listOfShops.Add(new Shop(shopName, shopCompany, shopUrl, curList, catList, shopLocalDeliveryCost, offList));                 // Полученный объект
            }
            return(listOfShops);
        }
        public OfferId Create(DateTime from, DateTime to, string apartmentIdString, decimal priceDecimal, string ownerIdString, decimal depositDecimal)
        {
            var apartmentId = ApartmentId.From(apartmentIdString);
            var apartment   = _apartmentRepository.Get(apartmentId);
            var period      = Period.From(from, to);
            var pricePerDay = Price.From(priceDecimal);
            var ownerId     = OwnerId.From(ownerIdString);
            var deposit     = Price.From(depositDecimal);

            var offer = OfferFactory.Create(apartment, ownerId, period, pricePerDay, deposit);

            _offerRepository.Save(offer);

            return(offer.Id);
        }
        public static List <Offer> ParseOffers(this XDocument doc)
        {
            var xml = doc;

            var shops = from xElement in xml.Root.Descendants("shop")
                        select xElement;

            List <Offer> offList = new List <Offer>();

            foreach (var shopXml in shops)
            {
                var Categories = shopXml.Element("categories").Elements();

                List <Category> catList = new List <Category>();

                foreach (var category in Categories)
                {
                    catList.Add(new Category(Convert.ToInt32(category.Attribute("id").Value),
                                             (category.Attributes().SingleOrDefault(atr => atr.Name == "parentId") != null) ? Convert.ToInt32(category.Attribute("parentId").Value) : 0,
                                             category.Value));
                }

                var Offers = shopXml.Element("offers").Elements();


                foreach (var offer in Offers)
                {
                    int categoryId = Convert.ToInt32(offer.Element("categoryId").Value);
                    mFactory = setFactoryByCategoryId(categoryId, catList);
                    Offer newOffer = mFactory.Create(offer);
                    offList.Add(newOffer);
                }
            }

            return(offList);
        }
示例#7
0
 public OfferService()
 {
     this._repo    = new OfferRepository(new ApplicationDbContext());
     this._factory = new OfferFactory();
 }