public bool Update(TourDTO tour) { var tourEntity = _tourRepository.First(x => x.Id == tour.Id); if (tourEntity != null) { tourEntity.OverView = tour.OverView; tourEntity.TourActivity = tour.TourActivity; tourEntity.TourCode = tour.TourCode; tourEntity.TourMap = tour.TourMap; tourEntity.TourName = tour.TourName; tourEntity.TourSpot = tour.TourSpot; tourEntity.TourType = tour.TourType; tourEntity.TourImage = tour.TourImage; tourEntity.TourSliderImage = tour.TourSliderImage; tourEntity.SEOTitle = tour.SEOTitle; tourEntity.SEODescription = tour.SEODescription; tourEntity.TourMapDesc = tour.TourMapDesc; tourEntity.TourMapImage = tour.TourMapImage; tourEntity.TourMorning = tour.TourMorning; tourEntity.TourLunch = tour.TourLunch; tourEntity.TourAfternoon = tour.TourAfternoon; tourEntity.Notes = tour.Notes; tourEntity.TourUrl = ConstHelper.UrlFriendly(tour.TourName); return(_tourRepository.Update(tourEntity)); } else { return(false); } }
/// <summary> /// 设置用户状态 /// </summary> /// <param name="userState"></param> public void SetUserState(string userState) { string root = ConstHelper.GetAllDescription <UserTypeConst>()[UserTypeConst.Manage]; if (UserType == UserTypeConst.Manage) { throw new CustomException($"{root}不能更改用户状态!"); } UserState = userState; }
public bool Insert(TourDTO tour) { return(_tourRepository.Add(new Tour() { OverView = tour.OverView, TourActivity = tour.TourActivity, RecordDate = DateTime.Now, TourCode = tour.TourCode, TourMap = "", TourName = tour.TourName, TourSpot = tour.TourSpot, TourSliderImage = tour.TourSliderImage, TourImage = tour.TourImage, TourType = tour.TourType, SEOTitle = tour.SEOTitle, SEODescription = tour.SEODescription, TourUrl = ConstHelper.UrlFriendly(tour.TourName) })); }
/// <summary> /// Creates a URL And SEO friendly slug /// https://www.johanbostrom.se/blog/how-to-create-a-url-and-seo-friendly-string-in-csharp-text-to-slug-generator /// </summary> /// <param name="text">Text to slugify</param> /// <param name="maxLength">Max length of slug</param> /// <returns>URL and SEO friendly string</returns> public static string UrlFriendly(this string text, int maxLength = 0) { // Return empty value if text is null if (text == null) { return(""); } var normalizedString = text // Make lowercase .ToLowerInvariant() // Normalize the text .Normalize(NormalizationForm.FormD); var stringBuilder = new StringBuilder(); var stringLength = normalizedString.Length; var prevdash = false; var trueLength = 0; char c; for (int i = 0; i < stringLength; i++) { c = normalizedString[i]; switch (CharUnicodeInfo.GetUnicodeCategory(c)) { // Check if the character is a letter or a digit if the character is a // international character remap it to an ascii valid character case UnicodeCategory.LowercaseLetter: case UnicodeCategory.UppercaseLetter: case UnicodeCategory.DecimalDigitNumber: if (c < 128) { stringBuilder.Append(c); } else { stringBuilder.Append(ConstHelper.RemapInternationalCharToAscii(c)); } prevdash = false; trueLength = stringBuilder.Length; break; // Check if the character is to be replaced by a hyphen but only if the last character wasn't case UnicodeCategory.SpaceSeparator: case UnicodeCategory.ConnectorPunctuation: case UnicodeCategory.DashPunctuation: case UnicodeCategory.OtherPunctuation: case UnicodeCategory.MathSymbol: if (!prevdash) { stringBuilder.Append('-'); prevdash = true; trueLength = stringBuilder.Length; } break; } // If we are at max length, stop parsing if (maxLength > 0 && trueLength >= maxLength) { break; } } // Trim excess hyphens var result = stringBuilder.ToString().Trim('-'); // Remove any excess character to meet maxlength criteria return(maxLength <= 0 || result.Length <= maxLength ? result : result.Substring(0, maxLength)); }
/// <summary> /// 设置需要跨域的自定义headers /// </summary> /// <param name="headers"></param> public void SetCrossDomainHeaders(string headers) { ConstHelper.SetCrossDomainHeaders(headers); }
/// <summary> /// 设置需要跨域的自定义headers /// </summary> /// <param name="headers"></param> public void SetCrossDomainHeaders(params string[] headers) { ConstHelper.SetCrossDomainHeaders(headers); }
public TestJob(ConstHelper constHelper) { _constHelper = constHelper; }