Ejemplo n.º 1
0
        public void UpdateURLForProduct(Product product)
        {
            string           slug           = UrlUtil.ModifyUrl(product.Name);
            List <UrlRecord> urlRecordsList = _thyMenaUrlRecordRepository.FindUrlRecordsByEntityIdEntityName(product.Id, "Product");

            if (urlRecordsList == null || urlRecordsList.Count == 0)
            {
                string           tmpSlug    = "";
                List <UrlRecord> urlRecords = _thyMenaUrlRecordRepository.FindSameUrlRecordsForDifferentProducts(
                    slug, "Product", product.Id);
                if (urlRecords != null && urlRecords.Count > 0)
                {
                    for (int i = 2; i < 6; i++)
                    {
                        tmpSlug    = slug + i.ToString();
                        urlRecords = _thyMenaUrlRecordRepository.FindSameUrlRecordsForDifferentProducts(
                            tmpSlug, "Product", product.Id);
                        if (urlRecords != null && urlRecords.Count > 0)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                UrlRecord urlRecord = _thyMenaUrlRecordRepository.FindUrlRecordBySlugEntityName(tmpSlug, "Product");
                if (urlRecord == null)
                {
                    _thyMenaUrlRecordRepository.Add(new UrlRecord()
                    {
                        EntityId   = product.Id,
                        EntityName = "Product",
                        Slug       = tmpSlug,
                        IsActive   = true,
                        LanguageId = 0
                    });
                    _thyMenaUrlRecordRepository.Save();
                }
                else
                {
                    urlRecord.EntityId = product.Id;
                    _thyMenaUrlRecordRepository.Update(urlRecord);
                    _thyMenaUrlRecordRepository.Save();
                }
            }
            else
            {
                UrlRecord urlRecord = urlRecordsList[0];
                urlRecord.Slug       = slug;
                urlRecord.IsActive   = true;
                urlRecord.LanguageId = 0;
                _thyMenaUrlRecordRepository.Update(urlRecord);
                _thyMenaUrlRecordRepository.Save();
            }
        }
Ejemplo n.º 2
0
        public void InsertOrUpdateProductManufacturerMapping(Product product, string marka)
        {
            Manufacturer manufacturer = _thyMenaManufacturerRepository.FindManufacturerByName(marka);

            if (manufacturer != null)
            {
                ProductManufacturerMapping productManufacturerMapping =
                    _thyMenaProductManufacturerMappingRepository.FindByProductId(product.Id);
                if (productManufacturerMapping == null)
                {
                    _thyMenaProductManufacturerMappingRepository.Add(new ProductManufacturerMapping()
                    {
                        ProductId         = product.Id,
                        ManufacturerId    = manufacturer.Id,
                        IsFeaturedProduct = false,
                        DisplayOrder      = 0
                    });
                    _thyMenaManufacturerRepository.Save();
                }
            }
            else
            {
                manufacturer = _thyMenaManufacturerRepository.Add(new Manufacturer()
                {
                    Name                           = marka,
                    Description                    = marka,
                    ManufacturerTemplateId         = 1,
                    MetaKeywords                   = null,
                    MetaDescription                = null,
                    MetaTitle                      = null,
                    PictureId                      = 0,
                    PageSize                       = 12,
                    AllowCustomersToSelectPageSize = false,
                    PageSizeOptions                = "4, 2, 8, 12",
                    PriceRanges                    = null,
                    Published                      = true,
                    Deleted                        = false,
                    DisplayOrder                   = 0,
                    CreatedOnUtc                   = DateTime.Now,
                    UpdatedOnUtc                   = DateTime.Now,
                    SubjectToAcl                   = false,
                    LimitedToStores                = false
                });
                _thyMenaManufacturerRepository.Save();
                _thyMenaProductManufacturerMappingRepository.Add(new ProductManufacturerMapping()
                {
                    ProductId         = product.Id,
                    ManufacturerId    = manufacturer.Id,
                    IsFeaturedProduct = false,
                    DisplayOrder      = 0
                });
                _thyMenaProductManufacturerMappingRepository.Save();
            }
            UrlRecord urlRecord = _thyMenaUrlRecordRepository.FindUrlRecordByEntityIdEntityName(manufacturer.Id, "Manufacturer");

            if (urlRecord == null)
            {
                _thyMenaUrlRecordRepository.Add(new UrlRecord()
                {
                    EntityId   = manufacturer.Id,
                    EntityName = "Manufacturer",
                    Slug       = UrlUtil.ModifyUrl(marka),
                    IsActive   = true,
                    LanguageId = 0,
                });
                _thyMenaUrlRecordRepository.Save();
            }
            else
            {
                urlRecord.Slug       = UrlUtil.ModifyUrl(marka);
                urlRecord.IsActive   = true;
                urlRecord.LanguageId = 0;
                _thyMenaUrlRecordRepository.Update(urlRecord);
                _thyMenaUrlRecordRepository.Save();
            }
        }