Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }