public IActionResult SaveReRoute(string id, FileReRouteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("FileReRoute", model));
            }

            var validator = new FileReRouteValidator();
            var results   = validator.Validate(model.FileReRoute);

            if (!results.IsValid)
            {
                results.Errors.ToList().ForEach(e => ModelState.AddModelError(e.PropertyName, e.ErrorMessage));
                return(View("FileReRoute", model));
            }

            var routes = _fileConfigRepo.Get();
            var route  = routes.Data.ReRoutes.FirstOrDefault(r => id == r.GetId());

            if (route != null)
            {
                routes.Data.ReRoutes.Remove(route);
            }

            routes.Data.ReRoutes.Add(model.FileReRoute);
            _fileConfigRepo.Set(routes.Data);

            Reload(routes.Data);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public IActionResult CreateReRoute(string id, FileReRouteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var validator = new FileReRouteValidator();
            var results   = validator.Validate(model.FileReRoute);

            if (!results.IsValid)
            {
                results.Errors.ToList().ForEach(e => ModelState.AddModelError($"FileReRoute.{e.PropertyName}", e.ErrorMessage));
                return(View(model));
            }

            var routes = _fileConfigRepo.Get().GetAwaiter().GetResult();

            routes.Data.ReRoutes.Add(model.FileReRoute);
            _fileConfigRepo.Set(routes.Data);

            _reload.AddReloadFlag();

            return(RedirectToAction("Index"));
        }