Skip to content

Commit

Permalink
try to fix display account name in edit transactions picker
Browse files Browse the repository at this point in the history
  • Loading branch information
gwalus committed May 27, 2024
1 parent c198243 commit 7251fad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@
<Picker
Grid.Row="1"
Title="Select account"
SelectedItem="{Binding SelectedAccount}"
ItemsSource="{Binding Accounts}"
ItemDisplayBinding="{Binding Name}"
SelectedItem="{Binding SelectedAccount}"/>
ItemDisplayBinding="{Binding Name}"/>

<!--<HorizontalStackLayout Grid.Row="1">
<Picker x:Name="Title" ItemsSource="{Binding Accounts}" ItemDisplayBinding="{Binding Name}" Title="Title"/>
--><!--<Entry x:Name="Name" Text="{Binding Source={x:Reference Title}, Path=SelectedItem.Text}" Placeholder="Name"/>--><!--
<Label x:Name="Name" Text="{Binding Source={x:Reference Title}, Path=SelectedItem.Text}"/>
<Label Text="{Binding SelectedAccount.Name}"/>
</HorizontalStackLayout>-->

<Label Grid.Column="1" Text="Date"/>
<DatePicker
Expand Down
5 changes: 5 additions & 0 deletions src/Dollet.Presentation/Maui/ViewModels/Dtos/AccountDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public partial class AccountDto : ObservableObject

[ObservableProperty]
bool isHidden, isDefault;

public override string ToString()
{
return Name;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Dollet.Core.Abstractions;
using Dollet.Core.Entities;
using Dollet.Helpers;
using Dollet.ViewModels.Dtos;

namespace Dollet.ViewModels.Transactions.Expenses
{
Expand All @@ -13,15 +14,15 @@ public partial class EditExpensePageViewModel(IUnitOfWork unitOfWork) : Observab
private readonly IUnitOfWork _unitOfWork = unitOfWork;

private decimal initialAmount;
private Account initialAccount;
private AccountDto initialAccount;

private int id;

[ObservableProperty]
decimal _amount;

[ObservableProperty]
Account _selectedAccount;
AccountDto _selectedAccount;

[ObservableProperty]
Category _selectedCategory;
Expand All @@ -34,7 +35,7 @@ public partial class EditExpensePageViewModel(IUnitOfWork unitOfWork) : Observab

public DateTime MaximumDate { get; } = DateTime.Now;

public ObservableRangeCollection<Account> Accounts { get; } = [];
public ObservableRangeCollection<AccountDto> Accounts { get; } = [];
public ObservableRangeCollection<Category> Categories { get; } = [];

public void ApplyQueryAttributes(IDictionary<string, object> query)
Expand All @@ -45,7 +46,13 @@ public void ApplyQueryAttributes(IDictionary<string, object> query)
Date = (DateTime)query["Date"];
Comment = (string)query["Comment"];

initialAccount = (Account)query["Account"];
var aaa = (Account)query["Account"];

initialAccount = new AccountDto
{
Id = aaa.Id,
Name = aaa.Name
};
initialAmount = (decimal)query["Amount"];
}

Expand All @@ -55,11 +62,22 @@ async Task Appearing()
var accounts = await _unitOfWork.AccountRepository.GetAllAsync();
var categories = await _unitOfWork.CategoryRepository.GetAllAsync();

Accounts.ReplaceRange(accounts);
Accounts.ReplaceRange(accounts.Select(x => new AccountDto { Id = x.Id, Name = x.Name}));
Categories.ReplaceRange(categories);

//var a = new AccountDto
//{
// Name = initialAccount.Name
//};

// Doesn't work because we need to set the SelectedAccount property as Obserbable Property, in dto model
SelectedAccount = initialAccount;
//SelectedAccount = a;

if (SelectedAccount is null)
{

}
}

[RelayCommand]
Expand All @@ -77,7 +95,7 @@ async Task EditExpense()
var expense = await _unitOfWork.ExpensesRepository.GetAsync(id);

expense.Amount = Amount;
expense.Account = selectedAccount;
//expense.Account = selectedAccount;
expense.Category = SelectedCategory;
expense.Date = Date;
expense.Comment = Comment;
Expand Down

0 comments on commit 7251fad

Please sign in to comment.