Skip to content

Commit

Permalink
feat: some changes
Browse files Browse the repository at this point in the history
Signed-off-by: russkyc <[email protected]>
  • Loading branch information
russkyc committed Jun 20, 2023
1 parent 3bf6c9c commit baa8210
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Models/Entities/CustomerContactInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GroomWise.Models.Entities;

public class CustomerContactInfo
public record CustomerContactInfo
{
public int CustomerId { get; set; }
public int ContactInfoId { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions Russkyc.GroomWise/Models/Interfaces/Service/IDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IDbContext
CustomerAddressRepository CustomerAddressRepository { get; }
CustomerPetRepository CustomerPetRepository { get; }
CustomerRepository CustomerRepository { get; }
ContactInfoRepository ContactInfoRepository { get; }
CustomerContactInfoRepository CustomerContactInfoRepository { get; }
EmployeeAccountRepository EmployeeAccountRepository { get; }
EmployeeAddressRepository EmployeeAddressRepository { get; }
EmployeeRepository EmployeeRepository { get; }
Expand Down
2 changes: 2 additions & 0 deletions Russkyc.GroomWise/Services/Data/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public void SaveChanges()
_appointmentRepository?.WriteToDb();
_appointmentServiceProductRepository?.WriteToDb();
_appointmentServiceRepository?.WriteToDb();
_contactInfoRepository?.WriteToDb();
_customerContactInfoRepository?.WriteToDb();
_customerAddressRepository?.WriteToDb();
_customerPetRepository?.WriteToDb();
_customerRepository?.WriteToDb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GroomWise.Services.Repository;

public class CustomerContactInfoRepository : Repository<ContactInfo>
public class CustomerContactInfoRepository : Repository<CustomerContactInfo>
{
public CustomerContactInfoRepository(IDatabaseServiceAsync databaseService)
: base(databaseService) { }
Expand Down
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Services/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static IServicesContainer ConfigureServices()
.AddSingleton<IMainViewModel, MainViewModel>()
// Add Views
.AddTransient<IAddAppointmentsView, AddAppointmentsView>()
.AddTransient<IAddCustomersView, AddCustomersView>()
.AddSingleton<IAppointmentsView, AppointmentsView>()
.AddSingleton<IInventoryView, InventoryView>()
.AddTransient<IAddCustomersView, AddCustomersView>()
.AddSingleton<ICustomersView, CustomersView>()
.AddSingleton<IDashboardView, DashboardView>()
.AddSingleton<IEmployeesView, EmployeesView>()
Expand Down
75 changes: 67 additions & 8 deletions Russkyc.GroomWise/ViewModels/Customers/AddCustomersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public partial class AddCustomersViewModel : ViewModelBase, IAddCustomersViewMod
{
private readonly ILogger _logger;
private readonly IDbContext _dbContext;
private readonly IFactory<Customer> _customerFactory;
private readonly IFactory<DialogView> _dialogFactory;

[ObservableProperty]
private string _firstName;
Expand All @@ -20,23 +22,80 @@ public partial class AddCustomersViewModel : ViewModelBase, IAddCustomersViewMod
private string _lastName;

[ObservableProperty]
private string _province;
private string _primaryAddress;

[ObservableProperty]
private string _city;
private string _secondaryAddress;

[ObservableProperty]
private string _barangay;
private string _contactNumber;

[ObservableProperty]
private string _houseNumber;
private string _email;

[ObservableProperty]
private string _zipCode;

public AddCustomersViewModel(ILogger logger, IDbContext dbContext)
public AddCustomersViewModel(
ILogger logger,
IDbContext dbContext,
IFactory<DialogView> dialogFactory,
IFactory<Customer> customerFactory
)
{
_logger = logger;
_dbContext = dbContext;
_dialogFactory = dialogFactory;
_customerFactory = customerFactory;
}

[RelayCommand]
void AddCustomer()
{
var customerId = _dbContext.CustomerRepository.GetLastId().Increment();
var customer = _customerFactory.Create(customer =>
{
customer.Id = customerId;
customer.FirstName = FirstName;
customer.MiddleName = MiddleName;
customer.LastName = LastName;
});
var addressId = _dbContext.AddressRepository.GetLastId().Increment();
var address = new Address
{
Id = addressId,
PrimaryAddress = PrimaryAddress,
SecondaryAddress = SecondaryAddress
};
var customerAddress = new CustomerAddress
{
CustomerId = customerId,
AddressId = addressId
};
var contactInfoId = _dbContext.ContactInfoRepository.GetLastId().Increment();
var contactInfo = new ContactInfo
{
Id = contactInfoId,
ContactNumber = ContactNumber,
Email = Email
};

var customerContactInfo = new CustomerContactInfo();

_dbContext.CustomerRepository.Add(customer);
_dbContext.AddressRepository.Add(address);
_dbContext.CustomerAddressRepository.Add(customerAddress);
_dbContext.ContactInfoRepository.Add(contactInfo);
_dbContext.CustomerContactInfoRepository.Add(customerContactInfo);

ClearFields();
}

void ClearFields()
{
FirstName = string.Empty;
MiddleName = string.Empty;
LastName = string.Empty;
Email = string.Empty;
ContactNumber = string.Empty;
PrimaryAddress = string.Empty;
SecondaryAddress = string.Empty;
}
}
85 changes: 27 additions & 58 deletions Russkyc.GroomWise/Views/Dialogs/AddCustomersView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,66 +60,35 @@
Placeholder="Last Name"
Text="{Binding LastName, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
<russkyc:ModernTextBox Margin="0,12,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Description"
Text="{Binding Address, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernComboBox Margin="0,12,0,0"
CornerRadius="5"
DisplayMemberPath="ServiceName"
ItemsSource="{Binding Services.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}"
Placeholder="Service"
SelectedValue="{Binding Service.ServiceDescription, UpdateSourceTrigger=PropertyChanged}" />
<Grid Margin="0,12,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="350" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<russkyc:ModernComboBox Grid.Column="0"
CornerRadius="5"
DisplayMemberPath="Time"
FontSize="14"
FontWeight="Medium"
ItemsSource="{Binding Times.EditableCollectionView, UpdateSourceTrigger=PropertyChanged}"
SelectedValue="{Binding Time, UpdateSourceTrigger=PropertyChanged}">
<russkyc:ModernComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="MaxHeight" Value="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=russkyc:ModernComboBox}}" />
<Setter Property="Width" Value="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=russkyc:ModernComboBox}}" />
</Style>
</russkyc:ModernComboBox.Resources>
</russkyc:ModernComboBox>
<russkyc:ModernRadioButton Grid.Column="1"
Width="70"
Margin="12,0,0,0"
Padding="2"
VerticalContentAlignment="Center"
BorderThickness="1"
Command="{Binding DataContext.SetTimeOfDayCommand, RelativeSource={RelativeSource AncestorType=russkyc:ModernWindow}}"
CommandParameter="{StaticResource True}"
Content="AM"
CornerRadius="5"
FontSize="14"
FontWeight="Medium"
GroupName="TimeOfDay"
IsChecked="{Binding IsAm, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernRadioButton Grid.Column="2"
Width="70"
Margin="6,0,0,0"
Padding="2"
VerticalContentAlignment="Center"
BorderThickness="1"
Command="{Binding .DataContext.SetTimeOfDayCommand, RelativeSource={RelativeSource AncestorType=russkyc:ModernWindow}}"
CommandParameter="{StaticResource False}"
Content="PM"
CornerRadius="5"
FontSize="14"
FontWeight="Medium"
GroupName="TimeOfDay"
IsChecked="{Binding IsAm, UpdateSourceTrigger=PropertyChanged, Converter={x:Static converter:InverseBooleanConverter.Instance}}" />
<russkyc:ModernTextBox Grid.Column="0"
Margin="0,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Email"
Text="{Binding Email, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox Grid.Column="1"
Margin="12,0,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Contact Number"
Text="{Binding ContactNumber, UpdateSourceTrigger=PropertyChanged}" />

</Grid>
<russkyc:ModernTextBox Margin="0,12,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Primary Address"
Text="{Binding PrimaryAddress, UpdateSourceTrigger=PropertyChanged}" />
<russkyc:ModernTextBox Margin="0,12,0,0"
CornerRadius="5"
HelperText="Max Length (200)"
Placeholder="Secondary Address"
Text="{Binding SecondaryAddress, UpdateSourceTrigger=PropertyChanged}" />
<StackPanel Margin="0,24,0,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
Expand All @@ -139,8 +108,8 @@
</b:Interaction.Triggers>
</russkyc:ModernButton>
<russkyc:ModernButton HorizontalAlignment="Right"
Command="{Binding AddAppointmentCommand}"
Content="Save Appointment"
Command="{Binding AddCustomerCommand}"
Content="Save Customer"
CornerRadius="5"
FontWeight="Medium"
LeftCenterIcon="{wpf:MaterialIconExt Kind=ContentSave}" />
Expand Down
3 changes: 2 additions & 1 deletion Russkyc.GroomWise/Views/Dialogs/AddCustomersView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace GroomWise.Views.Dialogs;

public partial class AddCustomersView : IAddCustomersView
{
public AddCustomersView()
public AddCustomersView(IAddCustomersViewModel viewModel)
{
DataContext = viewModel;
InitializeComponent();
}

Expand Down

0 comments on commit baa8210

Please sign in to comment.