Example #1
0
        public static IcbcodeContent Get(long content_id)
        {
            IcbcodeContent item = null;

            using (ContentRepository content_repository = new ContentRepository())
            {
                item = IcbcodeContent.Convert(content_repository.GetActiveByID(content_id), 1, 1);
            }

            return(item);
        }
Example #2
0
        public static IcbcodeContent Get(string content_url, string domain)
        {
            IcbcodeContent item = null;

            using (ContentRepository content_repository = new ContentRepository())
            {
                item = IcbcodeContent.Convert(content_repository.GetActiveByUrl(content_url.TrimEnd('/'), domain ?? _Domain), 1, 1);
            }

            return(item);
        }
Example #3
0
        private static IcbcodeCollection <IcbcodeContent> Get(long[] content_root, string[] block_name, string[] template_name, string order_fields, long page, long size, string query, dynamic where, string domain)
        {
            IcbcodeCollection <IcbcodeContent> items = new IcbcodeCollection <IcbcodeContent>(); long totals;

            using (ContentRepository content_repository = new ContentRepository())
            {
                List <dynamic> contents = content_repository.GetActive(block_name, content_root, template_name, order_fields, page, size, out totals, query, where, domain);

                items.TotalPages  = totals;
                items.CurrentPage = page;
                items.PageSize    = size;

                for (int index = 0; index < contents.Count; index++)
                {
                    items.Add(IcbcodeContent.Convert(contents[index], index + 1, contents.Count));
                }
            }

            return(items);
        }
Example #4
0
        public IcbcodeCollection <IcbcodeContent> Childs(string[] template_name = null, string order_fields = null, long page = 1, long size = Int64.MaxValue, string query = null, dynamic where = null, string domain = null)
        {
            IcbcodeCollection <IcbcodeContent> items = new IcbcodeCollection <IcbcodeContent>(); long totals;

            using (ContentRepository content_repository = new ContentRepository())
            {
                List <dynamic> contents = content_repository.GetActive(null, new long[] { ID }, template_name, order_fields, page, size, out totals, query, where, domain);

                items.TotalPages  = totals;
                items.CurrentPage = page;
                items.PageSize    = size;

                for (int index = 0; index < contents.Count; index++)
                {
                    items.Add(IcbcodeContent.Convert(contents[index], index + 1, contents.Count));
                }
            }

            return(items);
        }
Example #5
0
        public static string Do()
        {
            var catalog = GetCatalog("http://mikkimama.ru/marketplace/44666.xml");

            var partitions = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "razdel-kataloga" });

            var products = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "poziciya" });

            var oldProducts = IcbcodeContent.Get(new string[] { "katalog" }, new string[] { "poziciya" });

            List <string> newPartitions = new List <string>(); List <string> newProducts = new List <string>(); List <string> noNames = new List <string>();

            using (WebClient web = new WebClient())
            {
                using (ContentRepository content = new ContentRepository())
                    using (ImageRepository image = new ImageRepository())
                    {
                        foreach (var offer in catalog.Shop.Offers.Offer)
                        {
                            var partition = partitions.Find(x => x.UserDefined.vneshnij_id != null && x.UserDefined.vneshnij_id.ToString() == offer.CategoryId);

                            if (partition == null)
                            {
                                newPartitions.Add(offer.CategoryId);
                            }
                            else
                            {
                                oldProducts.RemoveAll(x => (long)x.UserDefined.vneshnij_id == Convert.ToInt64(offer.Id));

                                var product = products.Find(x => x.UserDefined.vneshnij_id != null && (long)x.UserDefined.vneshnij_id == Convert.ToInt64(offer.Id));

                                if (product == null)
                                {
                                    var product_id = content.CreateGlobalID();

                                    if (string.IsNullOrWhiteSpace(offer.Name))
                                    {
                                        offer.Name = offer.Url;

                                        noNames.Add($"{partition.Url}/{product_id}");
                                    }

                                    content.Create(product_id, 16512, offer.Name, 16515, $"{partition.Url}/{product_id}", 33436, partition.ID, $"proizvoditelj = 33457, edinica_izmereniya = 33456, cena_rub = {offer.Price}, artikul = '{offer.VendorCode}', vneshnij_id = {offer.Id}", 15984);

                                    newProducts.Add($"{partition.Url}/{product_id}");

                                    foreach (var pic in offer.Picture)
                                    {
                                        var image_id = image.CreateGlobalID();

                                        string extension = Path.GetExtension(pic);

                                        string savePath = Path.Combine(HostingEnvironment.MapPath("~/content/cms/files"), image_id.ToString() + extension);

                                        web.DownloadFile(pic, savePath);

                                        image.Save(image_id, extension, product_id.ToString(), null, "", 100000, product_id);
                                    }
                                }
                                else
                                {
                                    // обновляем только цену, удаляем и загружаем заново картинки
                                    content.Update($"cena_rub = {offer.Price}, content_active = true", $"content_id = {product.ID}");

                                    image.RemoveByRef(product.ID);

                                    foreach (var pic in offer.Picture)
                                    {
                                        var image_id = image.CreateGlobalID();

                                        string extension = Path.GetExtension(pic);

                                        string savePath = Path.Combine(HostingEnvironment.MapPath("~/content/cms/files"), image_id.ToString() + extension);

                                        web.DownloadFile(pic, savePath);

                                        image.Save(image_id, extension, product.ID.ToString(), null, "", 100000, product.ID);
                                    }
                                }
                            }
                        }

                        foreach (var oldProduct in oldProducts)
                        {
                            content.Update($"artikul = '', content_active = false", $"vneshnij_id = '{oldProduct.UserDefined.vneshnij_id}' and content_template = 16515");
                        }
                    }
            }

            StringBuilder result = new StringBuilder();

            if (newPartitions.Count > 0)
            {
                result.Append("Новые разделы: <br/>");
                foreach (string item in newPartitions)
                {
                    result.Append($"{item}<br/>");
                }
                result.Append("<br/><br/><br/>");
            }

            if (newProducts.Count > 0)
            {
                result.Append("Новые товары: <br/>");
                foreach (string item in newProducts)
                {
                    result.Append($"{item}<br/>");
                }
                result.Append("<br/><br/><br/>");
            }

            if (noNames.Count > 0)
            {
                result.Append("Товары без имени: <br/>");
                foreach (string item in noNames)
                {
                    result.Append($"{item}<br/>");
                }
                result.Append("<br/><br/><br/>");
            }

            if (oldProducts.Count > 0)
            {
                result.Append("Удаленные товары: <br/>");
                foreach (var item in oldProducts)
                {
                    result.Append($"{item.Url}<br/>");
                }
                result.Append("<br/><br/><br/>");
            }

            return(result.ToString());
        }
Example #6
0
 public bool ExistsInParents(IcbcodeContent item)
 {
     return(Parents.Exists(x => x.Url == item.Url));
 }