Пример #1
0
        public async Task <int> DeleteWateringStationAsync(WateringStation wateringStation)
        {
            int             result          = 0;
            WateringStation existingStation = await database.Table <WateringStation>().Where(i => i.guid == wateringStation.guid).FirstOrDefaultAsync();

            if (existingStation != null)
            {
                result = database.DeleteAsync(wateringStation).Result;
            }
            return(result);
        }
Пример #2
0
        public async Task <int> SaveWateringStationAsync(WateringStation wateringStation)
        {
            WateringStation existingStation = await database.Table <WateringStation>().Where(i => i.guid == wateringStation.guid).FirstOrDefaultAsync();

            if (existingStation != null)
            {
                return(database.UpdateAsync(wateringStation).Result);
            }
            else
            {
                return(database.InsertAsync(wateringStation).Result);
            }
        }
        public async Task <bool> DeleteWateringStation()
        {
            int             result          = 0;
            WateringStation wateringStation = new WateringStation();

            wateringStation.guid   = this.guid;
            wateringStation.number = this.number;
            try
            {
                result = await App.Database.DeleteWateringStationAsync(wateringStation);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        public WateringStationViewModel(int stationNumber)
        {
            WateringStation checkExistingStation = App.Database.GetWateringStationAsync(stationNumber).Result;

            if (checkExistingStation == null)
            {
                this.guid   = Guid.NewGuid().ToString();
                this.active = false;
            }
            else
            {
                this.guid         = checkExistingStation.guid;
                this.number       = checkExistingStation.number;
                this.name         = checkExistingStation.name;
                this.fullName     = checkExistingStation.fullName;
                this.active       = checkExistingStation.active;
                this.wateringTime = checkExistingStation.wateringTime;
            }
        }
        public async Task <bool> SaveWateringStation()
        {
            int             result          = 0;
            WateringStation wateringStation = new WateringStation();

            wateringStation.guid         = this.guid;
            wateringStation.number       = this.number;
            wateringStation.name         = this.name;
            wateringStation.wateringTime = this.wateringTime;
            this.fullName            = String.Concat(this.number, " - ", this.name);
            wateringStation.fullName = String.Concat(this.number, " - ", this.name);
            try
            {
                result = await App.Database.SaveWateringStationAsync(wateringStation);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        // ######################### MODEL OPERATIONS ##############################

        public async Task <bool> RetrieveWateringStation(int stationNumber)
        {
            WateringStation result = new WateringStation();

            try
            {
                result = await App.Database.GetWateringStationAsync(stationNumber);

                if (result != null)
                {
                    this.fullName     = result.fullName;
                    this.guid         = result.guid;
                    this.name         = result.name;
                    this.number       = result.number;
                    this.wateringTime = result.wateringTime;
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }