/// <summary>
        /// Get what the mission's link should be
        /// </summary>
        /// <param name="mission"></param>
        /// <returns>Link</returns>
        public static string GetMissionLink(ApplicationDbContext context, Mission mission)
        {
            var link = mission.Name;

            var counter = 1;

            link = Regex.Replace(link, @"\p{P}", ""); //remove punctuation
            link = link.Replace(' ', '-');            // change spaces
            link = link.ToLower();                    //lowercase

            var originalLink = link;


            if (MissionHelper.IsRestrictedMissionName(link))
            {
                link = originalLink + counter;
                counter++;
            }

            //check if the link already exists, and isn't this mission
            while (context.Missions.Any(m => m.MissionLink.Equals(link) && m.Id.Equals(mission.Id)))
            {
                link = originalLink + counter;
                counter++;
            }

            return(link);
        }
Ejemplo n.º 2
0
        internal static void SetMissionLinks(ApplicationDbContext context)
        {
            var noLinkMissions = context.Missions.Where(m => string.IsNullOrEmpty(m.MissionLink)).ToList();

            foreach (var mission in noLinkMissions)
            {
                mission.MissionLink = MissionHelper.GetMissionLink(context, mission);
                context.SaveChanges();
            }
        }