private bool Save(Category current, Category posted, System.Collections.Specialized.NameValueCollection form) { bool result = false; if (current != null) { current.Name = posted.Name.Trim(); /* Areas */ string mainArea = string.Empty; if (form["area-main"] != null) { mainArea = form["area-main"]; } current.Description = mainArea; current.PreTransformDescription = mainArea; current.GetCurrentVersion().Areas.SetAreaContent("main", mainArea); /* Other Settings */ current.MetaDescription = form["metadescription"] ?? current.MetaDescription; current.MetaTitle = form["metatitle"] ?? current.MetaTitle; current.MetaKeywords = form["metakeywords"] ?? current.MetaKeywords; current.ShowInTopMenu = false; // This could be changed to support show in top menu functionality current.SourceType = CategorySourceType.CustomPage; // hidden checkbox string isChecked = form["hidden"] ?? string.Empty; current.Hidden = (isChecked == "true"); string oldUrl = current.RewriteUrl; // no entry, generate one if (current.RewriteUrl.Trim().Length < 1) { current.RewriteUrl = MerchantTribe.Web.Text.Slugify(current.Name, true, true); } else { current.RewriteUrl = MerchantTribe.Web.Text.Slugify(form["rewriteurl"] ?? current.RewriteUrl, true, true); } if (UrlRewriter.IsCategorySlugInUse(current.RewriteUrl, current.Bvin, MTApp.CurrentRequestContext)) { FlashWarning("The requested URL is already in use by another item."); return false; } current.TemplateName = posted.TemplateName; current.CustomerChangeableSortOrder = true; result = MTApp.CatalogServices.Categories.Update(current); if (result == true) { if (oldUrl != string.Empty) { if (oldUrl != current.RewriteUrl) { MTApp.ContentServices.CustomUrls.Register301(oldUrl, current.RewriteUrl, current.Bvin, CustomUrlType.Category, MTApp.CurrentRequestContext, MTApp); } } } } return result; }
protected void btnNew_Click(object sender, ImageClickEventArgs e) { Category c = new Category(); c.ParentId = this.lstParents.SelectedItem.Value; CategorySourceType sourceType = CategorySourceType.Manual; System.Enum.TryParse<CategorySourceType>(this.lstType.SelectedItem.Value, out sourceType); c.SourceType = sourceType; c.Name = "NEW Page"; c.RewriteUrl = "NEW-Page"; c.StoreId = MTApp.CurrentStore.Id; if (c.SourceType == CategorySourceType.CustomPage) { c.GetCurrentVersion().Areas.SetAreaContent("Main", string.Empty); c.TemplateName = "default.html"; } MTApp.CatalogServices.Categories.Create(c); string editUrl = "~" + MTApp.CatalogServices.EditorRouteForCategory(c.SourceType, c.Bvin); editUrl = Page.ResolveUrl(editUrl); Response.Redirect(editUrl); }