private async void HasAccess_ts_Toggled(object sender, RoutedEventArgs e) { ToggleSwitch clickedItem = (ToggleSwitch)e.OriginalSource; try { var item = clickedItem.DataContext; if (item.GetType() == typeof(Home)) { await HomeTable.Update(HomeConverter.CreateFrom((Home)item)); } else if (item.GetType() == typeof(Room)) { await RoomTable.Update(RoomConverter.CreateFrom((Room)item)); } else if (item.GetType() == typeof(Device)) { await DeviceTable.Update(DeviceConverter.CreateFrom((Device)item)); } await Shared.Services.Storage.SyncAsync(); } catch (Exception) { } }
private async void UpdateHome() { await HomeTable.Update(HomeConverter.CreateFrom(SelectedHome)); GetHomes(); GetHome(); }
private async Task <bool> GetHome() { IMobileServiceTableQuery <HomeItem> homeQuery; if (MobileService.Client.CurrentUser != null) { if (SelectedHome != null) { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.Id == SelectedHome.Id && homeItem.HasAccess == true && homeItem.UserId == MobileService.Client.CurrentUser.UserId && homeItem.Deleted == false); } else { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.HasAccess == true && homeItem.UserId == MobileService.Client.CurrentUser.UserId && homeItem.Deleted == false); } } else { if (SelectedHome != null) { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.Id == SelectedHome.Id && homeItem.HasAccess == true && homeItem.Deleted == false); } else { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.HasAccess == true && homeItem.Deleted == false); } } await HomeTable.Read(homeQuery); if (HomeTable.HomeItems.Count() != 0) { SelectedHome = Converters.HomeConverter.CreateFrom(HomeTable.HomeItems.ElementAt(0)); } return(true); }
private async void DeleteHome() { SelectedHome.Deleted = true; await HomeTable.Update(HomeConverter.CreateFrom(SelectedHome)); GetHome(); GetHomes(); }
public async void GetUser() { IMobileServiceTableQuery <HomeItem> homeQuery; homeQuery = HomeTable.HomeSyncTable.Where(p => p.HasAccess == true && p.IsPrimary == true); await HomeTable.Read(homeQuery); if (HomeTable.HomeItems.Count() != 0) { //SelectedHome = Converters.HomeConverter.CreateFrom(HomeTable.HomeItems.ElementAt(0)); } }
/// <summary> /// /// </summary> /// <returns></returns> public static async Task <bool> PurgeLocalStoreAsync() { Debug.WriteLine("LocalStore.PurgeLocalStoreAsync - Purging Local Store from device"); if (await HomeTable.PurgeTableAsync() && await RoomTable.PurgeTableAsync() && await DeviceTable.PurgeTableAsync()) { Debug.WriteLine("LocalStore.PurgeLocalStoreAsync - Local Store Purged from device"); return(true); } else { return(false); } }
/// <summary> /// /// </summary> /// <returns></returns> public static async Task <bool> PullLocalStoreAsync() { Debug.WriteLine("LocalStore.PullLocalStoreAsync - Pulling Local Store from server"); if (await HomeTable.PullTableAsync() && await RoomTable.PullTableAsync() && await DeviceTable.PullTableAsync()) { Debug.WriteLine("LocalStore.PullLocalStoreAsync - Local Store pulled sucessfully"); return(true); } else { return(false); } }
public async Task <bool> GetUsers(string homeId) { Homes.Clear(); IMobileServiceTableQuery <HomeItem> homeQuery; homeQuery = HomeTable.HomeSyncTable.Where(p => p.HomeId == homeId); await HomeTable.Read(homeQuery); foreach (HomeItem HomeItem in HomeTable.HomeItems) { Homes.Add(Converters.HomeConverter.CreateFrom(HomeItem)); } return(true); }
private async void AddHome() { HomeItem home = new HomeItem { Name = HomeName, UserName = UserName }; if (MobileService.Client.CurrentUser != null) { home.OwnerId = MobileService.Client.CurrentUser.UserId; home.UserId = MobileService.Client.CurrentUser.UserId; } await HomeTable.Create(home); home.HomeId = HomeTable.HomeItem.Id; await HomeTable.Update(home); SelectedHome = Converters.HomeConverter.CreateFrom(HomeTable.HomeItem); GetHomes(); }
public static async void AddUser(string userID, string homeId) { IMobileServiceTableQuery <HomeItem> homeQuery; homeQuery = HomeTable.HomeSyncTable.Where(p => p.HomeId == homeId); await HomeTable.Read(homeQuery); foreach (HomeItem HomeItem in HomeTable.HomeItems) { HomeItem.UserId = userID; HomeItem.UserName = "******"; HomeItem.Id = null; await HomeTable.Create(HomeItem); IMobileServiceTableQuery <RoomItem> roomQuery; roomQuery = RoomTable.RoomSyncTable.Where(p => p.HomeId == homeId); await RoomTable.Read(roomQuery); foreach (RoomItem RoomItem in RoomTable.RoomItems) { RoomItem.UserId = userID; string roomId = RoomItem.Id; RoomItem.Id = null; RoomItem.HomeId = HomeTable.HomeItem.Id; await RoomTable.Create(RoomItem); IMobileServiceTableQuery <DeviceItem> deviceQuery; deviceQuery = DeviceTable.deviceTable.Where(p => p.RoomId == roomId); await DeviceTable.Read(deviceQuery); foreach (DeviceItem DeviceItem in DeviceTable.deviceItems) { DeviceItem.UserId = userID; DeviceItem.Id = null; DeviceItem.RoomId = RoomTable.RoomItem.Id; await DeviceTable.Create(DeviceItem); } } } }
private async Task <bool> GetHomes() { Homes.Clear(); IMobileServiceTableQuery <HomeItem> homeQuery; if (MobileService.Client.CurrentUser != null) { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.HasAccess == true && homeItem.UserId == MobileService.Client.CurrentUser.UserId && homeItem.Deleted == false); } else { homeQuery = HomeTable.HomeSyncTable.Where(homeItem => homeItem.HasAccess == true && homeItem.Deleted == false); } await HomeTable.Read(homeQuery); if (HomeTable.HomeItems.Count() != 0) { foreach (HomeItem HomeItem in HomeTable.HomeItems) { Homes.Add(Converters.HomeConverter.CreateFrom(HomeItem)); } } return(true); }
public static async Task <bool> CreateSampleHome(string homeName = "Railway House") { Home home = new Home { CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, OwnerId = "sid:79cb2d8a9896fd48bac1f3969a9965cc", UserId = "sid:79cb2d8a9896fd48bac1f3969a9965cc", HomeId = "", HasAccess = true, Name = homeName, IsPrimary = true, BackgroundUri = "ms-appx:///Leaf.Shared/Images/DefaultHomeBackground.jpg", BackgroundOpacity = 0.5, BackgroundBlur = 20, IsLocationAvailable = false, Location = "Castleconell", UserName = "******", Deleted = false }; HomeItem item = HomeConverter.CreateFrom(home); await HomeTable.Create(item); item.HomeId = HomeTable.HomeItem.Id; await HomeTable.Update(item); //Home hom = (Home)home; //Home Home = new Home(); //{ // Id = "0001", // CreatedAt = "", // UpdatedAt = "", // Version = "", // OwnerId = "", // UserId = "", // HomeId = "", // Name = homeName, // IsPrimary = true, // Background = new Background // { // Uri = "ms-appx:///Leaf.Shared/Images/DefaultHomeBackground.jpg", // Opacity = 0.4, // Blur = 50 // }, // Location = new Location // { // IsLocationAvailable = true, // Address = "Castleconnell" // }, // Rooms = new ObservableCollection<Room>() //}; //Room Room = CreateSampleRoom("0001", "Living Room"); //Home.Rooms.Add(Room); //Room = CreateSampleRoom("0002", "Kitchen"); //Home.Rooms.Add(Room); //Room = CreateSampleRoom("0003", "Bedroom"); //Home.Rooms.Add(Room); //Room = CreateSampleRoom("0004", "Office"); //Home.Rooms.Add(Room); //Room = CreateSampleRoom("0004", "Bathroom"); //Home.Rooms.Add(Room); return(true); }