Esempio n. 1
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;
                    var Repository = new Repository();
                    var Items      = await Repository.GetCats();

                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }

                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Error!", Error.Message, "OK");
                }

                return;
            }
        }
 public void Add(Cats cat)
 {
     int alreadyExist = arrayOfCats.FindIndex(f => f.Name.ToLower() == cat.Name.ToLower());
     if (alreadyExist >= 0)
     {
         Console.WriteLine("That cat already exists in the database");
         return;
     }
     else
     {
         arrayOfCats.Add(cat);
     }
 }
        public void Add(Cats cat)
        {
            int alreadyExist = arrayOfCats.FindIndex(f => f.Name.ToLower() == cat.Name.ToLower());

            if (alreadyExist >= 0)
            {
                Console.WriteLine("That cat already exists in the database");
                return;
            }
            else
            {
                arrayOfCats.Add(cat);
            }
        }
        static void Main(string[] args)
        {
            Animals animals = new Animals();
            Cats    cat1    = new Cats();

            cat1.Name = "Wilbur";
            animals.Add(cat1);

            animals.AllCats();

            while (true)
            {
                Console.WriteLine("Enter exit to quit program or remove to remove a cat.");
                Console.Write("Enter new cat's name: ");
                Cats   cat2  = new Cats();
                string input = Console.ReadLine();
                if (input.ToLower() == "exit")
                {
                    Console.WriteLine("Bye Bye!");
                    break;
                }
                else if (input.ToLower() == "remove")
                {
                    Console.Write("Enter name of cat you want to remove: ");
                    string removeName = Console.ReadLine();
                    animals.Remove(removeName);
                    animals.AllCats();
                }
                else
                {
                    cat2.Name = input;
                    animals.Add(cat2);
                    Console.WriteLine("Printing all cats...");
                    animals.AllCats();
                }
            }
            Console.Read();
        }
        static void Main(string[] args)
        {
            Animals animals = new Animals();
            Cats cat1 = new Cats();
            cat1.Name = "Wilbur";
            animals.Add(cat1);

            animals.AllCats();

            while(true)
            {
                Console.WriteLine("Enter exit to quit program or remove to remove a cat.");
                Console.Write("Enter new cat's name: ");
                Cats cat2 = new Cats();
                string input = Console.ReadLine();
                if (input.ToLower() == "exit")
                {
                    Console.WriteLine("Bye Bye!");
                    break;
                }
                else if (input.ToLower() == "remove")
                {
                    Console.Write("Enter name of cat you want to remove: ");
                    string removeName = Console.ReadLine();
                    animals.Remove(removeName);
                    animals.AllCats();
                }
                else {
                    cat2.Name = input;
                    animals.Add(cat2);
                    Console.WriteLine("Printing all cats...");
                    animals.AllCats();
                }
            }
            Console.Read();
        }