public async static Task DeleteBarriersAvailable (BarriersAvailable barriersAvailable) { var db = DependencyService.Get<ISQLite> ().GetAsyncConnection (); await db.DeleteAsync (barriersAvailable); }
public BarrierStrategyModal (User selectedUser, BarriersAvailable barrierAvailable, MemberBarriers memberBarrier = null) { InitializeComponent (); _viewModel = new BarrierStrategyViewModel (selectedUser, barrierAvailable, this, memberBarrier); this.BindingContext = _viewModel; }
//private static readonly AsyncLock Mutex = new AsyncLock (); public async static Task SaveBarriersAvailable (BarriersAvailable barriersAvailable) { var db = DependencyService.Get<ISQLite> ().GetAsyncConnection (); await db.CreateTableAsync<BarriersAvailable> (); var currentRecord = await db.Table<BarriersAvailable> ().Where (row => row.BarrierID == barriersAvailable.BarrierID).FirstOrDefaultAsync (); if (currentRecord != null && currentRecord.Id != 0) { await db.UpdateAsync (barriersAvailable); } else { await db.InsertAsync (barriersAvailable); } }
public BarrierStrategyViewModel(User selectedUser, BarriersAvailable barrierAvailable, Page page, MemberBarriers memberBarrier = null) { SelectedUser = selectedUser; BarrierAvailableProperty = barrierAvailable; PageProperty = page; if (memberBarrier == null) { BarrierName = barrierAvailable.BarrierIDTitle; memberBarrier = new MemberBarriers (); memberBarrier.BarrierDisplayValue = BarrierAvailableProperty.BarrierIDTitle; memberBarrier.BarrierID = BarrierAvailableProperty.BarrierID; memberBarrier.ProfileID = selectedUser.ProfileID; } else { BarrierName = memberBarrier.BarrierDisplayValue; } MemberBarrier = memberBarrier; }
public void Display (string body, string title, BarriersAvailable barrierAvailable, string cancelButtonTitle, string acceptButtonTitle = "", Action<BarriersAvailable, string> action = null) { UIAlertView alert = new UIAlertView(); alert.Title = title; alert.AddButton(acceptButtonTitle); alert.AddButton(cancelButtonTitle); alert.Message = body; alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput; var textField = alert.GetTextField (0); CGRect frameRect = textField.Frame; CGSize size = new CGSize (150, 60); frameRect.Size = size; textField.Frame = frameRect; alert.Clicked += (object s, UIButtonEventArgs ev) => { if(action != null) { if(ev.ButtonIndex ==0) { string input = alert.GetTextField(0).Text; action.Invoke(barrierAvailable, input); } } }; alert.Show(); // UIAlertController alert = UIAlertController.Create (title, body, UIAlertControllerStyle.Alert); // // alert.AddAction (UIAlertAction.Create (acceptButtonTitle, UIAlertActionStyle.Default, action2 => { // //SendComment(alert.TextFields[0].Text); // string input = alert.TextFields[0].Text; // action.Invoke(barrierAvailable, input); // })); // // alert.AddAction (UIAlertAction.Create (cancelButtonTitle, UIAlertActionStyle.Cancel, null)); // alert.AddTextField ((field) => { // field.Placeholder = title; // }); // // alert. }
public mpBarriersViewModel(User selectedUser) { SelectedUser = selectedUser; //get the Member Image if (SelectedUser.ImageURL == null || SelectedUser.ImageURL == "") { MemberImage = "memberpic.png"; } else { MemberImage = SelectedUser.ImageURL; } AvailableBarriersList = new ObservableCollection<BarriersAvailable>(); MemberBarriersList = new ObservableCollection<MemberBarriers>(); if (CrossConnectivity.Current.IsConnected) { Task.Run(async () => { var availableBarriersListAPI = await CoachServices.GetAvailableBarriers(); var memberBarriersListAPI = await CoachServices.GetMemberBarriers(SelectedUser.ProfileID); //If available barriers returned from the API delete all barriers from local database if (availableBarriersListAPI.Count() > 0) { var barriersAvailableToDeleteDB = await BarriersAvailableDAL.GetBarriersAvailable(); foreach (var barrierToDelete in barriersAvailableToDeleteDB) { await BarriersAvailableDAL.DeleteBarriersAvailable(barrierToDelete); } } //If member barriers returned from the API delete all barriers from local database if (memberBarriersListAPI.Count() > 0) { var memberBarriersToDeleteDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID); foreach (var barrierToDelete in memberBarriersToDeleteDB) { if (!barrierToDelete.IsSoftDeleted) { await MemberBarriersDAL.DeleteMemberBarriers(barrierToDelete); } } } foreach (var availablebarrierDTO in availableBarriersListAPI) { BarriersAvailable availableBarrier = new BarriersAvailable(); availableBarrier.BarrierID = availablebarrierDTO.BarrierID; availableBarrier.BarrierIDTitle = availablebarrierDTO.BarrierIDTitle; await BarriersAvailableDAL.SaveBarriersAvailable(availableBarrier); } var barriersAvailableDB = await BarriersAvailableDAL.GetBarriersAvailable(); AvailableBarriersList = new ObservableCollection<BarriersAvailable>(barriersAvailableDB); foreach (var memberBarrierDTO in memberBarriersListAPI) { MemberBarriers memberBarrier = new MemberBarriers(); //Start here memberBarrier.BarrierID = memberBarrierDTO.BarrierID; memberBarrier.BarrierSetDate = memberBarrierDTO.BarrierSetDate; memberBarrier.BarrierValue = memberBarrierDTO.BarrierValue; string barrierName = AvailableBarriersList.First(row => row.BarrierID == memberBarrier.BarrierID).BarrierIDTitle; memberBarrier.BarrierDisplayValue = barrierName; memberBarrier.MemberBarrierValueID = memberBarrierDTO.MemberBarrierValueID; memberBarrier.ProfileID = memberBarrierDTO.ProfileID; await MemberBarriersDAL.SaveMemberBarriers(memberBarrier); } }); } else { DependencyService.Get<ICustomDialog>().Display("You are not connected to a network. The displayed data might not be up to date.", "OK"); Task.Run(async () => { var barriersAvailableDB = await BarriersAvailableDAL.GetBarriersAvailable(); AvailableBarriersList = new ObservableCollection<BarriersAvailable>(barriersAvailableDB); var memberBarriersDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID); MemberBarriersList = new ObservableCollection<MemberBarriers>(memberBarriersDB); }); } }