Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string GenerateFormFieldUniqueName(string currentName)
- {
- currentName = GetNameWithoutBrackets(currentName);
- currentName = currentName.UniqueName();
- try
- {
- var lastOccurence = _formFieldRepository.GetAll()
- .OrderByDescending(x => x.Id)
- .FirstOrDefault(x => x.UniqueName.StartsWith(currentName));
- if (lastOccurence == null) return currentName;
- if (lastOccurence.UniqueName == currentName) return $"{currentName}1";
- var tail = lastOccurence.UniqueName.Replace(currentName, "");
- int count = 0;
- var tailHasIndex = int.TryParse(tail, out count);
- var generatedName = tailHasIndex ? string.Format(currentName, count+1) : currentName;
- if (_formFieldRepository.GetAll().All(f => f.UniqueName != generatedName)) return generatedName;
- return GenerateFormFieldUniqueName($"{generatedName}-2");
- }
- catch (Exception e)
- {
- throw new UserFriendlyException(e.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement