public async Task <IActionResult> Create(ProductAttributeModel model, bool continueEditing) { if (ModelState.IsValid) { var productAttribute = model.ToEntity(); productAttribute.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(productAttribute.SeName) ? productAttribute.Name : productAttribute.SeName, _seoSettings); if (_workContext.CurrentCustomer.IsStaff()) { model.LimitedToStores = true; model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } await _productAttributeService.InsertProductAttribute(productAttribute); //activity log await _customerActivityService.InsertActivity("AddNewProductAttribute", productAttribute.Id, _localizationService.GetResource("ActivityLog.AddNewProductAttribute"), productAttribute.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = productAttribute.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form //Stores await model.PrepareStoresMappingModel(null, _storeService, true); return(View(model)); }
protected virtual string GetBundleVirtualPath(string prefix, string extension, string[] parts) { if (parts == null || parts.Length == 0) { throw new ArgumentException("parts"); } //calculate hash var hash = ""; using (SHA256 sha = new SHA256Managed()) { // string concatenation var hashInput = ""; foreach (var part in parts) { hashInput += part; hashInput += ","; } var input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput)); hash = HttpServerUtility.UrlTokenEncode(input); } //ensure only valid chars hash = SeoExtensions.GetSeName(hash); var sb = new StringBuilder(prefix); sb.Append(hash); //we used "extension" when we had "runAllManagedModulesForAllRequests" set to "true" in web.config //now we disabled it. hence we should not use "extension" //sb.Append(extension); return(sb.ToString()); }
public async Task <IActionResult> CategoryCreate(BlogCategoryModel model, bool continueEditing) { if (ModelState.IsValid) { if (_workContext.CurrentCustomer.IsStaff()) { model.LimitedToStores = true; model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } var blogCategory = model.ToEntity(); blogCategory.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName, _seoSettings); await _blogService.InsertBlogCategory(blogCategory); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogCategory.Added")); return(continueEditing ? RedirectToAction("CategoryEdit", new { id = blogCategory.Id }) : RedirectToAction("CategoryList")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = await _languageService.GetAllLanguages(true); //locales await AddLocales(_languageService, model.Locales); //Stores await model.PrepareStoresMappingModel(null, _storeService, true); return(View(model)); }
public ActionResult UpdateAttendanceStatus(int eventPageId, int attendanceStatusId) { if (_workContext.CurrentCustomer.IsGuest()) { return(Json(new { redirect = Url.RouteUrl("Login") }, JsonRequestBehavior.AllowGet)); } try { if (!System.Enum.IsDefined(typeof(AttendanceStatus), attendanceStatusId)) { throw new ApplicationException("Invalid attendance status."); } var customerId = _workContext.CurrentCustomer.Id; var customerAttendanceStatus = _eventPageAttendanceService.GetCustomerAttendanceStatus(eventPageId, customerId); var previousAttendanceStatusId = attendanceStatusId; if (customerAttendanceStatus == null) // new attendance { customerAttendanceStatus = new EventPageAttendance() { EventPageId = eventPageId, CustomerId = customerId, AttendanceStatusId = attendanceStatusId, DateCreated = DateTime.Now, DateUpdated = DateTime.Now }; _eventPageAttendanceService.Insert(customerAttendanceStatus); } else // update existing attendance { previousAttendanceStatusId = customerAttendanceStatus.AttendanceStatusId; customerAttendanceStatus.AttendanceStatusId = attendanceStatusId; customerAttendanceStatus.DateUpdated = DateTime.Now; _eventPageAttendanceService.Update(customerAttendanceStatus); } return(Json(new { PreviousAttendanceStatusId = previousAttendanceStatusId, EventPageAttendanceId = customerAttendanceStatus.Id, EventPageId = eventPageId, CustomerId = customerId, AttendanceStatusId = attendanceStatusId, FullName = _workContext.CurrentCustomer.GetFullName(), PictureUrl = _pictureService.GetPictureUrl( _workContext.CurrentCustomer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(_workContext.CurrentCustomer, 0) }), })); } catch { return(Json(false)); } }
protected virtual string GetBundleFileNameBasingOnModifyTime(string[] filePaths) { if (filePaths == null || filePaths.Length == 0) { throw new ArgumentException("parts"); } var ticks = filePaths.Where(filePath => File.Exists(filePath)).Select(filePath => { return(File.GetLastWriteTimeUtc(filePath).Ticks); }); //calculate hash var hash = ""; using (SHA256 sha = SHA256.Create()) { // string concatenation var hashInput = ""; foreach (var tick in ticks) { hashInput += tick; hashInput += ","; } byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput)); hash = WebEncoders.Base64UrlEncode(input); } //ensure only valid chars hash = SeoExtensions.GetSeName(hash, _seoSettings); return(hash); }
public IHttpActionResult InviteFriends(int eventPageId, int[] customerIds) { if (_workContext.CurrentCustomer.IsGuest()) { return(Json(new { redirect = Url.RouteUrl("Login") }, JsonRequestBehavior.AllowGet)); } var invitedCustomers = _eventPageAttendanceService.InviteFriends(eventPageId, customerIds); var models = new List <object>(); foreach (var customer in invitedCustomers) { models.Add(new { CustomerId = customer.Id, FullName = customer.GetFullName(), PictureUrl = _pictureService.GetPictureUrl( customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }), }); } return(Json(models)); }
public async Task <IActionResult> OptionCreatePopup(SpecificationAttributeOptionModel model) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeById(model.SpecificationAttributeId); if (specificationAttribute == null) { //No specification attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { var sao = model.ToEntity(); sao.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(sao.SeName) ? sao.Name : sao.SeName, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion); //clear "Color" values if it's disabled if (!model.EnableColorSquaresRgb) { sao.ColorSquaresRgb = null; } specificationAttribute.SpecificationAttributeOptions.Add(sao); await _specificationAttributeService.UpdateSpecificationAttribute(specificationAttribute); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
public IHttpActionResult GetInvited(int eventPageId) { var invited = _eventPageAttendanceService.GetAllInvited(eventPageId); if (invited.Count == 0) { return(Json(null)); } var invitedCustomers = _customerService.GetCustomersByIds(invited.Select(x => x.CustomerId).ToArray()); var models = new List <object>(); foreach (var customer in invitedCustomers) { models.Add(new { CustomerId = customer.Id, FullName = customer.GetFullName(), PictureUrl = _pictureService.GetPictureUrl( customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }), }); } return(Json(models)); }
public async Task <IActionResult> Edit(SpecificationAttributeModel model, bool continueEditing) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeById(model.Id); if (specificationAttribute == null) { //No specification attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { specificationAttribute = model.ToEntity(specificationAttribute); specificationAttribute.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(specificationAttribute.SeName) ? specificationAttribute.Name : specificationAttribute.SeName, _seoSettings); await _specificationAttributeService.UpdateSpecificationAttribute(specificationAttribute); //activity log await _customerActivityService.InsertActivity("EditSpecAttribute", specificationAttribute.Id, _localizationService.GetResource("ActivityLog.EditSpecAttribute"), specificationAttribute.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = specificationAttribute.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> CategoryCreate(BlogCategoryModel model, bool continueEditing) { if (ModelState.IsValid) { if (await _groupService.IsStaff(_workContext.CurrentCustomer)) { model.Stores = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } var blogCategory = model.ToEntity(); blogCategory.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion); await _blogService.InsertBlogCategory(blogCategory); Success(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Added")); return(continueEditing ? RedirectToAction("CategoryEdit", new { id = blogCategory.Id }) : RedirectToAction("CategoryList")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = await _languageService.GetAllLanguages(true); //locales await AddLocales(_languageService, model.Locales); return(View(model)); }
/// <summary> /// Get picture SEO friendly name /// </summary> /// <param name="name">Name</param> /// <returns>Result</returns> public virtual string GetPictureSeName(string name) { //if (String.IsNullOrEmpty(name)) // return name; //string okChars = "abcdefghijklmnopqrstuvwxyz1234567890 _-"; //name = name.Trim().ToLowerInvariant(); //var sb = new StringBuilder(); //foreach (char c in name.ToCharArray()) //{ // string c2 = c.ToString(); // if (okChars.Contains(c2)) // sb.Append(c2); //} //string name2 = sb.ToString(); //name2 = name2.Replace(" ", "_"); //name2 = name2.Replace("-", "_"); //while (name2.Contains("__")) // name2 = name2.Replace("__", "_"); //return name2.ToLowerInvariant(); //use SeoExtensions implementation return(SeoExtensions.GetSeName(name, true, false, false)); }
public async Task <IActionResult> OptionEditPopup(SpecificationAttributeOptionModel model) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeByOptionId(model.Id); var sao = specificationAttribute.SpecificationAttributeOptions.Where(x => x.Id == model.Id).FirstOrDefault(); if (sao == null) { //No specification attribute option found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { sao = model.ToEntity(sao); sao.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(sao.SeName) ? sao.Name : sao.SeName, _seoSettings); //clear "Color" values if it's disabled if (!model.EnableColorSquaresRgb) { sao.ColorSquaresRgb = null; } await _specificationAttributeService.UpdateSpecificationAttribute(specificationAttribute); ViewBag.RefreshPage = true; return(View(model)); } //If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Get bundled file name /// </summary> /// <param name="parts">Parts to bundle</param> /// <returns>File name</returns> protected virtual string GetBundleFileName(string[] parts) { if (parts == null || parts.Length == 0) { throw new ArgumentException("parts"); } //calculate hash var hash = ""; using (SHA256 sha = new SHA256Managed()) { // string concatenation var hashInput = ""; foreach (var part in parts) { hashInput += part; hashInput += ","; } var input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput)); hash = WebEncoders.Base64UrlEncode(input); } //ensure only valid chars hash = SeoExtensions.GetSeName(hash); return(hash); }
protected virtual string GetBundleVirtualPath(string prefix, string postfix, string[] parts) { if (parts == null || parts.Length == 0) { throw new ArgumentException("parts"); } //calculate hash var hash = ""; using (SHA256 sha = new SHA256Managed()) { // string concatenation var hashInput = ""; foreach (var part in parts) { hashInput += part; hashInput += ","; } byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput)); hash = HttpServerUtility.UrlTokenEncode(input); } //ensure only valid chars hash = SeoExtensions.GetSeName(hash); var sb = new StringBuilder(prefix); sb.Append(hash); sb.Append(postfix); return(sb.ToString()); }
public UrlRecord GetUrlRecord <T>(T entity, string typeName = "", bool isUpdate = true) where T : IPermalinkSupported { //first check if the entity already has a permalink if (string.IsNullOrWhiteSpace(typeName)) { typeName = entity.GetType().Name; } var urlRecord = FirstOrDefault(x => x.EntityName == typeName && x.EntityId == entity.Id); if (urlRecord == null) { urlRecord = new UrlRecord() { EntityName = typeName, EntityId = entity.Id, Slug = SeoExtensions.GetSeName(entity.Name), IsActive = true }; //save it Insert(urlRecord); } else { if (isUpdate) { urlRecord.Slug = SeoExtensions.GetSeName(entity.Name); urlRecord.IsActive = true; Update(urlRecord); } } return(urlRecord); }
public ActionResult GetAttendance(int start, int count, int attendanceStatusId) { if (System.Enum.IsDefined(typeof(AttendanceStatus), attendanceStatusId)) { return(Json(null)); } var attendances = new List <EventPageAttendance>(); var attendanceStatusName = string.Empty; switch (attendanceStatusId) { case (int)AttendanceStatus.Invited: attendanceStatusName = AttendanceStatus.Invited.ToString(); attendances = _eventPageAttendanceService.GetInvited(start, count); break; case (int)AttendanceStatus.Going: attendanceStatusName = AttendanceStatus.Going.ToString(); attendances = _eventPageAttendanceService.GetGoing(start, count); break; case (int)AttendanceStatus.Maybe: attendanceStatusName = AttendanceStatus.Maybe.ToString(); attendances = _eventPageAttendanceService.GetMaybies(start, count); break; case (int)AttendanceStatus.NotGoing: attendanceStatusName = AttendanceStatus.NotGoing.ToString(); attendances = _eventPageAttendanceService.GetNotGoing(start, count); break; } var customerIds = attendances.Select(x => x.CustomerId).ToArray(); var customers = _customerService.GetCustomersByIds(customerIds); var models = new List <object>(); foreach (var customer in customers) { models.Add(new { FullName = customer.GetFullName(), PictureUrl = _pictureService.GetPictureUrl( customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mobSocialSettings.EventPageAttendanceThumbnailSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar), ProfileUrl = Url.RouteUrl("CustomerProfileUrl", new { SeName = SeoExtensions.GetSeName(customer, 0) }), }); } return(Json(new { AttendanceStatusName = attendanceStatusName, Customers = models })); }
public async Task <IActionResult> CategoryEdit(BlogCategoryModel model, bool continueEditing) { var blogCategory = await _blogService.GetBlogCategoryById(model.Id); if (blogCategory == null) { //No blog post found with the specified id return(RedirectToAction("CategoryList")); } if (_workContext.CurrentCustomer.IsStaff()) { if (!blogCategory.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId)) { return(RedirectToAction("CategoryEdit", new { id = blogCategory.Id })); } } if (ModelState.IsValid) { if (_workContext.CurrentCustomer.IsStaff()) { model.LimitedToStores = true; model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } blogCategory = model.ToEntity(blogCategory); blogCategory.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName, _seoSettings); await _blogService.UpdateBlogCategory(blogCategory); SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.Blog.BlogCategory.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("CategoryEdit", new { id = blogCategory.Id })); } return(RedirectToAction("CategoryList")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = await _languageService.GetAllLanguages(true); //locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = blogCategory.GetLocalized(x => x.Name, languageId, false, false); }); //Store await model.PrepareStoresMappingModel(blogCategory, _storeService, true, _workContext.CurrentCustomer.StaffStoreId); return(View(model)); }
protected virtual string GetBundleVirtualPath(BundleType type, IEnumerable <string> files) { if (files == null || !files.Any()) { throw new ArgumentException("parts"); } string prefix = "~/bundles/js/"; string postfix = ".js"; if (type == BundleType.Stylesheet) { prefix = "~/bundles/css/"; postfix = ".css"; } // TBD: routing fix postfix = ""; // compute hash var hash = ""; using (SHA256 sha = new SHA256Managed()) { var hashInput = ""; foreach (var file in files.OrderBy(x => x)) { hashInput += file; hashInput += ","; } byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput)); hash = HttpServerUtility.UrlTokenEncode(input); // append StoreId & ThemeName to hash in order to vary cache by store/theme combination if (type == BundleType.Stylesheet && !_workContext.IsAdmin && files.Any(x => x.EndsWith(".scss", StringComparison.OrdinalIgnoreCase))) { hash += "-s" + _storeContext.CurrentStore.Id; hash += "-t" + _themeContext.CurrentTheme.ThemeName; } } // ensure only valid chars hash = SeoExtensions.GetSeName(hash); var sb = new StringBuilder(prefix); sb.Append(hash); sb.Append(postfix); return(sb.ToString()); }
protected virtual async Task InstallVendors() { var vendors = new List <Vendor> { new Vendor { Name = "Vendor 1", Email = "*****@*****.**", Description = "Some description...", AdminComment = "", PictureId = "", Active = true, DisplayOrder = 1, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9, 18", }, new Vendor { Name = "Vendor 2", Email = "*****@*****.**", Description = "Some description...", AdminComment = "", PictureId = "", Active = true, DisplayOrder = 2, PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = "6, 3, 9, 18", } }; await _vendorRepository.InsertAsync(vendors); //search engine names foreach (var vendor in vendors) { var seName = SeoExtensions.GenerateSlug(vendor.Name, false, false, false); await _entityUrlRepository.InsertAsync(new EntityUrl { EntityId = vendor.Id, EntityName = "Vendor", LanguageId = "", IsActive = true, Slug = seName }); vendor.SeName = seName; await _vendorRepository.UpdateAsync(vendor); } }
public async Task <IActionResult> CategoryEdit(BlogCategoryModel model, bool continueEditing) { var blogCategory = await _blogService.GetBlogCategoryById(model.Id); if (blogCategory == null) { //No blog post found with the specified id return(RedirectToAction("CategoryList")); } if (await _groupService.IsStaff(_workContext.CurrentCustomer)) { if (!blogCategory.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId)) { return(RedirectToAction("CategoryEdit", new { id = blogCategory.Id })); } } if (ModelState.IsValid) { if (await _groupService.IsStaff(_workContext.CurrentCustomer)) { model.Stores = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } blogCategory = model.ToEntity(blogCategory); blogCategory.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(blogCategory.SeName) ? blogCategory.Name : blogCategory.SeName, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion); await _blogService.UpdateBlogCategory(blogCategory); Success(_translationService.GetResource("Admin.Content.Blog.BlogCategory.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("CategoryEdit", new { id = blogCategory.Id })); } return(RedirectToAction("CategoryList")); } //If we got this far, something failed, redisplay form ViewBag.AllLanguages = await _languageService.GetAllLanguages(true); //locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = blogCategory.GetTranslation(x => x.Name, languageId, false); }); return(View(model)); }
protected virtual async Task InstallNews() { var defaultLanguage = _languageRepository.Table.FirstOrDefault(); var news = new List <NewsItem> { new NewsItem { AllowComments = false, Title = "About Grandnode", Short = "It's stable and highly usable. From downloads to documentation, www.grandnode.com offers a comprehensive base of information, resources, and support to the grandnode community.", Full = "<p>For full feature list go to <a href=\"https://grandnode.com\">grandnode.com</a></p><p>Providing outstanding custom search engine optimization, web development services and e-commerce development solutions to our clients at a fair price in a professional manner.</p>", Published = true, CreatedOnUtc = DateTime.UtcNow, }, new NewsItem { AllowComments = false, Title = "Grandnode new release!", Short = "grandnode includes everything you need to begin your e-commerce online store. We have thought of everything and it's all included! grandnode is a fully customizable shopping cart", Full = "<p>Grandnode includes everything you need to begin your e-commerce online store. We have thought of everything and it's all included!</p>", Published = true, CreatedOnUtc = DateTime.UtcNow.AddSeconds(1), }, new NewsItem { AllowComments = false, Title = "New online store is open!", Short = "The new grandnode store is open now! We are very excited to offer our new range of products. We will be constantly adding to our range so please register on our site.", Full = "<p>Our online store is officially up and running. Stock up for the holiday season! We have a great selection of items. We will be constantly adding to our range so please register on our site, this will enable you to keep up to date with any new products.</p><p>All shipping is worldwide and will leave the same day an order is placed! Happy Shopping and spread the word!!</p>", Published = true, CreatedOnUtc = DateTime.UtcNow.AddSeconds(2), }, }; await _newsItemRepository.InsertAsync(news); //search engine names foreach (var newsItem in news) { newsItem.SeName = SeoExtensions.GenerateSlug(newsItem.Title, false, false, false); await _entityUrlRepository.InsertAsync(new EntityUrl { EntityId = newsItem.Id, EntityName = "NewsItem", LanguageId = "", IsActive = true, Slug = newsItem.SeName }); await _newsItemRepository.UpdateAsync(newsItem); } }
public ActionResult Create(EventPageModel model, bool continueEditing) { //if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) // return AccessDeniedView(); if (ModelState.IsValid) { var entity = new EventPage() { Name = model.Name, LocationName = model.LocationName, LocationAddress1 = model.LocationAddress1, LocationAddress2 = model.LocationAddress2, LocationCity = model.City, LocationState = model.LocationState, LocationZipPostalCode = model.ZipPostalCode, LocationPhone = model.Phone, LocationWebsite = model.Website, LocationEmail = model.Email, LocationCountry = model.LocationCountry, StartDate = model.StartDate, EndDate = model.EndDate, Description = model.Description, MetaKeywords = model.MetaKeywords, MetaDescription = model.MetaDescription, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, }; //search engine name model.SeName = SeoExtensions.GetSeName(entity, _workContext.WorkingLanguage.Id); // todo: add event hosts _eventPageService.Insert(entity); //save hotels //SaveEventHotels(product, ParseProductTags(model.ProductTags)); //activity log //_customerActivityService.InsertActivity("AddNewProduct", _localizationService.GetResource("ActivityLog.AddNewProduct"), product.Name); _customerActivityService.InsertActivity("AddNewEventPage", _localizationService.GetResource("ActivityLog.AddNewEventPage"), entity.Name); SuccessNotification(_localizationService.GetResource("Admin.MobSocial.EventPage.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = entity.Id }) : RedirectToAction("List")); } return(View("~/Plugins/Widgets.mobSocial/Views/mobSocial/Admin/ManageEventPage/Create.cshtml", model)); }
public async Task <IActionResult> Edit(SpecificationAttributeModel model, bool continueEditing) { var specificationAttribute = await _specificationAttributeService.GetSpecificationAttributeById(model.Id); if (specificationAttribute == null) { //No specification attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { specificationAttribute = model.ToEntity(specificationAttribute); specificationAttribute.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(specificationAttribute.SeName) ? specificationAttribute.Name : specificationAttribute.SeName, _seoSettings); if (_workContext.CurrentCustomer.IsStaff()) { model.LimitedToStores = true; model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } await _specificationAttributeService.UpdateSpecificationAttribute(specificationAttribute); //activity log await _customerActivityService.InsertActivity("EditSpecAttribute", specificationAttribute.Id, _localizationService.GetResource("ActivityLog.EditSpecAttribute"), specificationAttribute.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = specificationAttribute.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form //Stores await model.PrepareStoresMappingModel(specificationAttribute, _storeService, false, _workContext.CurrentCustomer.StaffStoreId); //locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = specificationAttribute.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
/// <summary> /// Validate friendly URL name /// </summary> /// <param name="affiliate">Affiliate</param> /// <param name="friendlyUrlName">Friendly URL name</param> /// <returns>Valid friendly name</returns> public static string ValidateFriendlyUrlName(this Affiliate affiliate, string friendlyUrlName) { if (affiliate == null) { throw new ArgumentNullException("affiliate"); } //ensure we have only valid chars friendlyUrlName = SeoExtensions.GetSeName(friendlyUrlName); //max length //For long URLs we can get the following error: //"the specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters" //that's why we limit it to 200 here (consider a store URL + probably added {0}-{1} below) friendlyUrlName = CommonHelper.EnsureMaximumLength(friendlyUrlName, 200); //ensure this name is not reserved yet //empty? nothing to check if (String.IsNullOrEmpty(friendlyUrlName)) { return(friendlyUrlName); } //check whether such friendly URL name already exists (and that is not the current affiliate) int i = 2; var tempName = friendlyUrlName; while (true) { var affiliateService = EngineContext.Current.Resolve <IAffiliateService>(); var affiliateByFriendlyUrlName = affiliateService.GetAffiliateByFriendlyUrlName(tempName); bool reserved = affiliateByFriendlyUrlName != null && affiliateByFriendlyUrlName.Id != affiliate.Id; if (!reserved) { break; } tempName = string.Format("{0}-{1}", friendlyUrlName, i); i++; } friendlyUrlName = tempName; return(friendlyUrlName); }
//action displaying notification (warning) to a store owner that entered SE URL already exists public virtual IActionResult UrlReservedWarning(string entityId, string entityName, string seName) { if (string.IsNullOrEmpty(seName)) { return(Json(new { Result = string.Empty })); } int.TryParse(entityId, out int parsedEntityId); var validatedSeName = SeoExtensions.ValidateSeName(parsedEntityId, entityName, seName, null, false); if (seName.Equals(validatedSeName, StringComparison.InvariantCultureIgnoreCase)) { return(Json(new { Result = string.Empty })); } return(Json(new { Result = string.Format(_localizationService.GetResource("Admin.System.Warnings.URL.Reserved"), validatedSeName) })); }
public async Task <IActionResult> Create(SpecificationAttributeModel model, bool continueEditing) { if (ModelState.IsValid) { var specificationAttribute = model.ToEntity(); specificationAttribute.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(specificationAttribute.SeName) ? specificationAttribute.Name : specificationAttribute.SeName, _seoSettings); await _specificationAttributeService.InsertSpecificationAttribute(specificationAttribute); //activity log await _customerActivityService.InsertActivity("AddNewSpecAttribute", specificationAttribute.Id, _localizationService.GetResource("ActivityLog.AddNewSpecAttribute"), specificationAttribute.Name); SuccessNotification(_localizationService.GetResource("Admin.Catalog.Attributes.SpecificationAttributes.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = specificationAttribute.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public void SeoExtensionsTest() { //german letters with diacritics Assert.AreEqual("testaou", SeoExtensions.GetSeName("testäöü", true, false)); Assert.AreEqual("test", SeoExtensions.GetSeName("testäöü", false, false)); //russian letters Assert.AreEqual("testtest", SeoExtensions.GetSeName("testтест", true, false)); Assert.AreEqual("test", SeoExtensions.GetSeName("testтест", false, false)); Assert.AreEqual("test", SeoExtensions.GetSeName("testтест", false, false)); Assert.AreEqual("testтест", SeoExtensions.GetSeName("testтест", false, true)); //other Assert.AreEqual("abcdefghijklmnopqrstuvwxyz1234567890", SeoExtensions.GetSeName("abcdefghijklmnopqrstuvwxyz1234567890", false, false)); Assert.AreEqual("test-test", SeoExtensions.GetSeName("test test", false, false)); Assert.AreEqual("test-test", SeoExtensions.GetSeName("test test", false, false)); }
public async Task <IActionResult> Edit(ProductAttributeModel model, bool continueEditing) { var productAttribute = await _productAttributeService.GetProductAttributeById(model.Id); if (productAttribute == null) { //No product attribute found with the specified id return(RedirectToAction("List")); } if (ModelState.IsValid) { productAttribute = model.ToEntity(productAttribute); productAttribute.SeName = SeoExtensions.GetSeName(string.IsNullOrEmpty(productAttribute.SeName) ? productAttribute.Name : productAttribute.SeName, _seoSettings.ConvertNonWesternChars, _seoSettings.AllowUnicodeCharsInUrls, _seoSettings.SeoCharConversion); if (await _groupService.IsStaff(_workContext.CurrentCustomer)) { model.Stores = new string[] { _workContext.CurrentCustomer.StaffStoreId }; } await _productAttributeService.UpdateProductAttribute(productAttribute); //activity log await _customerActivityService.InsertActivity("EditProductAttribute", productAttribute.Id, _translationService.GetResource("ActivityLog.EditProductAttribute"), productAttribute.Name); Success(_translationService.GetResource("Admin.Catalog.Attributes.ProductAttributes.Updated")); if (continueEditing) { //selected tab await SaveSelectedTabIndex(); return(RedirectToAction("Edit", new { id = productAttribute.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form // locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = productAttribute.GetTranslation(x => x.Name, languageId, false); locale.Description = productAttribute.GetTranslation(x => x.Description, languageId, false); }); return(View(model)); }
/// <summary> /// Validate friendly URL name /// </summary> /// <param name="affiliate">Affiliate</param> /// <param name="friendlyUrlName">Friendly URL name</param> /// <returns>Valid friendly name</returns> public static string ValidateFriendlyUrlName(this Affiliate affiliate, string friendlyUrlName) { if (affiliate == null) { throw new ArgumentNullException(nameof(affiliate)); } //ensure we have only valid chars friendlyUrlName = SeoExtensions.GetSeName(friendlyUrlName); //max length //(consider a store URL + probably added {0}-{1} below) friendlyUrlName = CommonHelper.EnsureMaximumLength(friendlyUrlName, NopAffiliateDefaults.FriendlyUrlNameLength); //ensure this name is not reserved yet //empty? nothing to check if (string.IsNullOrEmpty(friendlyUrlName)) { return(friendlyUrlName); } //check whether such friendly URL name already exists (and that is not the current affiliate) var i = 2; var tempName = friendlyUrlName; while (true) { var affiliateService = EngineContext.Current.Resolve <IAffiliateService>(); var affiliateByFriendlyUrlName = affiliateService.GetAffiliateByFriendlyUrlName(tempName); var reserved = affiliateByFriendlyUrlName != null && affiliateByFriendlyUrlName.Id != affiliate.Id; if (!reserved) { break; } tempName = $"{friendlyUrlName}-{i}"; i++; } friendlyUrlName = tempName; return(friendlyUrlName); }
/// <summary> /// Validate friendly URL name /// </summary> /// <param name="affiliate">Affiliate</param> /// <param name="friendlyUrlName">Friendly URL name</param> /// <returns>Valid friendly name</returns> public static async Task <string> ValidateFriendlyUrlName(this Affiliate affiliate, IAffiliateService affiliateService, SeoSettings seoSettings, string friendlyUrlName, string name) { if (affiliate == null) { throw new ArgumentNullException(nameof(affiliate)); } if (string.IsNullOrEmpty(friendlyUrlName)) { friendlyUrlName = name; } //ensure we have only valid chars friendlyUrlName = SeoExtensions.GetSeName(friendlyUrlName, seoSettings.ConvertNonWesternChars, seoSettings.AllowUnicodeCharsInUrls, seoSettings.SeoCharConversion); //max length friendlyUrlName = CommonHelper.EnsureMaximumLength(friendlyUrlName, 200); if (String.IsNullOrEmpty(friendlyUrlName)) { return(friendlyUrlName); } //check whether such friendly URL name already exists (and that is not the current affiliate) int i = 2; var tempName = friendlyUrlName; while (true) { var affiliateByFriendlyUrlName = await affiliateService.GetAffiliateByFriendlyUrlName(tempName); bool reserved = affiliateByFriendlyUrlName != null && affiliateByFriendlyUrlName.Id != affiliate.Id; if (!reserved) { break; } tempName = string.Format("{0}-{1}", friendlyUrlName, i); i++; } friendlyUrlName = tempName; return(friendlyUrlName); }