Skip to content

Commit f598e76

Browse files
committed
feat(*.cs & *.xaml): Add currency selection to debt offer and update video text
Introduces a currency selection ComboBox for new debt offers, passing the selected BaseCurrencyType through the view model and service layers. Updates the video commitment text to use the selected currency and English language, and improves error handling in the video recorder. Also enhances lender and borrower info display in the debt details view.
1 parent 8c2690d commit f598e76

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

FinTrack/Services/Debts/DebtStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public async Task LoadDebtsAsync()
115115
}
116116
}
117117

118-
public async Task SendOfferAsync(string borrowerEmail, decimal amount, string currency, DateTime dueDate, string description)
118+
public async Task SendOfferAsync(string borrowerEmail, decimal amount, BaseCurrencyType currency, DateTime dueDate, string description)
119119
{
120120
IsLoading = true;
121121
try
@@ -124,7 +124,7 @@ public async Task SendOfferAsync(string borrowerEmail, decimal amount, string cu
124124
{
125125
BorrowerEmail = borrowerEmail,
126126
Amount = amount,
127-
CurrencyCode = BaseCurrencyType.TRY,
127+
CurrencyCode = currency,
128128
DueDateUtc = dueDate.ToUniversalTime(),
129129
Description = description
130130
};

FinTrack/Services/Debts/IDebtStore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FinTrackForWindows.Models.Debt;
1+
using FinTrackForWindows.Enums;
2+
using FinTrackForWindows.Models.Debt;
23
using System.Collections.ObjectModel;
34
using System.IO;
45

@@ -13,7 +14,7 @@ public interface IDebtStore
1314
bool IsLoading { get; }
1415

1516
Task LoadDebtsAsync();
16-
Task SendOfferAsync(string borrowerEmail, decimal amount, string currency, DateTime dueDate, string description);
17+
Task SendOfferAsync(string borrowerEmail, decimal amount, BaseCurrencyType currency, DateTime dueDate, string description);
1718
Task RespondToOfferAsync(DebtModel debt, bool accepted);
1819
Task UploadVideoAsync(DebtModel debt, string filePath);
1920

FinTrack/ViewModels/DebtViewModel.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.Input;
3+
using FinTrackForWindows.Enums;
34
using FinTrackForWindows.Models.Debt;
45
using FinTrackForWindows.Services.AppInNotifications;
56
using FinTrackForWindows.Services.Camera;
67
using FinTrackForWindows.Services.Debts;
78
using FinTrackForWindows.Views;
89
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Logging;
11+
using System.Collections.ObjectModel;
1012
using System.IO;
1113
using System.Windows;
1214

@@ -29,6 +31,11 @@ public partial class DebtViewModel : ObservableObject
2931
[ObservableProperty]
3032
private decimal newProposalAmount;
3133

34+
[ObservableProperty]
35+
private BaseCurrencyType newCurrencyType;
36+
37+
public ObservableCollection<BaseCurrencyType> CurrencyTypes { get; }
38+
3239
[ObservableProperty]
3340
private string? newProposalDescription;
3441

@@ -44,6 +51,8 @@ public DebtViewModel(ILogger<DebtViewModel> logger,
4451
_debtStore = debtStore;
4552
_serviceProvider = serviceProvider;
4653
_appInNotificationService = appInNotificationService;
54+
55+
CurrencyTypes = new ObservableCollection<BaseCurrencyType>(Enum.GetValues(typeof(BaseCurrencyType)).Cast<BaseCurrencyType>());
4756
}
4857

4958
[RelayCommand]
@@ -57,7 +66,7 @@ private async Task SendOfferAsync()
5766

5867
try
5968
{
60-
await _debtStore.SendOfferAsync(NewProposalBorrowerEmail, NewProposalAmount, "TRY", NewProposalDueDate, NewProposalDescription);
69+
await _debtStore.SendOfferAsync(NewProposalBorrowerEmail, NewProposalAmount, NewCurrencyType, NewProposalDueDate, NewProposalDescription);
6170

6271
NewProposalBorrowerEmail = string.Empty;
6372
NewProposalAmount = 0;
@@ -119,7 +128,7 @@ private async Task UploadVideoAsync(DebtModel? debt)
119128
}
120129
};
121130

122-
var videoRecorderViewModel = new VideoRecorderViewModel(debt, cameraService, closeAction);
131+
var videoRecorderViewModel = new VideoRecorderViewModel(debt, cameraService, closeAction, _logger, _appInNotificationService);
123132
var videoRecorderWindow = new VideoRecorderWindow
124133
{
125134
DataContext = videoRecorderViewModel
@@ -142,7 +151,6 @@ private async Task UploadVideoAsync(DebtModel? debt)
142151
}
143152
finally
144153
{
145-
// Delete the temporary file whether upload succeeded or failed.
146154
try
147155
{
148156
File.Delete(videoPathToProcess);
@@ -157,7 +165,6 @@ private async Task UploadVideoAsync(DebtModel? debt)
157165
}
158166
else if (!string.IsNullOrEmpty(videoPathToProcess))
159167
{
160-
// If user canceled, delete the temporary file.
161168
try
162169
{
163170
File.Delete(videoPathToProcess);

FinTrack/ViewModels/VideoRecorderViewModel.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.Input;
33
using FinTrackForWindows.Models.Debt;
4+
using FinTrackForWindows.Services.AppInNotifications;
45
using FinTrackForWindows.Services.Camera;
6+
using Microsoft.Extensions.Logging;
57
using System.Windows.Media.Imaging;
68

79
namespace FinTrackForWindows.ViewModels
@@ -26,20 +28,31 @@ public partial class VideoRecorderViewModel : ObservableObject
2628
public string RecordButtonText => IsRecording ? "Stop Recording" : "Start Recording";
2729
public string CommitmentText { get; }
2830

29-
public VideoRecorderViewModel(DebtModel debt, ICameraService cameraService, Action<bool, string?> closeWindowAction)
31+
private readonly ILogger<DebtViewModel> _logger;
32+
private readonly IAppInNotificationService _appInNotificationService;
33+
34+
public VideoRecorderViewModel(DebtModel debt,
35+
ICameraService cameraService,
36+
Action<bool, string?> closeWindowAction,
37+
ILogger<DebtViewModel> logger,
38+
IAppInNotificationService appInNotificationService)
3039
{
3140
_cameraService = cameraService;
3241
_closeWindowAction = closeWindowAction;
3342

34-
CommitmentText = $"Ben, {debt.BorrowerName}, {debt.LenderName} kişisinden {DateTime.UtcNow:dd.MM.yyyy} tarihinde almış olduğum {debt.Amount:N2} TRY tutarındaki borcu, " +
35-
$"en geç {debt.DueDate:dd.MM.yyyy} tarihinde ödemeyi taahhüt ediyorum. Eğer borcu belirtilen zamanda ve miktarda geri ödemezsem, " +
36-
$"bu video kaydının borç veren {debt.LenderName} kişisinin erişimine açılacağını ve yasal delil olarak kullanılabileceğini kabul ediyorum.";
43+
_logger = logger;
44+
_appInNotificationService = appInNotificationService;
45+
46+
CommitmentText = $"I, {debt.BorrowerName}, acknowledge that I have received a loan in the amount of {debt.Amount:N2} {debt.Currency} from {debt.LenderName} on {DateTime.UtcNow:dd.MM.yyyy}. " +
47+
$"I undertake to make the payment no later than {debt.DueDate:dd.MM.yyyy}. If I fail to repay the debt in the specified amount and on the specified date, " +
48+
$"I acknowledge that this video recording will be made available to the lender {debt.LenderName} and may be used as legal evidence.";
3749

3850
_cameraService.OnFrameReady = (frame) => CameraFrame = frame;
3951

4052
if (!_cameraService.InitializeCamera())
4153
{
42-
// TODO: Show a user-friendly error message.
54+
_logger.LogError("There was a problem while recording the video.");
55+
_appInNotificationService.ShowError("There was a problem while recording the video.");
4356
_closeWindowAction(false, null);
4457
}
4558
}
@@ -78,7 +91,6 @@ private void Cancel()
7891
[RelayCommand]
7992
private void Cleanup()
8093
{
81-
// Bu metot, pencere kapandığında çağrılır.
8294
_cameraService.Release();
8395
}
8496
}

FinTrack/Views/DebtView.xaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<UserControl.Resources>
1616
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
17+
<helpers:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter"/>
1718
<helpers:ObjectArrayConverter x:Key="ObjectArrayConverter"/>
1819
<helpers:VideoStatusConverter x:Key="VideoStatusConverter"/>
1920
<sys:Boolean x:Key="TrueBoolean">True</sys:Boolean>
@@ -44,6 +45,15 @@
4445
<TextBox Style="{StaticResource ModernTextBoxStyle}" Text="{Binding NewProposalDescription, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,15" MinHeight="60" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto"/>
4546
<TextBlock Text="AMOUNT OF DEBT" Style="{StaticResource LabelTextStyle}"/>
4647
<TextBox Style="{StaticResource ModernTextBoxStyle}" Text="{Binding NewProposalAmount, UpdateSourceTrigger=PropertyChanged, StringFormat=N2}" Margin="0,0,0,15"/>
48+
<TextBlock Text="CURRENCY" Style="{StaticResource LabelTextStyle}"/>
49+
<ComboBox SelectedIndex="0" Style="{StaticResource ModernComboBoxStyle}" Margin="0,0,0,15"
50+
ItemsSource="{Binding CurrencyTypes}" SelectedItem="{Binding NewCurrencyType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
51+
<ComboBox.ItemTemplate>
52+
<DataTemplate>
53+
<TextBlock Text="{Binding Converter={StaticResource EnumToDescriptionConverter}}"/>
54+
</DataTemplate>
55+
</ComboBox.ItemTemplate>
56+
</ComboBox>
4757
<TextBlock Text="FINAL PAYMENT DATE" Style="{StaticResource LabelTextStyle}"/>
4858
<DatePicker SelectedDate="{Binding NewProposalDueDate}" Style="{StaticResource ModernDatePickerStyle}" Margin="0,0,0,25"/>
4959
<Button Content="SEND OFFER" Style="{StaticResource PrimaryButtonStyle}" Command="{Binding SendOfferCommand}"/>
@@ -164,8 +174,15 @@
164174
</Border.Background>
165175
</Border>
166176
<StackPanel VerticalAlignment="Center" Margin="10,0,0,0">
167-
<TextBlock Text="{Binding LenderName}" Style="{StaticResource DetailValueTextStyle}"/>
168-
<TextBlock Text="{Binding LenderEmail}" Style="{StaticResource DetailLabelTextStyle}"/>
177+
<TextBlock Text="LENDER" Foreground="Green" FontWeight="Bold"/>
178+
<TextBlock Style="{StaticResource DetailValueTextStyle}">
179+
<Run Text="UserName: " FontWeight="Bold"/>
180+
<Run Text="{Binding LenderName}"/>
181+
</TextBlock>
182+
<TextBlock Style="{StaticResource DetailLabelTextStyle}">
183+
<Run Text="Email: " FontWeight="Bold"/>
184+
<Run Text="{Binding LenderEmail}" />
185+
</TextBlock>
169186
</StackPanel>
170187
</StackPanel>
171188
<Separator Grid.Column="1" Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="15,0"/>
@@ -176,8 +193,15 @@
176193
</Border.Background>
177194
</Border>
178195
<StackPanel VerticalAlignment="Center" Margin="10,0,0,0">
179-
<TextBlock Text="{Binding BorrowerName}" Style="{StaticResource DetailValueTextStyle}"/>
180-
<TextBlock Text="{Binding BorrowerEmail}" Style="{StaticResource DetailLabelTextStyle}"/>
196+
<TextBlock Text="BORROWER" Foreground="Red" FontWeight="Bold"/>
197+
<TextBlock Style="{StaticResource DetailValueTextStyle}">
198+
<Run Text="UserName: " FontWeight="Bold"/>
199+
<Run Text="{Binding BorrowerName}"/>
200+
</TextBlock>
201+
<TextBlock Style="{StaticResource DetailLabelTextStyle}">
202+
<Run Text="Email: " FontWeight="Bold"/>
203+
<Run Text="{Binding BorrowerEmail}" />
204+
</TextBlock>
181205
</StackPanel>
182206
</StackPanel>
183207
</Grid>

0 commit comments

Comments
 (0)