/// <summary> /// Löscht einen Trainingsplan aus der lokalen DB /// </summary> /// <param name="data">Schedule</param> /// <param name="path">SQLite Connection String</param> /// <returns>1 -> Delete</returns> /// <returns>-1 -> Exception</returns> public async Task<int> deleteSchedule(Schedule data) { try { var db = new SQLiteAsyncConnection(path); await db.DeleteAsync(data); return 1; } catch (SQLiteException ex) { Console.WriteLine(ex.Message); return -1; } }
/// <summary> /// Gibt alle Trainingspläne eines Benutzers zurück /// </summary> /// <returns></returns> public async Task<IEnumerable<ScheduleModel>> GetAllSchedulesAsync(Guid userID = new Guid()) { if (Online) { try { IEnumerable<ScheduleModel> schedules = await mgnService.GetAllSchedulesAsync().ConfigureAwait(continueOnCapturedContext: false); if(schedules != null) { foreach (var item in schedules) { Schedule s = new Schedule(); s.Id = item.Id; s.Name = item.Name; s.UserId = item.UserId; s.Url = item.Url; s.WasOffline = false; db.insertUpdateSchedule(s); foreach (var data in item.Exercises) { bool a = db.InsertScheduleHasExercises(item.Id, data.Id, false); } } return schedules; } return null; } catch (ServerException ex) { System.Console.WriteLine("Fehler beim Abrufen der Trainingspläne: " + ex.StackTrace); throw; } } else { try { //Alle Trainingspläne für den User zurückgeben IEnumerable<Schedule> schedules = db.GetAllSchedules(userID); List<ScheduleModel> resultSchedules = new List<ScheduleModel>(); if(schedules != null) { foreach (var schedule in schedules) { ScheduleModel temp = new ScheduleModel(); temp.Id = schedule.Id; temp.UserId = schedule.UserId; temp.Name = schedule.Name; temp.Url = schedule.Url; resultSchedules.Add(temp); } return resultSchedules; } return null; } catch (Exception exc) { System.Console.WriteLine("Fehler beim lokalen Abrufen der Trainingspläne: " + exc.StackTrace); return null; } } }
/* /// <summary> /// Gibt für die Methode OnOffService.checkSync() alle User zurück, die im Offline-Modus angelegt wurden /// </summary> /// <returns></returns> public IEnumerable<User> getOfflineUser() { List<User> result = null; try { var db = new SQLiteConnection(path); result = db.Query<User>("Select * From User Where wasOffline=?", true); } catch (SQLiteException ex) { Console.WriteLine(ex.Message); } return result; }*/ #endregion #region Schedule /// <summary> /// Speichert oder updatet einen Trainingsplan in der lokalen DB /// </summary> /// <param name="data">Schedule</param> /// <param name="path">SQLite Connection String</param> /// <returns>0 -> Update</returns> /// <returns>1 -> Insert</returns> /// <returns>-1 -> Exception</returns> public int insertUpdateSchedule(Schedule data) { SQLiteConnection db; List<Schedule> tempList; Schedule temp; try { db = new SQLiteConnection(path); tempList = db.Query<Schedule>("Select * From Schedule Where Id=?", data.Id); if(tempList.Count != 0) { temp = tempList.First<Schedule>(); //Bei temp alles updaten außer Id und LocalId und dann ein Update darauf fahren temp.Name = data.Name; temp.Url = data.Url; temp.UserId = data.UserId; temp.WasOffline = false; db.Update(temp); return 0; } db.Insert(data); return 1; } catch (SQLiteException ex) { Console.WriteLine(ex.Message); return -1; } }