public coreModel.Category Create(coreModel.Category category) { if (category == null) throw new ArgumentNullException("category"); var dbCategory = category.ToDataModel(); using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCategory); CommitChanges(repository); } //Need add seo separately if (category.SeoInfos != null) { foreach (var seoInfo in category.SeoInfos) { seoInfo.ObjectId = dbCategory.Id; seoInfo.ObjectType = typeof(coreModel.Category).Name; _commerceService.UpsertSeo(seoInfo); } } category.Id = dbCategory.Id; return GetById(dbCategory.Id); }
public coreModel.Property Create(coreModel.Property property) { if (property.CatalogId == null) { throw new NullReferenceException("property.CatalogId"); } var dbProperty = property.ToDataModel(); using (var repository = _catalogRepositoryFactory()) { if (property.CategoryId != null) { var dbCategory = repository.GetCategoriesByIds(new[] { property.CategoryId }, coreModel.CategoryResponseGroup.Info).FirstOrDefault(); if (dbCategory == null) { throw new NullReferenceException("dbCategory"); } dbCategory.Properties.Add(dbProperty); } else { var dbCatalog = repository.GetCatalogById(property.CatalogId); if (dbCatalog == null) { throw new NullReferenceException("dbCatalog"); } dbCatalog.Properties.Add(dbProperty); } repository.Add(dbProperty); CommitChanges(repository); } var retVal = GetById(dbProperty.Id); return retVal; }
public coreModel.Catalog Create(coreModel.Catalog catalog) { var dbCatalog = catalog.ToDataModel(); coreModel.Catalog retVal = null; using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCatalog); CommitChanges(repository); } retVal = GetById(dbCatalog.Id); return retVal; }
public coreModel.Catalog Create(coreModel.Catalog catalog) { var pkMap = new PrimaryKeyResolvingMap(); var dbCatalog = catalog.ToDataModel(pkMap); coreModel.Catalog retVal = null; using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCatalog); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } retVal = GetById(dbCatalog.Id); return retVal; }
public coreModel.Category Create(coreModel.Category category) { if (category == null) throw new ArgumentNullException("category"); var pkMap = new PrimaryKeyResolvingMap(); var dbCategory = category.ToDataModel(pkMap); using (var repository = _catalogRepositoryFactory()) { repository.Add(dbCategory); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); } //Need add seo separately _commerceService.UpsertSeoForObjects(new[] { category }); return GetById(dbCategory.Id, Domain.Catalog.Model.CategoryResponseGroup.Info); }
public coreModel.CatalogProduct Create(coreModel.CatalogProduct item) { var dbItem = item.ToDataModel(); using (var repository = _catalogRepositoryFactory()) { repository.Add(dbItem); item.Id = dbItem.Id; if (item.Variations != null) { foreach (var variation in item.Variations) { variation.MainProductId = dbItem.Id; variation.CatalogId = dbItem.CatalogId; var dbVariation = variation.ToDataModel(); repository.Add(dbVariation); variation.Id = dbVariation.Id; } } CommitChanges(repository); } //Need add seo separately if (item.SeoInfos != null) { foreach (var seoInfo in item.SeoInfos) { seoInfo.ObjectId = dbItem.Id; seoInfo.ObjectType = typeof(coreModel.CatalogProduct).Name; _commerceService.UpsertSeo(seoInfo); } } if (item.Variations != null) { foreach (var variation in item.Variations) { if (variation.SeoInfos != null) { foreach (var seoInfo in variation.SeoInfos) { seoInfo.ObjectId = variation.Id; seoInfo.ObjectType = typeof(coreModel.CatalogProduct).Name; _commerceService.UpsertSeo(seoInfo); } } } } var retVal = GetById(dbItem.Id, coreModel.ItemResponseGroup.ItemLarge); return retVal; }
public coreModel.Property Create(coreModel.Property property) { if (property.CatalogId == null) { throw new NullReferenceException("property.CatalogId"); } var dbProperty = property.ToDataModel(); using (var repository = _catalogRepositoryFactory()) { if (property.CategoryId != null) { var dbCategory = repository.GetCategoryById(property.CategoryId); repository.SetCategoryProperty(dbCategory, dbProperty); } else { var dbCatalog = repository.GetCatalogById(property.CatalogId) as dataModel.Catalog; if(dbCatalog == null) { throw new OperationCanceledException("Add property only to catalog"); } repository.SetCatalogProperty(dbCatalog, dbProperty); } repository.Add(dbProperty); CommitChanges(repository); } var retVal = GetById(dbProperty.Id); return retVal; }