public string ip_pool_add(Pool pool)
        {
            var command = new StringBuilder("ip pool add ");
            command.Append(Repository.BuildCommand("name", pool.Name))
                .Append(Repository.BuildCommand("ranges", pool.Addresses))
                .Append(Repository.BuildCommand("next-pool", pool.NextPoolName));

            return Repository.RunCommand(command.ToString());
        }
 public ActionResult Edit(Pool pool)
 {
     if (_service.EditPool(pool))
     {
         _sshService.EditPool(pool.PoolId);
         return View("Index", _service.ListPools());
     }
     ViewData["Pools"] = _service.ListPools(pool.PoolId);
     return View(pool);
 }
        public string ip_pool_add(Pool pool)
        {
            var command = new StringBuilder("ip pool add ");
            command.Append(BuildCommand("name", pool.Name))
                .Append(BuildCommand("ranges", pool.Addresses))
                .Append(BuildCommand("next-pool", pool.NextPoolName));

            _sshStream.Write(command.ToString());
            return ParseResponse(_sshStream.ReadResponse(), command.ToString());
        }
        public string ip_pool_set(Pool pool)
        {
            var command = new StringBuilder("ip pool set ");
            command.Append((string.IsNullOrEmpty(pool.OldName) ? pool.Name : pool.OldName) + " ")
                .Append(Repository.BuildCommand("name", pool.Name))
                .Append(Repository.BuildCommand("ranges", pool.Addresses))
                .Append(Repository.BuildCommand("next-pool", pool.NextPoolName));

            return Repository.RunCommand(command.ToString());
        }
        public bool CreatePool(Pool pool)
        {
            // Validation logic
            if (!ValidatePool(pool))
                return false;

            // Database logic
            try
            {
                _repository.CreatePool(pool);
            }
            catch (Exception ex)
            {
                _validationDictionary.AddError("_FORM", "Pool is not saved. " + ex.Message);
                return false;
            }
            return true;
        }
        public List<Pool> BuildIPPools(string pool)
        {
            var pools = new List<Pool>();
            foreach (var val in Regex.Split(pool, "\r\n\r\n"))
            {
                var properties = Repository.BuildProperties(val);
                var name = Repository.GetValue(properties, "name");

                if (name.Contains("(") || name.Contains(")")) continue;

                var _pool = new Pool
                {
                    Name = name,
                    Addresses = Repository.GetValue(properties, "ranges"),
                    NextPoolName = Repository.GetValue(properties, "next-pool")
                };
                if (!string.IsNullOrEmpty(_pool.Name))
                    pools.Add(_pool);
            }
            return pools;
        }
        public bool ValidatePool(Pool pool)
        {
            bool isValid = true;
            var r = new Regex(PATTERN, RegexOptions.Compiled);
            if (string.IsNullOrEmpty(pool.Name))
            {
                _validationDictionary.AddError("Name", "Pool Name is required.");
                isValid = false;
            }

            if (r.Match(pool.Name).Success)
            {
                _validationDictionary.AddError("Name", "Pool Name " + pool.Name + " contain not allowed symbols '()[]'.");
                isValid = false;
            }
            return isValid;
        }
        public SelectList ListPools(int? selectedValue)
        {
            var list = ListPools();
            SelectList returnList;
            if (selectedValue.HasValue)
                returnList =  new SelectList(list, "PoolId", "Name", selectedValue.Value);
            else
                returnList = new SelectList(list, "PoolId", "Name");

            var pool = new Pool { PoolId = 0, Name = "None"};
            list.Add(pool);
            list.Sort((c1, c2) => c1.PoolId.CompareTo(c2.PoolId));
            return returnList;
        }
 public bool EditPool(Pool pool)
 {
     if (!ValidatePool(pool))
         return false;
     try
     {
         _repository.EditPool(pool);
     }
     catch (Exception ex)
     {
         _validationDictionary.AddError("_FORM", "Pool is not saved. " + ex.Message);
         return false;
     }
     return true;
 }