public void UpdateSlug(ArgumentModel argument) { var postSlug = _commonService.cleanStringPath(argument.name); //Get all argument with father id this argument and update slug var arguments = _argumentService.GetByFatherId(argument.id); foreach (var arg in arguments) { var slug = _slugService.GetById(arg.slugId).name; var replace = _slugService.GetById(argument.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var newSlug = slug.Replace(replace[replace.Length - 1], postSlug); _slugService.Update(arg.slugId, newSlug); } //Get all post with this argument id and update slug var posts = _postService.GetAllByArgumentId(argument.id); foreach (var post in posts) { var slug = _slugService.GetById(post.slugId).name; var replace = _slugService.GetById(argument.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var newSlug = slug.Replace(replace[replace.Length - 1], postSlug); _slugService.Update(post.slugId, newSlug); } var argumentSlug = _slugService.GetById(argument.slugId).name; var slugArray = argumentSlug.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var name = argumentSlug.Replace(slugArray[slugArray.Length - 1], postSlug); _slugService.Update(argument.slugId, name); }
public void UpdateSlug(CategoryModel category) { var categorySlug = _commonService.cleanStringPath(category.name); //Get all argument with this category id and update slug var arguments = _argumentService.GetByCategoryId(category.id); foreach (var arg in arguments) { var slug = _slugService.GetById(arg.slugId).name; var replace = _slugService.GetById(category.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var newSlug = slug.Replace(replace[replace.Length - 1], categorySlug); _slugService.Update(arg.slugId, newSlug); } //Get all post with this category id and update slug var posts = _postService.GetAllByCategory(category.id); foreach (var post in posts) { var slug = _slugService.GetById(post.slugId).name; var replace = _slugService.GetById(category.slugId).name.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var newSlug = slug.Replace(replace[replace.Length - 1], categorySlug); _slugService.Update(post.slugId, newSlug); } var oldSlug = _slugService.GetById(category.slugId).name; var slugArray = oldSlug.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var name = oldSlug.Replace(slugArray[slugArray.Length - 1], categorySlug); _slugService.Update(category.slugId, name); }
public void UpdateSlug(Posts model) { var postSlug = _commonService.cleanStringPath(model.title); var oldSlug = _slugService.GetById(model.slugId).name; var slugArray = oldSlug.Split('/').Where(x => !string.IsNullOrEmpty(x)).ToArray(); var name = oldSlug.Replace(slugArray[slugArray.Length - 1], postSlug); _slugService.Update(model.slugId, name); }