예제 #1
0
        public (bool, string) AddNew(Host host)
        {
            try
            {
                var lsData = RepoBase.GetHosts();

                if (lsData.Any(d => d.Name.ToLower() == host.Name.ToLower() ||
                               d.HostName.ToLower() == host.HostName.ToLower()))
                {
                    return(false, "Host already exists");
                }

                if (lsData.Count > 0)
                {
                    host.Id = lsData.Max(s => s.Id) + 1;
                }
                else
                {
                    host.Id = 1;
                }

                lsData.Add(host);
                RepoBase.SaveHosts(lsData);

                return(true, "Successful");
            }
            catch (Exception ex)
            {
                return(false, ex.Message);
            }
        }
예제 #2
0
        public (bool, string) Remove(Host host)
        {
            try
            {
                var lsData = RepoBase.GetHosts();

                if (!lsData.Any(d => d.Id == host.Id))
                {
                    return(false, "Host does not exist");
                }

                lsData.Remove(lsData.FirstOrDefault(d => d.Id == host.Id));
                RepoBase.SaveHosts(lsData);

                return(true, "Successful");
            }
            catch (Exception ex)
            {
                return(false, ex.Message);
            }
        }
예제 #3
0
 public IList <Host> GetAll()
 {
     return(RepoBase.GetHosts());
 }