public IHttpActionResult Post(webModel.Category category) { var coreCategory = category.ToModuleModel(); if (coreCategory.Id == null) { if (coreCategory.SeoInfos == null || !coreCategory.SeoInfos.Any()) { var slugUrl = category.Name.GenerateSlug(); if (!String.IsNullOrEmpty(slugUrl)) { var catalog = _catalogService.GetById(category.CatalogId); var defaultLanguage = catalog.Languages.First(x => x.IsDefault).LanguageCode; coreCategory.SeoInfos = new SeoInfo[] { new SeoInfo { LanguageCode = defaultLanguage, SemanticUrl = slugUrl } }; } } var retVal = _categoryService.Create(coreCategory).ToWebModel(); retVal.Catalog = null; return Ok(retVal); } else { _categoryService.Update(new[] { coreCategory }); return StatusCode(HttpStatusCode.NoContent); } }
public IHttpActionResult CreateLinks(webModel.ListEntryLink[] links) { //Scope bound security check base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, links); InnerUpdateLinks(links, (x, y) => x.Links.Add(y)); return StatusCode(HttpStatusCode.NoContent); }
private void InnerUpdateLinks(webModel.ListEntryLink[] links, Action<coreModel.ILinkSupport, coreModel.CategoryLink> action) { var changedObjects = new List<coreModel.ILinkSupport>(); foreach (var link in links) { coreModel.ILinkSupport changedObject; var newlink = new coreModel.CategoryLink { CategoryId = link.CategoryId, CatalogId = link.CatalogId }; if (String.Equals(link.ListEntryType, webModel.ListEntryCategory.TypeName, StringComparison.InvariantCultureIgnoreCase)) { changedObject = _categoryService.GetById(link.ListEntryId, coreModel.CategoryResponseGroup.Full); } else { changedObject = _itemService.GetById(link.ListEntryId, coreModel.ItemResponseGroup.ItemLarge); } action(changedObject, newlink); changedObjects.Add(changedObject); } _categoryService.Update(changedObjects.OfType<coreModel.Category>().ToArray()); _itemService.Update(changedObjects.OfType<coreModel.CatalogProduct>().ToArray()); }
public IHttpActionResult Move(webModel.MoveInfo moveInfo) { var categories = new List<coreModel.Category>(); //Move categories foreach (var listEntryCategory in moveInfo.ListEntries.Where(x => String.Equals(x.Type, webModel.ListEntryCategory.TypeName, StringComparison.InvariantCultureIgnoreCase))) { var category = _categoryService.GetById(listEntryCategory.Id, coreModel.CategoryResponseGroup.Info); if (category.CatalogId != moveInfo.Catalog) { category.CatalogId = moveInfo.Catalog ?? String.Empty; } if (category.ParentId != moveInfo.Category) { category.ParentId = moveInfo.Category ?? String.Empty; } categories.Add(category); } var products = new List<coreModel.CatalogProduct>(); //Move products foreach (var listEntryProduct in moveInfo.ListEntries.Where(x => String.Equals(x.Type, webModel.ListEntryProduct.TypeName, StringComparison.InvariantCultureIgnoreCase))) { var product = _itemService.GetById(listEntryProduct.Id, Domain.Catalog.Model.ItemResponseGroup.ItemLarge); if (product.CatalogId != moveInfo.Catalog) { product.CatalogId = moveInfo.Catalog ?? String.Empty; product.CategoryId = null; foreach (var variation in product.Variations) { variation.CatalogId = moveInfo.Catalog ?? String.Empty; variation.CategoryId = null; } } if (product.CategoryId != moveInfo.Category) { product.CategoryId = moveInfo.Category ?? String.Empty; foreach (var variation in product.Variations) { variation.CategoryId = moveInfo.Category ?? String.Empty; } } products.Add(product); products.AddRange(product.Variations); } //Scope bound security check CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, categories); CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, products); if (categories.Any()) { _categoryService.Update(categories.ToArray()); } if (products.Any()) { _itemService.Update(products.ToArray()); } return Ok(); }
private string GenerateProductDefaultSlugUrl(webModel.Product product) { var retVal = new List<string>(); retVal.Add(product.Name); if (product.Properties != null) { foreach (var property in product.Properties.Where(x => x.Type == coreModel.PropertyType.Variation && x.Values != null)) { retVal.AddRange(property.Values.Select(x => x.PropertyName + "-" + x.Value)); } } return String.Join(" ", retVal).GenerateSlug(); }
private coreModel.CatalogProduct UpdateProduct(webModel.Product product) { var moduleProduct = product.ToModuleModel(_blobUrlResolver); if (moduleProduct.Id == null) { if (moduleProduct.SeoInfos == null || !moduleProduct.SeoInfos.Any()) { var slugUrl = GenerateProductDefaultSlugUrl(product); if (!string.IsNullOrEmpty(slugUrl)) { var catalog = _catalogService.GetById(product.CatalogId); var defaultLanguageCode = catalog.Languages.First(x => x.IsDefault).LanguageCode; var seoInfo = new SeoInfo { LanguageCode = defaultLanguageCode, SemanticUrl = slugUrl }; moduleProduct.SeoInfos = new SeoInfo[] { seoInfo }; } } base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, moduleProduct); return _itemsService.Create(moduleProduct); } else { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, moduleProduct); _itemsService.Update(new[] { moduleProduct }); } return null; }
public IHttpActionResult Update(webModel.Product product) { var updatedProduct = UpdateProduct(product); if (updatedProduct != null) { return Ok(updatedProduct); } return StatusCode(HttpStatusCode.NoContent); }
private void UpdateCatalog(webModel.Catalog catalog) { var moduleCatalog = catalog.ToModuleModel(); CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, catalog); _catalogService.Update(new[] { moduleCatalog }); }
public IHttpActionResult Post(webModel.Property property) { var moduleProperty = property.ToModuleModel(); if (property.IsNew) { _propertyService.Create(moduleProperty); } else { _propertyService.Update(new moduleModel.Property[] { moduleProperty }); } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult Create(webModel.Catalog catalog) { var newCatalog = _catalogService.Create(catalog.ToModuleModel()); var retVal = newCatalog.ToWebModel(); //Need for UI permission checks retVal.SecurityScopes = GetObjectPermissionScopeStrings(newCatalog); return Ok(retVal); }
public IHttpActionResult Update(webModel.Catalog catalog) { UpdateCatalog(catalog); return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult CreateOrUpdateCategory(webModel.Category category) { var coreCategory = category.ToModuleModel(); if (coreCategory.Id == null) { if (coreCategory.SeoInfos == null || !coreCategory.SeoInfos.Any()) { var slugUrl = category.Name.GenerateSlug(); if (!String.IsNullOrEmpty(slugUrl)) { var catalog = _catalogService.GetById(category.CatalogId); var defaultLanguage = catalog.Languages.First(x => x.IsDefault).LanguageCode; coreCategory.SeoInfos = new SeoInfo[] { new SeoInfo { LanguageCode = defaultLanguage, SemanticUrl = slugUrl } }; } } base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, coreCategory); var retVal = _categoryService.Create(coreCategory).ToWebModel(_blobUrlResolver); retVal.Catalog = null; return Ok(retVal); } else { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, coreCategory); _categoryService.Update(new[] { coreCategory }); return StatusCode(HttpStatusCode.NoContent); } }
private void UpdateCatalog(webModel.Catalog catalog) { var moduleCatalog = catalog.ToModuleModel(); _catalogService.Update(new moduleModel.Catalog[] { moduleCatalog }); }
public IHttpActionResult Create(webModel.Catalog catalog) { if ((_permissionService.UserHasAnyPermission(RequestContext.Principal.Identity.Name, PredefinedPermissions.CatalogsManage) && !catalog.Virtual) || (_permissionService.UserHasAnyPermission(RequestContext.Principal.Identity.Name, PredefinedPermissions.VirtualCatalogsManage) && catalog.Virtual)) { var retVal = _catalogService.Create(catalog.ToModuleModel()); return Ok(retVal.ToWebModel()); } else { throw new UnauthorizedAccessException(); } }
public IHttpActionResult CreateLinks(webModel.ListEntryLink[] links) { InnerUpdateLinks(links, (x, y) => x.Links.Add(y)); return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult CreateOrUpdateProperty(webModel.Property property) { var moduleProperty = property.ToModuleModel(); if (property.IsNew) { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, moduleProperty); _propertyService.Create(moduleProperty); } else { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, moduleProperty); _propertyService.Update(new moduleModel.Property[] { moduleProperty }); } return StatusCode(HttpStatusCode.NoContent); }