예제 #1
0
        private bool PopulateData(IPlant plant)
        {
            SaveCommand   = new Command(Save, CanSave);
            CancelCommand = new Command(Cancel, CanCancel);

            try
            {
                Strains   = Strain.FindAll().OrderBy(x => x.Name);
                Schedules = Schedule.FindAll().OrderBy(x => x.Name);
                Gardens   = Garden.FindAll().OrderBy(x => x.Name);

                if (plant == null)
                {
                    Plant = new Plant();
                    return(true);
                }

                Plant            = Plant.Find(plant.Id);
                SelectedSchedule = Schedules.Where(x => x.Id == plant.ScheduleId).FirstOrDefault();
                SelectedStrain   = Strains.Where(x => x.Id == plant.Strain.Id).FirstOrDefault();
                SelectedGarden   = Gardens.Where(x => x.Id == plant.GardenId).SingleOrDefault();
                _isDirty         = false;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool FillGardens()
        {
            try
            {
                IEnumerable <Garden>         gardenList = Garden.FindAll();
                List <GardenCollectionModel> model      = new List <GardenCollectionModel>();
                foreach (Garden garden in gardenList)
                {
                    model.Add(new GardenCollectionModel(garden));
                }

                IOrderedEnumerable <GardenCollectionModel> orderedModel = model.OrderBy(x => x.Garden.Name);
                Model = model;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }