private void SaveManufacturerMappings(ProductCreateOrUpdateModel model) { var manufacturerMappings = new List <ProductManufacturerMapping>(); if (model.ManufacturerIds != null) { foreach (var id in model.ManufacturerIds) { // check if manufacture exist Guid manufactureId; if (Guid.TryParse(id, out manufactureId)) { if (_manufacturerService.GetManufacturerById(manufactureId) != null) { // create mapping entity var manufacturerMapping = new ProductManufacturerMapping { Id = Guid.NewGuid(), ProductId = model.Id, ManufacturerId = Guid.Parse(id) }; manufacturerMappings.Add(manufacturerMapping); } } } } // save to database _manufacturerService.DeleteAllProductManufacturersMappings(model.Id); _manufacturerService.InsertProductManufacturerMappings(manufacturerMappings); }
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(); } }
public void AddProductManufacturerMapping(ProductManufacturerMapping productManufacturerMapping) { _thyMenaProductManufacturerMappingRepository.Add(productManufacturerMapping); _thyMenaProductManufacturerMappingRepository.Save(); }