Example #1
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;
                    var repo  = new Repository();
                    var items = await repo.GetCats();

                    Cats.Clear();
                    foreach (var item in items)
                    {
                        Cats.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
        public async Task LoadAsync()
        {
            Int64 startTicks = Log.VIEWMODEL("(NavigationViewModel) Enter", Common.LOG_CATEGORY);

            var lookupCats = await _CatLookupDataService.GetCatLookupAsync();

            Cats.Clear();

            foreach (var item in lookupCats)
            {
                Cats.Add(
                    new NavigationItemViewModel(item.Id, item.DisplayMember,
                                                nameof(CatDetailViewModel),
                                                EventAggregator, DialogService));
            }

            var lookupDogs = await _DogLookupDataService.GetDogLookupAsync();

            Dogs.Clear();

            foreach (var item in lookupDogs)
            {
                Dogs.Add(
                    new NavigationItemViewModel(item.Id, item.DisplayMember,
                                                nameof(DogDetailViewModel),
                                                EventAggregator, DialogService));
            }

            //TODO(crhodes)
            // Load more TYPEs as needed here

            Log.VIEWMODEL("(NavigationViewModel) Exit", Common.LOG_CATEGORY, startTicks);
        }
Example #3
0
        public async Task GetCats()
        {
            if (!IsBusy)
            {
                try
                {
                    IsBusy = true;
                    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 Application.Current.MainPage.DisplayAlert("Error!", Error.Message, "Ok");
                    }
                }
            }
        }
        private void LoadMoreDataAsync()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            _deviceService.BeginInvokeOnMainThread(async() => {
                try
                {
                    foreach (var cat in await _catService.GetAllAsync())
                    {
                        Cats.Add(cat);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    IsBusy = false;
                }
            });
        }
        //Atualiza os dados locais do Gato de maneira assincrona
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try {
                    IsBusy = true;
                    // cria instancia do repositório e inicia a tarefa assincrona
                    var Repository = new Repository();
                    var Items      = await Repository.GetCatsAzure();

                    //Limpa lista de e adiciona valores atualizados
                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                } catch (Exception ex) {
                    Error = ex;
                } finally {
                    IsBusy = false;
                }
                // se ocorreu um erro mostre para o usuário
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
Example #6
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception error = null;

                try
                {
                    IsBusy = true;
                    var Repositaro = new Repository();
                    var Items      = await Repositaro.GetCats();

                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    if (error != null)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Error", error.Message, "Ok");
                    }
                    IsBusy = false;
                }
            }

            return;
        }
        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;
                }

                //mostrar uma mensagem em caso de que se tenha gerado uma exceção.
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
Example #8
0
 /// <summary>
 /// adds manually entered Cat data (after validation)
 /// </summary>
 public void AddEnteredData()
 {
     if (!ValidateEnteredData(NewCat))
     {
         MessageBox.Show("Some data is missing!!!");
         return;
     }
     Cats.Add(NewCat);
 }
        public async Task Create_Cat_Successful()
        {
            var cat = new Cat(Guid.NewGuid().ToString(), Ability.Napping);

            Cats.Add(cat);
            await CatRepository.Create(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
Example #10
0
        /// <summary>
        /// randomly generates new instane of Cat and adda it to current collection
        /// </summary>
        public void GenerateRandomCat()
        {
            NewCat = new Cat();
            var rn = new Random();

            NewCat.Name   = Repository.Names[rn.Next(Repository.Names.Count)];
            NewCat.Breed  = Repository.Breeds[rn.Next(Repository.Breeds.Count)];
            NewCat.Color  = Repository.Colors[rn.Next(Repository.Colors.Count)];
            NewCat.Age    = rn.Next(1, 10);
            NewCat.Weight = ((double)rn.Next(800) + 200.0) / 100.0;
            Cats.Add(NewCat);
        }
        public async Task Should_Add_A_Cat()
        {
            var cat = new Cat {
                Name = Guid.NewGuid().ToString(), Ability = Ability.Napping
            };

            Cats.Add(cat);
            await CatRepository.AddAsync(cat);

            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
Example #12
0
 /// <summary>
 /// Loads collection from Json file and replaces current collection
 /// </summary>
 public void LoadFromJson()
 {
     Cats.Clear();
     using (StreamReader fs = File.OpenText("Cats.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         tempCats = (List <Cat>)serializer.Deserialize(fs, typeof(List <Cat>));
         foreach (var item in tempCats)
         {
             Cats.Add(item);
         }
     }
 }
Example #13
0
        /// <summary>
        /// Loads collection from Xml file and replaces current collection
        /// </summary>
        public void LoadFromXml()
        {
            XmlSerializer formatter = new XmlSerializer(typeof(List <Cat>));

            using (FileStream fs = new FileStream("Cats.xml", FileMode.OpenOrCreate))
            {
                tempCats = (List <Cat>)formatter.Deserialize(fs);
                Cats.Clear();
                fs.Close();
                foreach (var item in tempCats)
                {
                    Cats.Add(item);
                }
            }
        }
        public void OneTimeSetUp()
        {
            Setup.Bootstrap(SetupType.Test);

            CreateCatTestData();

            var mockApiClient  = new Mock <IApiClient>();
            var mockServiceBus = new Mock <IMessageBroker <Cat> >();
            var mockCatService = new Mock <ICatService>();

            // Setup the cat service
            mockCatService.Setup(x => x.GetAll()).Returns(Task.FromResult(Cats.AsEnumerable()));

            mockCatService.Setup(x => x.GetById(It.IsAny <Guid>()))
            .Returns((Guid id) => { return(Task.FromResult(Cats.FirstOrDefault(x => x.Id == id))); });

            mockCatService.Setup(x => x.Create(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Update(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                var existing = Cats.Find(x => x.Id == entity.Id);

                Cats.Remove(existing);
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Delete(It.IsAny <Guid>()))
            .Returns((Guid id) =>
            {
                Cats.Remove(Cats.FirstOrDefault(x => x.Id == id));
                return(Task.CompletedTask);
            });

            ApiClient     = mockApiClient.Object;
            MessageBroker = mockServiceBus.Object;
            CatService    = mockCatService.Object;

            ViewModel = new MainViewModel(CatService);
        }
Example #15
0
        public MainWindow()
        {
            InitializeComponent();

            for (int i = 0; i < 10; i++)
            {
                Dogs.Add(new Dog()
                {
                    Name = "Dog" + i
                });

                Cats.Add(new Cat()
                {
                    Name = "Cat" + i
                });
            }

            DataContext = this;
        }
Example #16
0
        public void CreateACat()
        {
            if (Equals(null, _model))
            {
                return;
            }
            Cat           cat = new Cat();
            CatProperties dlg = new CatProperties(cat);

            if (DialogResult.OK == dlg.ShowDialog())
            {
                _model.SaveObject <Cat>(cat);
                // Refresh the cats list
                Cats.Add(cat);
                Cats.Sort((catA, catB) =>
                          catA.CompareTo(catB));
            }
            if (!Equals(null, OnNewCatsAvailable))
            {
                OnNewCatsAvailable(this);
            }
        }
        /// <summary>
        /// Execute the LoadCats command.
        /// </summary>
        /// <returns>Asynchronous task.</returns>
        private async Task ExecuteLoadCatsCommand()
        {
            try
            {
                Cats.Clear();
                if (DataStore != null)
                {
                    var cats = await DataStore.GetAllAsync();

                    foreach (var cat in cats)
                    {
                        Cats.Add(cat);
                    }
                }
            }
            catch (Exception error)
            {
                Debug.WriteLine(error);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #18
0
        public void addCat(string catName, string catColor)
        {
            Cat catToAdd = new Cat(catName, catColor);

            Cats.Add(catToAdd);
        }
Example #19
0
        // otherCats: {
        // "garfield" : {name:"Garfiled", color: "Gold", etc...}
        // }


        public void addCat(string catName, string catColor, int catLives)
        {
            Cat catToAdd = new Cat(catName, catColor, catLives);

            Cats.Add(catToAdd);
        }