예제 #1
0
        public IActionResult EditViewName(string org, string service, string edition, string currentName, string newName)
        {
            if (string.IsNullOrWhiteSpace(currentName) || string.IsNullOrWhiteSpace(newName))
            {
                return(StatusCode(400, "Input missing"));
            }

            if (currentName.Equals(newName, StringComparison.CurrentCultureIgnoreCase))
            {
                return(StatusCode(400, $"Ingen endring. Både nytt og gammelt navn er \"{currentName}\""));
            }

            const string nameRegex = @"^[a-zA-Z][a-zA-Z0-9_\-]{2,30}$";
            var          match     = Regex.Match(newName, nameRegex, RegexOptions.IgnoreCase);

            if (!match.Success)
            {
                return(StatusCode(400, "Minst 3 tegn, kan ikke inneholde mellomrom eller spesialtegn ('-' er tillatt)"));
            }

            bool updated = _viewRepository.UpdateViewName(org, service, edition, currentName, newName);

            if (updated)
            {
                _repository.UpdateViewNameTextResource(org, service, edition, currentName, newName);
            }

            return(Ok());
        }