Skip to content

Commit

Permalink
Update main project to use the domain layer
Browse files Browse the repository at this point in the history
  • Loading branch information
kathulhur committed Dec 14, 2023
1 parent cdc9206 commit 2707969
Show file tree
Hide file tree
Showing 53 changed files with 690 additions and 437 deletions.
Binary file modified .vs/ProjectEvaluation/storemanagementsystemx.metadata.v7.bin
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/storemanagementsystemx.projects.v7.bin
Binary file not shown.
Binary file modified .vs/StoreManagementSystemX/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/StoreManagementSystemX/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/StoreManagementSystemX/v17/.suo
Binary file not shown.
Binary file modified .vs/StoreManagementSystemX/v17/TestStore/0/testlog.manifest
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StoreManagementSystemX.Domain.Factories.StockPurchases;
using StoreManagementSystemX.Domain.Factories.Transactions;
using StoreManagementSystemX.Domain.Repositories.StockPurchases;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace StoreManagementSystemX.Domain.Tests
{
public class TransactionAggregateTests
{

private readonly ITransactionFactory _transactionFactory = new TransactionFactory();
private readonly IProductFactory _productFactory = new ProductFactory(new BarcodeGenerationService(new ProductRepository()));
private static readonly PayLaterFactory payLaterFactory = new PayLaterFactory();
private static readonly ITransactionFactory _transactionFactory = new TransactionFactory(payLaterFactory);
private static readonly IProductFactory _productFactory = new ProductFactory(new BarcodeGenerationService(new ProductRepository()));

private ITransaction CreateEmptyTransaction()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using StoreManagementSystemX.Domain.Factories.Transactions;
using StoreManagementSystemX.Domain.Repositories;
using StoreManagementSystemX.Domain.Factories.Transactions.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Transactions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,11 +11,12 @@ namespace StoreManagementSystemX.Domain.Tests
{
public class TransactionRepositoryTests
{
private static PayLaterFactory payLaterFactory = new PayLaterFactory();

private TransactionRepository CreateTransactionRepositoryWithSingleTransaction()
{
TransactionRepository transactionRepository = new TransactionRepository();
TransactionFactory transactionFactory = new TransactionFactory();
TransactionFactory transactionFactory = new TransactionFactory(payLaterFactory);

var transaction = transactionFactory.Create(Guid.NewGuid());

Expand Down
4 changes: 3 additions & 1 deletion StoreManagementSystemX.Domain.Tests/UserRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using StoreManagementSystemX.Domain.Factories.Products.Interfaces;
using StoreManagementSystemX.Domain.Factories.StockPurchases;
using StoreManagementSystemX.Domain.Factories.Transactions;
using StoreManagementSystemX.Domain.Factories.Transactions.Interfaces;
using StoreManagementSystemX.Domain.Factories.Users;
using StoreManagementSystemX.Domain.Factories.Users.Interfaces;
using StoreManagementSystemX.Domain.Repositories;
Expand All @@ -28,7 +29,8 @@ private UserFactory CreateUserFactory()
var productRepository = new ProductRepository();
var barcodeGenerationService = new BarcodeGenerationService(productRepository);
var productFactory = new ProductFactory(barcodeGenerationService);
var transactionFactory = new TransactionFactory();
var payLaterFactory = new PayLaterFactory();
var transactionFactory = new TransactionFactory(payLaterFactory);
var stockPurchaseFactory = new StockPurchaseFactory();
var userFactory = new UserFactory(productFactory, transactionFactory, stockPurchaseFactory);
return userFactory;
Expand Down
28 changes: 19 additions & 9 deletions StoreManagementSystemX/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@ public NavigationService
IUnitOfWorkFactory unitOfWorkFactory,
IAuthenticationService authenticationService,
IDialogService dialogService,
Domain.Repositories.Products.Interfaces.IProductRepository productRepository
Domain.Repositories.Products.Interfaces.IProductRepository productRepository,
Domain.Repositories.StockPurchases.Interfaces.IStockPurchaseRepository stockPurchaseRepository,
Domain.Repositories.Transactions.Interfaces.ITransactionRepository transactionRepository,
Domain.Repositories.Users.Interfaces.IUserRepository userRepository
)
{
_currentViewModel = initialViewModel;
_authenticationService = authenticationService;
_unitOfWorkFactory = unitOfWorkFactory;
_dialogService = dialogService;
_productRepository = productRepository;
_stockPurchaseRepository = stockPurchaseRepository;
_transactionRepository = transactionRepository;
_userRepository = userRepository;
_productUpdateService = new ProductUpdateService(productRepository);
_barcodeImageService = new BarcodeImageService();
_productCreationService = new ProductCreationService(_productRepository, _barcodeImageService);
_userCreationService = new UserCreationService(_unitOfWorkFactory);
_stockPurchaseCreationService = new StockPurchaseCreationService(_unitOfWorkFactory, _dialogService);
_transactionCreationService = new TransactionCreationService(_unitOfWorkFactory, _dialogService);
_userCreationService = new UserCreationService(_userRepository);
_stockPurchaseCreationService = new StockPurchaseCreationService(stockPurchaseRepository, productRepository, _dialogService);
_transactionCreationService = new TransactionCreationService(_transactionRepository, _productRepository, _dialogService);

}
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
Expand All @@ -51,7 +57,11 @@ Domain.Repositories.Products.Interfaces.IProductRepository productRepository
private readonly UserCreationService _userCreationService;
private readonly StockPurchaseCreationService _stockPurchaseCreationService;
private readonly TransactionCreationService _transactionCreationService;

private readonly Domain.Repositories.Products.Interfaces.IProductRepository _productRepository;
private readonly Domain.Repositories.StockPurchases.Interfaces.IStockPurchaseRepository _stockPurchaseRepository;
private readonly Domain.Repositories.Transactions.Interfaces.ITransactionRepository _transactionRepository;
private readonly Domain.Repositories.Users.Interfaces.IUserRepository _userRepository;
private BaseViewModel _currentViewModel;

public BaseViewModel CurrentViewModel
Expand All @@ -74,7 +84,7 @@ public void NavigateTo(View view)
}
else if (view == View.Dashboard && _authenticationService.AuthContext != null)
{
CurrentViewModel = new DashboardViewModel(_authenticationService.AuthContext, _unitOfWorkFactory, _dialogService, _transactionCreationService);
CurrentViewModel = new DashboardViewModel(_authenticationService.AuthContext, _transactionRepository, _dialogService, _transactionCreationService);
}
else if (view == View.Inventory && _authenticationService.AuthContext != null)
{
Expand All @@ -83,20 +93,20 @@ public void NavigateTo(View view)
}
else if (view == View.Transactions && _authenticationService.AuthContext != null)
{
CurrentViewModel = new TransactionListViewModel(_authenticationService.AuthContext, _unitOfWorkFactory, _dialogService, _transactionCreationService);
CurrentViewModel = new TransactionListViewModel(_authenticationService.AuthContext, _transactionRepository, _dialogService, _transactionCreationService);
}
else if (view == View.PayLaterTransactions && _authenticationService.AuthContext != null)
{
CurrentViewModel = new PayLaterTransactionsViewModel(_authenticationService.AuthContext, _unitOfWorkFactory, _dialogService, _transactionCreationService);
CurrentViewModel = new PayLaterTransactionsViewModel(_authenticationService.AuthContext, _transactionRepository, _dialogService, _transactionCreationService);
}
else if (view == View.UserList && _authenticationService.AuthContext != null)
{

CurrentViewModel = new UserListViewModel(_authenticationService.AuthContext, _unitOfWorkFactory, _dialogService, _userCreationService);
CurrentViewModel = new UserListViewModel(_authenticationService.AuthContext, _userRepository, _dialogService, _userCreationService);
}
else if (view == View.StockPurchaseList && _authenticationService.AuthContext != null)
{
CurrentViewModel = new StockPurchaseListViewModel(_authenticationService.AuthContext, _unitOfWorkFactory, _dialogService, _stockPurchaseCreationService);
CurrentViewModel = new StockPurchaseListViewModel(_authenticationService.AuthContext, _stockPurchaseRepository, _dialogService, _stockPurchaseCreationService);
}
else
{
Expand Down
21 changes: 11 additions & 10 deletions StoreManagementSystemX/Services/StockPurchaseCreationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using StoreManagementSystemX.Database.DAL.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Products.Interfaces;
using StoreManagementSystemX.Domain.Repositories.StockPurchases.Interfaces;
using StoreManagementSystemX.Services.Interfaces;
using StoreManagementSystemX.Views.StockPurchases;
using System;
Expand All @@ -11,27 +13,26 @@ namespace StoreManagementSystemX.Services
{
class StockPurchaseCreationService : IStockPurchaseCreationService
{
public StockPurchaseCreationService(IUnitOfWorkFactory unitOfWorkFactory, IDialogService dialogService)
public StockPurchaseCreationService(Domain.Repositories.StockPurchases.Interfaces.IStockPurchaseRepository stockPurchaseRepository, Domain.Repositories.Products.Interfaces.IProductRepository productRepository, IDialogService dialogService)
{
_unitOfWorkFactory = unitOfWorkFactory;
_stockPurchaseRepository = stockPurchaseRepository;
_productRepository = productRepository;
_dialogService = dialogService;
}

private readonly IDialogService _dialogService;
private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly Domain.Repositories.StockPurchases.Interfaces.IStockPurchaseRepository _stockPurchaseRepository;
private readonly Domain.Repositories.Products.Interfaces.IProductRepository _productRepository;

public Guid? CreateStockPurchase(AuthContext authContext)
{
Guid? newStockPurchase = null;
using (var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
var window = new CreateStockPurchaseWindow(authContext, _stockPurchaseRepository, _productRepository, _dialogService, (Guid stockPurchaseId) =>
{
var window = new CreateStockPurchaseWindow(authContext, unitOfWork, _dialogService, (Guid stockPurchaseId) =>
{
newStockPurchase = stockPurchaseId;
});
window.ShowDialog();
newStockPurchase = stockPurchaseId;
});
window.ShowDialog();

}
return newStockPurchase;
}
}
Expand Down
27 changes: 15 additions & 12 deletions StoreManagementSystemX/Services/TransactionCreationService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using StoreManagementSystemX.Database.DAL.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Products.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Transactions.Interfaces;
using StoreManagementSystemX.Services.Interfaces;
using StoreManagementSystemX.ViewModels.Transactions.Interfaces;
using StoreManagementSystemX.Views.Transactions;
using System;
using System.Collections.Generic;
Expand All @@ -12,30 +15,30 @@ namespace StoreManagementSystemX.Services
public class TransactionCreationService : ITransactionCreationService
{

public TransactionCreationService(IUnitOfWorkFactory unitOfWorkFactory, IDialogService dialogService)
public TransactionCreationService(
Domain.Repositories.Transactions.Interfaces.ITransactionRepository transactionRepository,
Domain.Repositories.Products.Interfaces.IProductRepository productRepository,
IDialogService dialogService)
{
_unitOfWorkFactory = unitOfWorkFactory;
_transactionRepository = transactionRepository;
_productRepository = productRepository;
_dialogService = dialogService;
}

private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly Domain.Repositories.Transactions.Interfaces.ITransactionRepository _transactionRepository;
private readonly Domain.Repositories.Products.Interfaces.IProductRepository _productRepository;

private readonly IDialogService _dialogService;

public Guid? CreateNewTransaction(AuthContext authContext)
{
Guid? newTransaction = null;
using(var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
var window = new CreateTransactionWindow(authContext, _transactionRepository, _productRepository, _dialogService, (Guid transactionId) =>
{
var window = new CreateTransactionWindow(authContext, unitOfWork, _dialogService, (Guid transactionId) =>
{
newTransaction = transactionId;
});
newTransaction = transactionId;
});

window.ShowDialog();


}
window.ShowDialog();
return newTransaction;

}
Expand Down
9 changes: 5 additions & 4 deletions StoreManagementSystemX/Services/UserCreationService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StoreManagementSystemX.Database.DAL.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Users.Interfaces;
using StoreManagementSystemX.Services.Interfaces;
using StoreManagementSystemX.Views.Users;
using System;
Expand All @@ -11,17 +12,17 @@ namespace StoreManagementSystemX.Services
{
public class UserCreationService : IUserCreationService
{
public UserCreationService(IUnitOfWorkFactory unitOfWorkFactory)
public UserCreationService(Domain.Repositories.Users.Interfaces.IUserRepository userRepository)
{
_unitOfWorkFactory = unitOfWorkFactory;
_userRepository = userRepository;
}

private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly Domain.Repositories.Users.Interfaces.IUserRepository _userRepository;

public Guid? CreateNewUser(AuthContext authContext)
{
Guid? newUserId = null;
var window = new CreateUserWindow(authContext, _unitOfWorkFactory, (Guid id) =>
var window = new CreateUserWindow(authContext, _userRepository, (Guid id) =>
{
newUserId = id;
});
Expand Down
29 changes: 13 additions & 16 deletions StoreManagementSystemX/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.Input;
using StoreManagementSystemX.Database.DAL.Interfaces;
using StoreManagementSystemX.Domain.Repositories.Transactions.Interfaces;
using StoreManagementSystemX.Services;
using StoreManagementSystemX.Services.Interfaces;
using StoreManagementSystemX.ViewModels.Interfaces;
Expand All @@ -19,21 +20,20 @@ public class DashboardViewModel : BaseViewModel, IDashboardViewModel
{


public DashboardViewModel(AuthContext authContext, IUnitOfWorkFactory unitOfWorkFactory, IDialogService dialogService, ITransactionCreationService transactionCreationService)
public DashboardViewModel(AuthContext authContext, Domain.Repositories.Transactions.Interfaces.ITransactionRepository transactionRepository, IDialogService dialogService, ITransactionCreationService transactionCreationService)
{
_unitOfWorkFactory = unitOfWorkFactory;
_transactionRepository = transactionRepository;
_authContext = authContext;
_dialogService = dialogService;
_transactionCreationService = transactionCreationService;
TransactionsToday = new ObservableCollection<ITransactionRowViewModel>();
using(var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())

var transactions = _transactionRepository.GetAll();
foreach (var transaction in transactions)
{
var transactions = unitOfWork.TransactionRepository.Get(t => t.DateTime.Date == DateTime.Now.Date, t => t.OrderByDescending(e => e.DateTime), "TransactionProducts");
foreach (var transaction in transactions)
{
TransactionsToday.Add(new TransactionRowViewModel(unitOfWorkFactory, _dialogService, transaction));
}
TransactionsToday.Add(new TransactionRowViewModel(transactionRepository, _dialogService, transaction));
}

NewTransactionCommand = new RelayCommand(NewTransactionCommandHandler);
if (TransactionsToday.Any())
{
Expand All @@ -46,7 +46,7 @@ public DashboardViewModel(AuthContext authContext, IUnitOfWorkFactory unitOfWork
}
}

private readonly IUnitOfWorkFactory _unitOfWorkFactory;
private readonly Domain.Repositories.Transactions.Interfaces.ITransactionRepository _transactionRepository;
private readonly AuthContext _authContext;
private readonly IDialogService _dialogService;
private readonly ITransactionCreationService _transactionCreationService;
Expand Down Expand Up @@ -113,15 +113,12 @@ private void NewTransactionCommandHandler()
var newTransactionId = _transactionCreationService.CreateNewTransaction(_authContext);
if(newTransactionId != null)
{
using(var unitOfWork = _unitOfWorkFactory.CreateUnitOfWork())
var newTransaction = _transactionRepository.GetById((Guid) newTransactionId);
if(newTransaction != null)
{
var newTransaction = unitOfWork.TransactionRepository.GetById((Guid) newTransactionId, "TransactionProducts,TransactionProducts.Product");
if(newTransaction != null)
{
TransactionsToday.Insert(0, new TransactionRowViewModel(_unitOfWorkFactory, _dialogService, newTransaction));
}
NotifyPropertiesChanged();
TransactionsToday.Insert(0, new TransactionRowViewModel(_transactionRepository, _dialogService, newTransaction));
}
NotifyPropertiesChanged();
}

}
Expand Down
Loading

0 comments on commit 2707969

Please sign in to comment.