コード例 #1
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();
            }
        }