public void Display (string body, string title, GoalsAvailable availableGoal, string cancelButtonTitle, string acceptButtonTitle = "", Action<GoalsAvailable, int> action = null) { EditText goalTextBox = new EditText (Forms.Context); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder (Forms.Context); alertDialogBuilder.SetTitle (title); alertDialogBuilder.SetMessage (body); alertDialogBuilder.SetView (goalTextBox); goalTextBox.InputType = Android.Text.InputTypes.NumberFlagSigned; var inputFilter = new Android.Text.InputFilterLengthFilter (7); var filters = new Android.Text.IInputFilter[1]; filters [0] = inputFilter; goalTextBox.SetFilters (filters); goalTextBox.InputType = Android.Text.InputTypes.ClassNumber; alertDialogBuilder.SetPositiveButton ("OK", (senderAlert, args) => { if(action != null) { int goalValue; int.TryParse(goalTextBox.Text, out goalValue); action.Invoke(availableGoal, goalValue); } } ); alertDialogBuilder.SetNeutralButton ("CANCEL", (senderAlert, args) => { } ); alertDialogBuilder.Show (); }
public void Display (string body, string title, GoalsAvailable goalAvailable, string cancelButtonTitle, string acceptButtonTitle = "", Action<GoalsAvailable, int> action = null) { UIAlertView alert = new UIAlertView(); alert.Title = title; alert.AddButton(acceptButtonTitle); alert.AddButton(cancelButtonTitle); alert.Message = body; alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput; alert.GetTextField(0).KeyboardType=UIKeyboardType.NumberPad; const int maxCharacters =7; alert.GetTextField(0).ShouldChangeCharacters = (textField, range, replacement) => { var newContent = new NSString(textField.Text).Replace(range, new NSString(replacement)).ToString(); int number; return newContent.Length <= maxCharacters && (replacement.Length == 0 || int.TryParse(replacement, out number)); }; alert.Clicked += (object s, UIButtonEventArgs ev) => { if(action != null) { if(ev.ButtonIndex ==0) { string input = alert.GetTextField(0).Text; int goalValue; int.TryParse(input, out goalValue); action.Invoke(goalAvailable, goalValue); } } }; alert.Show(); }
public async static Task DeleteGoalsAvailable (GoalsAvailable goalsAvailable) { var db = DependencyService.Get<ISQLite> ().GetAsyncConnection (); await db.DeleteAsync (goalsAvailable); }
//private static readonly AsyncLock Mutex = new AsyncLock (); public async static Task SaveGoalsAvailable (GoalsAvailable goalsAvailable) { var db = DependencyService.Get<ISQLite> ().GetAsyncConnection (); await db.CreateTableAsync<GoalsAvailable> (); var currentRecord = await db.Table<GoalsAvailable> ().Where (row => row.GoalID == goalsAvailable.GoalID).FirstOrDefaultAsync (); if (currentRecord != null && currentRecord.Id != 0) { await db.UpdateAsync (goalsAvailable); } else { await db.InsertAsync (goalsAvailable); } }
public mpGoalsViewModel(User selectedUser) { SelectedUser = selectedUser; //get the Member Image if(SelectedUser.ImageURL == null || SelectedUser.ImageURL == ""){ MemberImage = "memberpic.png"; }else{ MemberImage = SelectedUser.ImageURL; } AvailableGoalsList = new ObservableCollection<GoalsAvailable> (); MemberGoalsList = new ObservableCollection<MemberGoals> (); if (CrossConnectivity.Current.IsConnected) { Task.Run (async() => { var availableGoalsListAPI = await CoachServices.GetAvailableGoals (); var memberGoalsListAPI = await CoachServices.GetMemberGoals(SelectedUser.ProfileID); //If available goals returned from the API delete all goals from local database if(availableGoalsListAPI.Count() > 0) { var goalsAvailableToDeleteDB = await GoalsAvailableDAL.GetGoalsAvailable(); foreach(var goalToDelete in goalsAvailableToDeleteDB) { await GoalsAvailableDAL.DeleteGoalsAvailable(goalToDelete); } } //If member goals returned from the API delete all goals from local database if(memberGoalsListAPI.Count() > 0) { var memberGoalsToDeleteDB = await MemberGoalsDAL.GetMemberGoals(SelectedUser.ProfileID); foreach(var goalToDelete in memberGoalsToDeleteDB) { if(!goalToDelete.IsSoftDeleted) { await MemberGoalsDAL.DeleteMemberGoals(goalToDelete); } } } foreach(var availableGoalDTO in availableGoalsListAPI) { GoalsAvailable availableGoal = new GoalsAvailable(); availableGoal.GoalID = availableGoalDTO.GoalID; availableGoal.GoalName = availableGoalDTO.GoalName; await GoalsAvailableDAL.SaveGoalsAvailable(availableGoal); } var goalsAvailableDB = await GoalsAvailableDAL.GetGoalsAvailable(); AvailableGoalsList = new ObservableCollection<GoalsAvailable> (goalsAvailableDB); foreach(var memberGoalDTO in memberGoalsListAPI) { MemberGoals memberGoal = new MemberGoals(); memberGoal.GoalID = memberGoalDTO.GoalID; memberGoal.GoalSetDate = memberGoalDTO.GoalSetDate; memberGoal.GoalValue = memberGoalDTO.GoalValue; memberGoal.MemberGoalValueID = memberGoalDTO.MemberGoalValueID; memberGoal.ProfileID = memberGoalDTO.ProfileID; string goalName = AvailableGoalsList.First(row => row.GoalID == memberGoal.GoalID).GoalName; memberGoal.GoalDisplayValue = memberGoal.GoalValue.ToString() + " " + goalName; await MemberGoalsDAL.SaveMemberGoals(memberGoal); } var memberGoalsDB = await MemberGoalsDAL.GetMemberGoals(SelectedUser.ProfileID); MemberGoalsList = new ObservableCollection<MemberGoals> (memberGoalsDB); }); } 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 goalsAvailableDB = await GoalsAvailableDAL.GetGoalsAvailable(); AvailableGoalsList = new ObservableCollection<GoalsAvailable> (goalsAvailableDB); var memberGoalsDB = await MemberGoalsDAL.GetMemberGoals(SelectedUser.ProfileID); MemberGoalsList = new ObservableCollection<MemberGoals> (memberGoalsDB); }); } }
public async void AddGoal(GoalsAvailable goalAvailable, int goalValue) { List<MemberGoals> memberGoalsDTOList = new List<MemberGoals> (); MemberGoals memberGoalsDTO = new MemberGoals (); memberGoalsDTO.GoalID = goalAvailable.GoalID; memberGoalsDTO.GoalSetDate = DateTime.Now.ToString (); memberGoalsDTO.GoalValue = goalValue; //Insert new goal by assigning value of 0 memberGoalsDTO.MemberGoalValueID = 0; memberGoalsDTO.ProfileID = SelectedUser.ProfileID; memberGoalsDTOList.Add (memberGoalsDTO); if (CrossConnectivity.Current.IsConnected) { var resultList = await CoachServices.SaveMemberGoalsToServer (memberGoalsDTOList); memberGoalsDTO.MemberGoalValueID = resultList [0].MemberGoalValueID; } MemberGoals memberGoal = new MemberGoals (); memberGoal.GoalDisplayValue = goalValue.ToString() + " " + goalAvailable.GoalName; memberGoal.GoalID = memberGoalsDTO.GoalID; memberGoal.GoalSetDate = memberGoalsDTO.GoalSetDate; memberGoal.GoalValue = memberGoalsDTO.GoalValue; memberGoal.MemberGoalValueID = memberGoalsDTO.MemberGoalValueID; memberGoal.ProfileID = memberGoalsDTO.ProfileID; await MemberGoalsDAL.SaveMemberGoals (memberGoal); var memberGoalsDB = await MemberGoalsDAL.GetMemberGoals(SelectedUser.ProfileID); MemberGoalsList = new ObservableCollection<MemberGoals> (memberGoalsDB); MessagingCenter.Send<mpGoalsPage> (Application.Current.MainPage.Navigation.NavigationStack.Last() as mpGoalsPage, "GoalsModified"); }