/// <summary> /// Deletes an expense report /// </summary> public Task DeleteExpenseAsync (Assignment assignment, Expense expense) { return service.DeleteExpenseAsync (expense) .ContinueWith (t => { expenses.Remove (expense); CalculateExpenses (assignment); }); }
/// <summary> /// Saves an expense report /// </summary> public Task SaveExpenseAsync (Assignment assignment, Expense expense) { bool newItem = expense.Id == 0; return service.SaveExpenseAsync (expense) .ContinueWith (t => { if (newItem) expenses.Add (expense); CalculateExpenses (assignment); }); }
/// <summary> /// Sets the labor hours on this cell /// </summary> public void SetExpense (Expense expense) { type.Text = expense.Category.ToString (); description.Text = expense.Description; cost.Text = expense.Cost.ToString ("$0.00"); if (!expense.HasPhoto) { icon.Hidden = true; } else { icon.Hidden = false; icon.Image = Theme.Camera; } type.TextColor = description.TextColor = cost.TextColor = Theme.LabelColor; type.HighlightedTextColor = description.HighlightedTextColor = cost.HighlightedTextColor = Theme.LabelColor; }
/// <summary> /// Loads the photo for an expense /// </summary> public Task LoadPhotoAsync (Expense expense) { return service .GetExpensePhotoAsync (expense) .ContinueOnCurrentThread (t => Photo = t.Result); }
public override void OnDetachedFromWindow() { base.OnDetachedFromWindow (); base.OnDetachedFromWindow (); expensePhoto.SetImageBitmap (null); if (imageBitmap != null) { imageBitmap.Recycle (); imageBitmap.Dispose (); imageBitmap = null; } Assignment = null; CurrentExpense = null; }
public Task<int> DeleteExpenseAsync (Expense expense, CancellationToken cancellationToken) { return Task.Factory.StartNew (() => 1); }
public Task<ExpensePhoto> GetExpensePhotoAsync (Expense expense, CancellationToken cancellationToken) { return Task.Factory.StartNew (() => new ExpensePhoto { ExpenseId = expense.Id }); }
public Task<ExpensePhoto> GetExpensePhotoAsync (Expense expense, CancellationToken cancellationToken = default(CancellationToken)) { return Database.GetConnection (cancellationToken).Table<ExpensePhoto> ().Where (p => p.ExpenseId == expense.Id).FirstOrDefaultAsync (); }
public void DeleteExpense () { var expense = new Expense (); expense.Description = "New Description"; var saveTask = service.SaveExpenseAsync (expense, CancellationToken.None); saveTask.Wait (); var deleteTask = service.DeleteExpenseAsync (expense, CancellationToken.None); deleteTask.Wait (); Assert.That (deleteTask.Result, Is.EqualTo (1)); }
public Task<int> DeleteExpenseAsync (Expense expense, CancellationToken cancellationToken = default(CancellationToken)) { return Database.GetConnection (cancellationToken).DeleteAsync (expense); }
public Task<int> SaveExpenseAsync (Expense expense, CancellationToken cancellationToken = default(CancellationToken)) { if (expense.Id == 0) return Database.GetConnection (cancellationToken).InsertAsync (expense); else return Database.GetConnection (cancellationToken).UpdateAsync (expense); }
public Task <ExpensePhoto> GetExpensePhotoAsync(Expense expense, CancellationToken cancellationToken = default(CancellationToken)) { return(Database.GetConnection(cancellationToken).Table <ExpensePhoto> ().Where(p => p.ExpenseId == expense.Id).FirstOrDefaultAsync()); }
public Task <int> DeleteExpenseAsync(Expense expense, CancellationToken cancellationToken = default(CancellationToken)) { return(Database.GetConnection(cancellationToken).DeleteAsync(expense)); }
public ExpenseViewModel () { picker = new MediaPicker (); assignmentViewModel = ServiceContainer.Resolve<AssignmentViewModel>(); addExpenseCommand = new DelegateCommand (async obj => { var expense = obj as Expense; if (expense != null) { SelectedExpense = expense; CanDelete = true; AddExpenseHeader = "Expense"; await LoadPhotoAsync (expense); } else { SelectedExpense = new Expense (); CanDelete = false; AddExpenseHeader = "Add Expense"; Photo = new ExpensePhoto (); } if (addExpensePopUp != null && addExpensePopUp.IsOpen) { addExpensePopUp.IsOpen = false; } addExpensePopUp = new Popup (); addExpensePopUp.Height = Window.Current.Bounds.Height; addExpensePopUp.Width = Constants.PopUpWidth; AddExpenseFlyoutPanel flyoutpanel = new AddExpenseFlyoutPanel (); flyoutpanel.Width = addExpensePopUp.Width; flyoutpanel.Height = addExpensePopUp.Height; addExpensePopUp.Child = flyoutpanel; addExpensePopUp.SetValue (Canvas.LeftProperty, Window.Current.Bounds.Width - Constants.PopUpWidth); addExpensePopUp.SetValue (Canvas.TopProperty, 0); addExpensePopUp.IsOpen = true; }); saveExpenseCommand = new DelegateCommand (async _ => { selectedExpense.Cost = ExpenseCost.ToDecimal (CultureInfo.InvariantCulture); selectedExpense.AssignmentId = assignmentViewModel.SelectedAssignment.Id; var task = SaveExpenseAsync (assignmentViewModel.SelectedAssignment, SelectedExpense); if (Photo !=null && Photo.Image != null) { task = task.ContinueWith (obj => { Photo.ExpenseId = SelectedExpense.Id; }); await SavePhotoAsync (); } await LoadExpensesAsync (assignmentViewModel.SelectedAssignment); addExpensePopUp.IsOpen = false; }); deleteExpenseCommand = new DelegateCommand (async _ => { await DeleteExpenseAsync (assignmentViewModel.SelectedAssignment, selectedExpense); await LoadExpensesAsync (assignmentViewModel.SelectedAssignment); addExpensePopUp.IsOpen = false; }); cancelExpenseCommand = new DelegateCommand (_ => { addExpensePopUp.IsOpen = false; }); addImageCommand = new DelegateCommand (async _ => { bool cameraCommand = false, imageCommand = false; var dialog = new MessageDialog ("Take picture with your built in camera or select one from your photo library.", "Add Image"); if (picker.IsCameraAvailable) { dialog.Commands.Add (new UICommand ("Camera", new UICommandInvokedHandler (q => cameraCommand = true))); } dialog.Commands.Add (new UICommand ("Library", new UICommandInvokedHandler (q => imageCommand = true))); await dialog.ShowAsync (); if (cameraCommand) { try { var mediaFile = await picker.TakePhotoAsync (new StoreCameraMediaOptions ()); var photo = await mediaFile.GetStream ().LoadBytes (); if (Photo == null) Photo = new ExpensePhoto { ExpenseId = SelectedExpense.Id }; Photo.Image = photo; OnPropertyChanged ("Photo"); } catch (Exception exc) { Debug.WriteLine (exc.Message); //this could happen if they cancel, etc. } } else if (imageCommand) { try { var mediaFile = await picker.PickPhotoAsync (); var photo = await mediaFile.GetStream ().LoadBytes (); if (Photo == null) Photo = new ExpensePhoto { ExpenseId = SelectedExpense.Id }; Photo.Image = photo; OnPropertyChanged ("Photo"); } catch (Exception exc) { Debug.WriteLine (exc.Message); //this could happen if they cancel, etc. } } }); }