diff --git a/Library/DataLayer/Implementations/DataContex.cs b/Library/DataLayer/Implementations/DataContex.cs index a80a41d..ea6bd06 100644 --- a/Library/DataLayer/Implementations/DataContex.cs +++ b/Library/DataLayer/Implementations/DataContex.cs @@ -65,7 +65,24 @@ public async Task AddUserAsync(IUser user) } } - public async Task UpdateUserAsync(IUser user) + public async Task GetUserQueryAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.User? user = await Task.Run(() => + { + var query = from u in context.User + where u.guid == guid + select u; + + return query.FirstOrDefault(); + }); + + return user is not null ? new User(user.guid, user.firstName, user.lastName, user.email, user.balance, user.phoneNumber) : null; + } + } + + public async Task UpdateUserAsync(IUser user) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) { @@ -93,6 +110,18 @@ public async Task DeleteUserAsync(string guid) } } + public async Task DeleteUserMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.User toDelete = context.User.FirstOrDefault(u => u.guid == guid)!; + + context.User.DeleteOnSubmit(toDelete); + + await Task.Run(() => context.SubmitChanges()); + } + } + public async Task> GetAllUsersAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -105,6 +134,17 @@ public async Task DeleteUserAsync(string guid) } } + public async Task> GetAllUsersMethodAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + IQueryable usersQuery = context.User + .Select(u => new User(u.guid, u.firstName, u.lastName, u.email, u.balance, u.phoneNumber) as IUser); + + return await Task.Run(() => usersQuery.ToDictionary(k => k.Guid)); + } + } + public async Task GetUsersCountAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -113,6 +153,17 @@ public async Task GetUsersCountAsync() } } + public async Task GetUsersCountQueryAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + var userCountQuery = from u in context.User + select u; + + return await Task.Run(() => userCountQuery.Count()); + } + } + #endregion #region Product CRUD @@ -157,6 +208,19 @@ public async Task AddProductAsync(IBook product) } } + public async Task GetProductMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Book? product = await Task.Run(() => + { + return context.Book.FirstOrDefault(p => p.guid == guid); + }); + + return product is not null ? new Book(product.guid, product.name, (double)product.price, product.author, product.publisher, product.pages, product.publicationDate) : null; + } + } + public async Task UpdateProductAsync(IBook product) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -176,6 +240,26 @@ public async Task UpdateProductAsync(IBook product) } } + public async Task UpdateProductMethodAsync(IBook product) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Book toUpdate = context.Book.FirstOrDefault(p => p.guid == product.Guid)!; + + if (toUpdate != null) + { + toUpdate.name = product.Name; + toUpdate.price = product.Price; + toUpdate.author = product.Author; + toUpdate.publisher = product.Publisher; + toUpdate.pages = product.Pages; + toUpdate.publicationDate = product.PublicationDate; + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task DeleteProductAsync(string guid) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -188,6 +272,21 @@ public async Task DeleteProductAsync(string guid) } } + public async Task DeleteProductMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Book toDelete = context.Book.FirstOrDefault(p => p.guid == guid)!; + + if (toDelete != null) + { + context.Book.DeleteOnSubmit(toDelete); + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task> GetAllProductsAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -200,6 +299,17 @@ public async Task DeleteProductAsync(string guid) } } + public async Task> GetAllProductsMethodAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + IQueryable productQuery = context.Book + .Select(p => new Book(p.guid, p.name, (double)p.price, p.author, p.publisher, p.pages, p.publicationDate) as IBook); + + return await Task.Run(() => productQuery.ToDictionary(k => k.Guid)); + } + } + public async Task GetProductsCountAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -248,6 +358,19 @@ public async Task AddStateAsync(IState state) } } + public async Task GetStateMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.State? state = await Task.Run(() => + { + return context.State.FirstOrDefault(s => s.guid == guid); + }); + + return state is not null ? new State(state.guid, state.productGuid, state.quantity) : null; + } + } + public async Task UpdateStateAsync(IState state) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -261,6 +384,22 @@ public async Task UpdateStateAsync(IState state) } } + public async Task UpdateStateMethodAsync(IState state) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.State toUpdate = context.State.FirstOrDefault(s => s.guid == state.Guid)!; + + if (toUpdate != null) + { + toUpdate.productGuid = state.ProductGuid; + toUpdate.quantity = state.Quantity; + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task DeleteStateAsync(string guid) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -273,6 +412,21 @@ public async Task DeleteStateAsync(string guid) } } + public async Task DeleteStateMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.State toDelete = context.State.FirstOrDefault(s => s.guid == guid)!; + + if (toDelete != null) + { + context.State.DeleteOnSubmit(toDelete); + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task> GetAllStatesAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -285,6 +439,17 @@ public async Task DeleteStateAsync(string guid) } } + public async Task> GetAllStatesMethodAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + IQueryable stateQuery = context.State + .Select(s => new State(s.guid, s.productGuid, s.quantity) as IState); + + return await Task.Run(() => stateQuery.ToDictionary(k => k.Guid)); + } + } + public async Task GetStatesCountAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -336,6 +501,19 @@ public async Task AddEventAsync(IEvent even) } + public async Task GetEventMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Event? even = await Task.Run(() => + { + return context.Event.FirstOrDefault(e => e.guid == guid); + }); + + return even is not null ? new Event(even.guid, even.stateGuid, even.userGuid, even.createdAt, even.type) : null; + } + } + public async Task UpdateEventAsync(IEvent even) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -351,6 +529,24 @@ public async Task UpdateEventAsync(IEvent even) } } + public async Task UpdateEventMethodAsync(IEvent even) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Event toUpdate = context.Event.FirstOrDefault(e => e.guid == even.Guid)!; + + if (toUpdate != null) + { + toUpdate.stateGuid = even.StateGuid; + toUpdate.userGuid = even.UserGuid; + toUpdate.createdAt = even.CreatedAt; + toUpdate.type = even.Type; + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task DeleteEventAsync(string guid) { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -363,6 +559,21 @@ public async Task DeleteEventAsync(string guid) } } + public async Task DeleteEventMethodAsync(string guid) + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + Database.Event toDelete = context.Event.FirstOrDefault(e => e.guid == guid)!; + + if (toDelete != null) + { + context.Event.DeleteOnSubmit(toDelete); + + await Task.Run(() => context.SubmitChanges()); + } + } + } + public async Task> GetAllEventsAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -375,6 +586,17 @@ public async Task DeleteEventAsync(string guid) } } + public async Task> GetAllEventsMethodAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + IQueryable eventQuery = context.Event + .Select(e => new Event(e.guid, e.stateGuid, e.userGuid, e.createdAt, e.type) as IEvent); + + return await Task.Run(() => eventQuery.ToDictionary(k => k.Guid)); + } + } + public async Task GetEventsCountAsync() { using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) @@ -383,6 +605,17 @@ public async Task GetEventsCountAsync() } } + public async Task GetEventsCountQueryAsync() + { + using (LibraryDataClassesDataContext context = new LibraryDataClassesDataContext(_connectionString)) + { + var eventCountQuery = from e in context.Event + select e; + + return await Task.Run(() => eventCountQuery.Count()); + } + } + #endregion diff --git a/Library/Presentation/IErrorInformer.cs b/Library/Presentation/IErrorInformer.cs deleted file mode 100644 index 6b13222..0000000 --- a/Library/Presentation/IErrorInformer.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Presentation -{ - public interface IErrorInformer - { - void InformError(string message); - - void InformSuccess(string message); - - string GetRecentMessage(); - } -} diff --git a/Library/Presentation/Model/API/IEventModelOperation.cs b/Library/Presentation/Model/API/IEventModelOperation.cs index 9b22897..a90babc 100644 --- a/Library/Presentation/Model/API/IEventModelOperation.cs +++ b/Library/Presentation/Model/API/IEventModelOperation.cs @@ -1,5 +1,4 @@ -using Presentation.Model.Implementation; -using Service.API; +using Service.API; namespace Presentation.Model.API { diff --git a/Library/Presentation/Model/API/IProductModelOperation.cs b/Library/Presentation/Model/API/IProductModelOperation.cs index ae9f5fd..dd539c8 100644 --- a/Library/Presentation/Model/API/IProductModelOperation.cs +++ b/Library/Presentation/Model/API/IProductModelOperation.cs @@ -1,5 +1,4 @@ -using Presentation.Model.Implementation; -using Service.API; +using Service.API; namespace Presentation.Model.API { diff --git a/Library/Presentation/Model/API/IStateModelOperation.cs b/Library/Presentation/Model/API/IStateModelOperation.cs index 2400de4..d795633 100644 --- a/Library/Presentation/Model/API/IStateModelOperation.cs +++ b/Library/Presentation/Model/API/IStateModelOperation.cs @@ -1,5 +1,4 @@ -using Presentation.Model.Implementation; -using Service.API; +using Service.API; namespace Presentation.Model.API { diff --git a/Library/Presentation/Model/API/IUserModelOperation.cs b/Library/Presentation/Model/API/IUserModelOperation.cs index 5f1ae39..581747c 100644 --- a/Library/Presentation/Model/API/IUserModelOperation.cs +++ b/Library/Presentation/Model/API/IUserModelOperation.cs @@ -1,6 +1,4 @@ -using Presentation.Model.Implementation; -using Service.API; -using Service.Implementation; +using Service.API; namespace Presentation.Model.API { diff --git a/Library/Presentation/Model/Implementation/EventModel .cs b/Library/Presentation/Model/EventModel.cs similarity index 93% rename from Library/Presentation/Model/Implementation/EventModel .cs rename to Library/Presentation/Model/EventModel.cs index 525b0b1..6b49dce 100644 --- a/Library/Presentation/Model/Implementation/EventModel .cs +++ b/Library/Presentation/Model/EventModel.cs @@ -2,7 +2,7 @@ using System; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class EventModel : IEventModel { diff --git a/Library/Presentation/Model/Implementation/EventModelOperation .cs b/Library/Presentation/Model/EventModelOperation.cs similarity index 97% rename from Library/Presentation/Model/Implementation/EventModelOperation .cs rename to Library/Presentation/Model/EventModelOperation.cs index 3de8733..0aadcd0 100644 --- a/Library/Presentation/Model/Implementation/EventModelOperation .cs +++ b/Library/Presentation/Model/EventModelOperation.cs @@ -3,7 +3,7 @@ using Service.API; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class EventModelOperation : IEventModelOperation { diff --git a/Library/Presentation/Model/Implementation/ProductModel.cs b/Library/Presentation/Model/ProductModel.cs similarity index 95% rename from Library/Presentation/Model/Implementation/ProductModel.cs rename to Library/Presentation/Model/ProductModel.cs index 51b918a..a1dc162 100644 --- a/Library/Presentation/Model/Implementation/ProductModel.cs +++ b/Library/Presentation/Model/ProductModel.cs @@ -1,7 +1,7 @@ using Presentation.Model.API; using Service.API; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class ProductModel : IProductModel { diff --git a/Library/Presentation/Model/Implementation/ProductModelOperation.cs b/Library/Presentation/Model/ProductModelOperation.cs similarity index 97% rename from Library/Presentation/Model/Implementation/ProductModelOperation.cs rename to Library/Presentation/Model/ProductModelOperation.cs index 0c95087..8eb9137 100644 --- a/Library/Presentation/Model/Implementation/ProductModelOperation.cs +++ b/Library/Presentation/Model/ProductModelOperation.cs @@ -2,7 +2,7 @@ using Presentation.Model.API; using Service.API; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class ProductModelOperation : IProductModelOperation { diff --git a/Library/Presentation/Model/Implementation/StateModel.cs b/Library/Presentation/Model/StateModel.cs similarity index 94% rename from Library/Presentation/Model/Implementation/StateModel.cs rename to Library/Presentation/Model/StateModel.cs index b312058..f9e4fdb 100644 --- a/Library/Presentation/Model/Implementation/StateModel.cs +++ b/Library/Presentation/Model/StateModel.cs @@ -2,7 +2,7 @@ using System; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class StateModel : IStateModel { diff --git a/Library/Presentation/Model/Implementation/StateModelOperation .cs b/Library/Presentation/Model/StateModelOperation.cs similarity index 97% rename from Library/Presentation/Model/Implementation/StateModelOperation .cs rename to Library/Presentation/Model/StateModelOperation.cs index 184d5f2..777d827 100644 --- a/Library/Presentation/Model/Implementation/StateModelOperation .cs +++ b/Library/Presentation/Model/StateModelOperation.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class StateModelOperation : IStateModelOperation { diff --git a/Library/Presentation/Model/Implementation/UserModel.cs b/Library/Presentation/Model/UserModel.cs similarity index 95% rename from Library/Presentation/Model/Implementation/UserModel.cs rename to Library/Presentation/Model/UserModel.cs index 6cce541..c5c6259 100644 --- a/Library/Presentation/Model/Implementation/UserModel.cs +++ b/Library/Presentation/Model/UserModel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class UserModel : IUserModel { diff --git a/Library/Presentation/Model/Implementation/UserModelOperation.cs b/Library/Presentation/Model/UserModelOperation.cs similarity index 97% rename from Library/Presentation/Model/Implementation/UserModelOperation.cs rename to Library/Presentation/Model/UserModelOperation.cs index 15a0988..69485c5 100644 --- a/Library/Presentation/Model/Implementation/UserModelOperation.cs +++ b/Library/Presentation/Model/UserModelOperation.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; -namespace Presentation.Model.Implementation +namespace Presentation.Model { internal class UserModelOperation : IUserModelOperation { diff --git a/Library/Presentation/PopupErrorInformer.cs b/Library/Presentation/PopupErrorInformer.cs deleted file mode 100644 index 4f2f54f..0000000 --- a/Library/Presentation/PopupErrorInformer.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Presentation -{ - internal class PopupErrorInformer : IErrorInformer - { - private string _recentMessage; - - public PopupErrorInformer() - { - _recentMessage = string.Empty; - } - - public void InformError(string message) - { - _recentMessage = message; - - MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - - public void InformSuccess(string message) - { - _recentMessage = message; - - MessageBox.Show(message, "Success", MessageBoxButton.OK, MessageBoxImage.Information); - } - - public string GetRecentMessage() - { - return _recentMessage; - } - } -} diff --git a/Library/Presentation/View/Event/EventDetailView.xaml b/Library/Presentation/View/Event/EventDetailView.xaml index c9ba31a..4830838 100644 --- a/Library/Presentation/View/Event/EventDetailView.xaml +++ b/Library/Presentation/View/Event/EventDetailView.xaml @@ -11,7 +11,6 @@ - diff --git a/Library/Presentation/View/Event/EventMasterView.xaml b/Library/Presentation/View/Event/EventMasterView.xaml index f835e60..250acd1 100644 --- a/Library/Presentation/View/Event/EventMasterView.xaml +++ b/Library/Presentation/View/Event/EventMasterView.xaml @@ -12,7 +12,6 @@ - diff --git a/Library/Presentation/View/Product/ProductDetailView.xaml b/Library/Presentation/View/Product/ProductDetailView.xaml index 129f017..c0a1b68 100644 --- a/Library/Presentation/View/Product/ProductDetailView.xaml +++ b/Library/Presentation/View/Product/ProductDetailView.xaml @@ -11,7 +11,6 @@ - diff --git a/Library/Presentation/View/Product/ProductMasterView.xaml b/Library/Presentation/View/Product/ProductMasterView.xaml index b0d9fb7..bc07da6 100644 --- a/Library/Presentation/View/Product/ProductMasterView.xaml +++ b/Library/Presentation/View/Product/ProductMasterView.xaml @@ -12,7 +12,6 @@ - diff --git a/Library/Presentation/View/State/StateDetailView.xaml b/Library/Presentation/View/State/StateDetailView.xaml index de6ca96..7f2d337 100644 --- a/Library/Presentation/View/State/StateDetailView.xaml +++ b/Library/Presentation/View/State/StateDetailView.xaml @@ -11,7 +11,6 @@ - diff --git a/Library/Presentation/View/State/StateMasterView.xaml b/Library/Presentation/View/State/StateMasterView.xaml index 8c8f1c0..6090668 100644 --- a/Library/Presentation/View/State/StateMasterView.xaml +++ b/Library/Presentation/View/State/StateMasterView.xaml @@ -12,7 +12,6 @@ - diff --git a/Library/Presentation/View/User/UserDetailView.xaml b/Library/Presentation/View/User/UserDetailView.xaml index 969f9c1..8a2a354 100644 --- a/Library/Presentation/View/User/UserDetailView.xaml +++ b/Library/Presentation/View/User/UserDetailView.xaml @@ -11,7 +11,6 @@ - diff --git a/Library/Presentation/View/User/UserMasterView.xaml b/Library/Presentation/View/User/UserMasterView.xaml index 611d9dc..f6080f9 100644 --- a/Library/Presentation/View/User/UserMasterView.xaml +++ b/Library/Presentation/View/User/UserMasterView.xaml @@ -11,7 +11,6 @@ - diff --git a/Library/Presentation/ViewModel/Event/EventDetailViewModel.cs b/Library/Presentation/ViewModel/Event/EventDetailViewModel.cs index 47e482f..792e919 100644 --- a/Library/Presentation/ViewModel/Event/EventDetailViewModel.cs +++ b/Library/Presentation/ViewModel/Event/EventDetailViewModel.cs @@ -15,8 +15,6 @@ internal class EventDetailViewModel : IViewModel, IEventDetailViewModel private readonly IEventModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private string _guid; private string _stateGuid; private string _userGuid; @@ -85,20 +83,18 @@ public DateTime OccurrenceDate } } - public EventDetailViewModel(IEventModelOperation? model = null, IErrorInformer? informer = null) + public EventDetailViewModel(IEventModelOperation? model = null) { this.UpdateEvent = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = IEventModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } - public EventDetailViewModel(string guid, string stateGuid, string userGuid, DateTime createdAt, string type, IEventModelOperation? model = null, IErrorInformer? informer = null) + public EventDetailViewModel(string guid, string stateGuid, string userGuid, DateTime createdAt, string type, IEventModelOperation? model = null) { this.UpdateEvent = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = IEventModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); this.Guid = guid; this.StateGuid = stateGuid; @@ -112,8 +108,6 @@ private void Update() Task.Run(async () => { await this._modelOperation.UpdateAsync(this.Guid, this.StateGuid, this.UserGuid, this.OccurrenceDate, this.Type); - - this._informer.InformSuccess("Event successfully updated!"); }); } diff --git a/Library/Presentation/ViewModel/Event/EventMasterViewModel.cs b/Library/Presentation/ViewModel/Event/EventMasterViewModel.cs index 0c9f3f3..d047990 100644 --- a/Library/Presentation/ViewModel/Event/EventMasterViewModel.cs +++ b/Library/Presentation/ViewModel/Event/EventMasterViewModel.cs @@ -29,8 +29,6 @@ internal class EventMasterViewModel : IViewModel, IEventMasterViewModel private readonly IEventModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private ObservableCollection _events; public ObservableCollection Events @@ -106,7 +104,7 @@ public IEventDetailViewModel SelectedDetailViewModel } } - public EventMasterViewModel(IEventModelOperation? model = null, IErrorInformer? informer = null) + public EventMasterViewModel(IEventModelOperation? model = null) { this.SwitchToUserMasterPage = new SwitchViewCommand("UserMasterView"); this.SwitchToStateMasterPage = new SwitchViewCommand("StateMasterView"); @@ -120,7 +118,6 @@ public EventMasterViewModel(IEventModelOperation? model = null, IErrorInformer? this.Events = new ObservableCollection(); this._modelOperation = IEventModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); this.IsEventSelected = false; @@ -162,12 +159,10 @@ private void StorePurchaseEvent() await this._modelOperation.AddAsync(guid, this.StateGuid, this.UserGuid, DateTime.Now, "RentEvent"); this.LoadEvents(); - - this._informer.InformSuccess("Event successfully created!"); } catch (Exception e) { - this._informer.InformError(e.Message); + } }); } @@ -181,8 +176,6 @@ private void StoreReturnEvent() await this._modelOperation.AddAsync(guid, this.StateGuid, this.UserGuid, DateTime.Now, "ReturnEvent"); this.LoadEvents(); - - this._informer.InformSuccess("Event successfully created!"); }); } @@ -195,8 +188,6 @@ private void StoreSupplyEvent() await this._modelOperation.AddAsync(guid, this.StateGuid, this.UserGuid, DateTime.Now, "SupplyEvent"); this.LoadEvents(); - - this._informer.InformSuccess("Event successfully created!"); }); } @@ -207,8 +198,6 @@ private void DeleteEvent() await this._modelOperation.DeleteAsync(this.SelectedDetailViewModel.Guid); this.LoadEvents(); - - this._informer.InformSuccess("Event successfully deleted!"); }); } diff --git a/Library/Presentation/ViewModel/Event/IEventDetailViewModel.cs b/Library/Presentation/ViewModel/Event/IEventDetailViewModel.cs index de4576d..67be75d 100644 --- a/Library/Presentation/ViewModel/Event/IEventDetailViewModel.cs +++ b/Library/Presentation/ViewModel/Event/IEventDetailViewModel.cs @@ -7,9 +7,9 @@ namespace Presentation.ViewModel { public interface IEventDetailViewModel { - static IEventDetailViewModel CreateViewModel(string guid, string stateGuid, string userGuid, DateTime CreatedAt, string type, IEventModelOperation model, IErrorInformer informer) + static IEventDetailViewModel CreateViewModel(string guid, string stateGuid, string userGuid, DateTime CreatedAt, string type, IEventModelOperation model) { - return new EventDetailViewModel(guid, stateGuid, userGuid, CreatedAt, type, model, informer); + return new EventDetailViewModel(guid, stateGuid, userGuid, CreatedAt, type, model); } ICommand UpdateEvent { get; set; } diff --git a/Library/Presentation/ViewModel/Event/IEventMasterViewModel.cs b/Library/Presentation/ViewModel/Event/IEventMasterViewModel.cs index 6f903a8..f7e509d 100644 --- a/Library/Presentation/ViewModel/Event/IEventMasterViewModel.cs +++ b/Library/Presentation/ViewModel/Event/IEventMasterViewModel.cs @@ -13,9 +13,9 @@ namespace Presentation.ViewModel { public interface IEventMasterViewModel { - static IEventMasterViewModel CreateViewModel(IEventModelOperation operation, IErrorInformer informer) + static IEventMasterViewModel CreateViewModel(IEventModelOperation operation) { - return new EventMasterViewModel(operation, informer); + return new EventMasterViewModel(operation); } ICommand PurchaseEvent { get; set; } diff --git a/Library/Presentation/ViewModel/Product/IProductDetailViewModel.cs b/Library/Presentation/ViewModel/Product/IProductDetailViewModel.cs index e8e14af..9cc8e2f 100644 --- a/Library/Presentation/ViewModel/Product/IProductDetailViewModel.cs +++ b/Library/Presentation/ViewModel/Product/IProductDetailViewModel.cs @@ -5,9 +5,9 @@ namespace Presentation.ViewModel { public interface IProductDetailViewModel { - static IProductDetailViewModel CreateViewModel(string guid, string name, double price, string author, string publisher, int pages, DateTime publicationDate, IProductModelOperation model, IErrorInformer informer) + static IProductDetailViewModel CreateViewModel(string guid, string name, double price, string author, string publisher, int pages, DateTime publicationDate, IProductModelOperation model) { - return new ProductDetailViewModel(guid, name, price, author, publisher, pages, publicationDate, model, informer); + return new ProductDetailViewModel(guid, name, price, author, publisher, pages, publicationDate, model); } ICommand UpdateProduct { get; set; } diff --git a/Library/Presentation/ViewModel/Product/IProductMasterViewModel.cs b/Library/Presentation/ViewModel/Product/IProductMasterViewModel.cs index 8a8ecd5..cc8902f 100644 --- a/Library/Presentation/ViewModel/Product/IProductMasterViewModel.cs +++ b/Library/Presentation/ViewModel/Product/IProductMasterViewModel.cs @@ -12,9 +12,9 @@ namespace Presentation.ViewModel { public interface IProductMasterViewModel { - static IProductMasterViewModel CreateViewModel(IProductModelOperation operation, IErrorInformer informer) + static IProductMasterViewModel CreateViewModel(IProductModelOperation operation) { - return new ProductMasterViewModel(operation, informer); + return new ProductMasterViewModel(operation); } ICommand CreateProduct { get; set; } diff --git a/Library/Presentation/ViewModel/Product/ProductDetailViewModel.cs b/Library/Presentation/ViewModel/Product/ProductDetailViewModel.cs index cbcbb91..865eea6 100644 --- a/Library/Presentation/ViewModel/Product/ProductDetailViewModel.cs +++ b/Library/Presentation/ViewModel/Product/ProductDetailViewModel.cs @@ -10,8 +10,6 @@ internal class ProductDetailViewModel : IViewModel, IProductDetailViewModel private readonly IProductModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private string _guid; private string _name; private double _price; @@ -90,15 +88,14 @@ public DateTime PublicationDate } } - public ProductDetailViewModel(IProductModelOperation? model = null, IErrorInformer? informer = null) + public ProductDetailViewModel(IProductModelOperation? model = null) { this.UpdateProduct = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = model ?? IProductModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } - public ProductDetailViewModel(string guid, string name, double price, string author, string publisher, int pages, DateTime publicationDate, IProductModelOperation? model = null, IErrorInformer? informer = null) + public ProductDetailViewModel(string guid, string name, double price, string author, string publisher, int pages, DateTime publicationDate, IProductModelOperation? model = null) { Guid = guid; Name = name; @@ -110,17 +107,13 @@ public ProductDetailViewModel(string guid, string name, double price, string aut this.UpdateProduct = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); - this._modelOperation = model ?? IProductModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); - } + this._modelOperation = model ?? IProductModelOperation.CreateModelOperation(); } private void Update() { Task.Run(() => { this._modelOperation.UpdateAsync(this.Guid, this.Name, this.Price, this.Author, this.Publisher, this.Pages, this.PublicationDate); - - this._informer.InformSuccess("Product successfully updated!"); }); } diff --git a/Library/Presentation/ViewModel/Product/ProductMasterViewModel.cs b/Library/Presentation/ViewModel/Product/ProductMasterViewModel.cs index 6148548..bb5a1a5 100644 --- a/Library/Presentation/ViewModel/Product/ProductMasterViewModel.cs +++ b/Library/Presentation/ViewModel/Product/ProductMasterViewModel.cs @@ -20,8 +20,6 @@ internal class ProductMasterViewModel : IViewModel, IProductMasterViewModel private readonly IProductModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private ObservableCollection _products; public ObservableCollection Products @@ -141,7 +139,7 @@ public IProductDetailViewModel SelectedDetailViewModel } } - public ProductMasterViewModel(IProductModelOperation? model = null, IErrorInformer? informer = null) + public ProductMasterViewModel(IProductModelOperation? model = null) { this.SwitchToUserMasterPage = new SwitchViewCommand("UserMasterView"); this.SwitchToStateMasterPage = new SwitchViewCommand("StateMasterView"); @@ -153,7 +151,6 @@ public ProductMasterViewModel(IProductModelOperation? model = null, IErrorInform this.Products = new ObservableCollection(); this._modelOperation = model ?? IProductModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); this.IsProductSelected = false; @@ -184,8 +181,6 @@ private void StoreProduct() this.LoadProducts(); - this._informer.InformSuccess("Product added successfully!"); - }); } @@ -198,12 +193,10 @@ private void DeleteProduct() await this._modelOperation.DeleteAsync(this.SelectedDetailViewModel.Guid); this.LoadProducts(); - - this._informer.InformSuccess("Product deleted successfully!"); } catch (Exception e) { - this._informer.InformError("Error while deleting product!"); + } }); } diff --git a/Library/Presentation/ViewModel/State/IStateDetailViewModel.cs b/Library/Presentation/ViewModel/State/IStateDetailViewModel.cs index fdabb03..b94ab83 100644 --- a/Library/Presentation/ViewModel/State/IStateDetailViewModel.cs +++ b/Library/Presentation/ViewModel/State/IStateDetailViewModel.cs @@ -7,9 +7,9 @@ namespace Presentation.ViewModel { public interface IStateDetailViewModel { - static IStateDetailViewModel CreateViewModel(string guid, string productGuid, int quantity, IStateModelOperation model, IErrorInformer informer) + static IStateDetailViewModel CreateViewModel(string guid, string productGuid, int quantity, IStateModelOperation model) { - return new StateDetailViewModel(guid, productGuid, quantity, model, informer); + return new StateDetailViewModel(guid, productGuid, quantity, model); } ICommand UpdateState { get; set; } diff --git a/Library/Presentation/ViewModel/State/IStateMasterViewModel.cs b/Library/Presentation/ViewModel/State/IStateMasterViewModel.cs index 2312774..52127b7 100644 --- a/Library/Presentation/ViewModel/State/IStateMasterViewModel.cs +++ b/Library/Presentation/ViewModel/State/IStateMasterViewModel.cs @@ -7,9 +7,9 @@ namespace Presentation.ViewModel { public interface IStateMasterViewModel { - static IStateMasterViewModel CreateViewModel(IStateModelOperation operation, IErrorInformer informer) + static IStateMasterViewModel CreateViewModel(IStateModelOperation operation) { - return new StateMasterViewModel(operation, informer); + return new StateMasterViewModel(operation); } public ICommand CreateState { get; set; } diff --git a/Library/Presentation/ViewModel/State/StateDetailViewModel.cs b/Library/Presentation/ViewModel/State/StateDetailViewModel.cs index 5031d33..68d4a69 100644 --- a/Library/Presentation/ViewModel/State/StateDetailViewModel.cs +++ b/Library/Presentation/ViewModel/State/StateDetailViewModel.cs @@ -10,8 +10,6 @@ internal class StateDetailViewModel : IViewModel, IStateDetailViewModel private readonly IStateModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private string _guid; private string _productGuid; private int _quantity; @@ -46,15 +44,14 @@ public int Quantity } } - public StateDetailViewModel(IStateModelOperation? model = null, IErrorInformer? informer = null) + public StateDetailViewModel(IStateModelOperation? model = null) { this.UpdateState = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = IStateModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } - public StateDetailViewModel(string guid, string productGuid, int quantity, IStateModelOperation? model = null, IErrorInformer? informer = null) + public StateDetailViewModel(string guid, string productGuid, int quantity, IStateModelOperation? model = null) { this.Guid = guid; this.ProductGuid = productGuid; @@ -63,7 +60,6 @@ public StateDetailViewModel(string guid, string productGuid, int quantity, IStat this.UpdateState = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = IStateModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } private void Update() @@ -71,8 +67,6 @@ private void Update() Task.Run(() => { this._modelOperation.UpdateAsync(this.Guid, this.ProductGuid, this.Quantity); - - this._informer.InformSuccess("State successfully updated!"); }); } diff --git a/Library/Presentation/ViewModel/State/StateMasterViewModel.cs b/Library/Presentation/ViewModel/State/StateMasterViewModel.cs index 85d36e4..e33fe8b 100644 --- a/Library/Presentation/ViewModel/State/StateMasterViewModel.cs +++ b/Library/Presentation/ViewModel/State/StateMasterViewModel.cs @@ -20,8 +20,6 @@ internal class StateMasterViewModel : IViewModel, IStateMasterViewModel private readonly IStateModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private ObservableCollection _states; public ObservableCollection States @@ -108,7 +106,7 @@ public IStateDetailViewModel SelectedDetailViewModel } } - public StateMasterViewModel(IStateModelOperation? model = null, IErrorInformer? informer = null) + public StateMasterViewModel(IStateModelOperation? model = null) { this.SwitchToUserMasterPage = new SwitchViewCommand("UserMasterView"); this.SwitchToProductMasterPage = new SwitchViewCommand("ProductMasterView"); @@ -120,7 +118,6 @@ public StateMasterViewModel(IStateModelOperation? model = null, IErrorInformer? this.States = new ObservableCollection(); this._modelOperation = IStateModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); this.IsStateSelected = false; @@ -147,12 +144,10 @@ private void StoreState() await this._modelOperation.AddAsync(guid, this.ProductGuid, this.Quantity); this.LoadStates(); - - this._informer.InformSuccess("State successfully created!"); } catch (Exception e) { - this._informer.InformError(e.Message); + } }); } @@ -166,12 +161,10 @@ private void DeleteState() await this._modelOperation.DeleteAsync(this.SelectedDetailViewModel.Guid); this.LoadStates(); - - this._informer.InformSuccess("State successfully deleted!"); } catch (Exception e) { - this._informer.InformError("Error while deleting state!"); + } }); } diff --git a/Library/Presentation/ViewModel/User/IUserDetailViewModel.cs b/Library/Presentation/ViewModel/User/IUserDetailViewModel.cs index 5a17973..098c029 100644 --- a/Library/Presentation/ViewModel/User/IUserDetailViewModel.cs +++ b/Library/Presentation/ViewModel/User/IUserDetailViewModel.cs @@ -10,9 +10,9 @@ namespace Presentation.ViewModel { public interface IUserDetailViewModel { - static IUserDetailViewModel CreateViewModel(string guid, string firstName, string lastName, string email, double balance, string phoneNumber, IUserModelOperation model, IErrorInformer informer) + static IUserDetailViewModel CreateViewModel(string guid, string firstName, string lastName, string email, double balance, string phoneNumber, IUserModelOperation model) { - return new UserDetailViewModel(guid, firstName, lastName, email, balance, phoneNumber, model, informer); + return new UserDetailViewModel(guid, firstName, lastName, email, balance, phoneNumber, model); } ICommand UpdateUser { get; set;} diff --git a/Library/Presentation/ViewModel/User/IUserMasterViewModel.cs b/Library/Presentation/ViewModel/User/IUserMasterViewModel.cs index 098fc79..302b6e3 100644 --- a/Library/Presentation/ViewModel/User/IUserMasterViewModel.cs +++ b/Library/Presentation/ViewModel/User/IUserMasterViewModel.cs @@ -8,15 +8,14 @@ using System.Windows.Input; using System.Windows; using Presentation; -using Presentation.ViewModel; -namespace Presentationion.ViewModel +namespace Presentation.ViewModel { public interface IUserMasterViewModel { - static IUserMasterViewModel CreateViewModel(IUserModelOperation operation, IErrorInformer informer) + static IUserMasterViewModel CreateViewModel(IUserModelOperation operation) { - return new UserMasterViewModel(operation, informer); + return new UserMasterViewModel(operation); } ICommand CreateUser { get; set; } diff --git a/Library/Presentation/ViewModel/User/UserDetailViewModel.cs b/Library/Presentation/ViewModel/User/UserDetailViewModel.cs index 74b3c43..4382693 100644 --- a/Library/Presentation/ViewModel/User/UserDetailViewModel.cs +++ b/Library/Presentation/ViewModel/User/UserDetailViewModel.cs @@ -9,7 +9,6 @@ internal class UserDetailViewModel : IViewModel, IUserDetailViewModel public ICommand UpdateUser { get; set; } private readonly IUserModelOperation _modelOperation; - private readonly IErrorInformer _informer; private string? _guid; private string? _firstName; @@ -80,15 +79,14 @@ public string PhoneNumber } } - public UserDetailViewModel(IUserModelOperation? model = null, IErrorInformer? informer = null) + public UserDetailViewModel(IUserModelOperation? model = null) { this.UpdateUser = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = model ?? IUserModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } - public UserDetailViewModel(string guid, string firstName, string lastName, string email, double balance, string phoneNumber, IUserModelOperation? model = null, IErrorInformer? informer = null) + public UserDetailViewModel(string guid, string firstName, string lastName, string email, double balance, string phoneNumber, IUserModelOperation? model = null) { this.Guid = guid; this.FirstName = firstName; @@ -100,7 +98,6 @@ public UserDetailViewModel(string guid, string firstName, string lastName, strin this.UpdateUser = new OnClickCommand(e => this.Update(), c => this.CanUpdate()); this._modelOperation = model ?? IUserModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); } private void Update() @@ -108,8 +105,6 @@ private void Update() Task.Run(() => { this._modelOperation.UpdateAsync(this.Guid, this.FirstName, this.LastName, this.Email, this.Balance, this.PhoneNumber); - - this._informer.InformSuccess("User successfully updated!"); }); } diff --git a/Library/Presentation/ViewModel/User/UserMasterViewModel.cs b/Library/Presentation/ViewModel/User/UserMasterViewModel.cs index 01a3812..82574e5 100644 --- a/Library/Presentation/ViewModel/User/UserMasterViewModel.cs +++ b/Library/Presentation/ViewModel/User/UserMasterViewModel.cs @@ -2,7 +2,7 @@ using System.Collections.ObjectModel; using System.Windows.Input; using System.Windows; -using Presentationion.ViewModel; +using Presentation.ViewModel; namespace Presentation.ViewModel { @@ -20,8 +20,6 @@ public class UserMasterViewModel : IViewModel, IUserMasterViewModel private readonly IUserModelOperation _modelOperation; - private readonly IErrorInformer _informer; - private ObservableCollection _users; public ObservableCollection Users @@ -131,7 +129,7 @@ public IUserDetailViewModel SelectedDetailViewModel } } - public UserMasterViewModel(IUserModelOperation? model = null, IErrorInformer? informer = null) + public UserMasterViewModel(IUserModelOperation? model = null) { this.SwitchToProductMasterPage = new SwitchViewCommand("ProductMasterView"); this.SwitchToStateMasterPage = new SwitchViewCommand("StateMasterView"); @@ -143,7 +141,6 @@ public UserMasterViewModel(IUserModelOperation? model = null, IErrorInformer? in this.Users = new ObservableCollection(); this._modelOperation = model ?? IUserModelOperation.CreateModelOperation(); - this._informer = informer ?? new PopupErrorInformer(); this.IsUserSelected = false; @@ -170,8 +167,6 @@ private void StoreUser() await this._modelOperation.AddAsync(guid, this.FirstName, this.LastName, this.Email, this.Balance, this.PhoneNumber); - this._informer.InformSuccess("User successfully created!"); - this.LoadUsers(); }); } @@ -184,13 +179,11 @@ private void DeleteUser() { await this._modelOperation.DeleteAsync(this.SelectedDetailViewModel.Guid); - this._informer.InformSuccess("User successfully deleted!"); - this.LoadUsers(); } catch (Exception e) { - this._informer.InformError("Error while deleting user!"); + } }); } diff --git a/Library/PresentationLayerTests/ISeeder.cs b/Library/PresentationLayerTests/ISeeder.cs index 09d1ea2..45aa121 100644 --- a/Library/PresentationLayerTests/ISeeder.cs +++ b/Library/PresentationLayerTests/ISeeder.cs @@ -1,5 +1,4 @@ using Presentation.ViewModel; -using Presentationion.ViewModel; using System; using System.Collections.Generic; using System.Linq; diff --git a/Library/PresentationLayerTests/MockErrorInformer.cs b/Library/PresentationLayerTests/MockErrorInformer.cs deleted file mode 100644 index 914b159..0000000 --- a/Library/PresentationLayerTests/MockErrorInformer.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Presentation; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PresentationLayerTests -{ - internal class MockErrorInformer : IErrorInformer - { - public string RecentMessage; - - public MockErrorInformer() - { - RecentMessage = string.Empty; - } - - public void InformError(string message) - { - RecentMessage = message; - } - - public void InformSuccess(string message) - { - RecentMessage = message; - } - - public string GetRecentMessage() - { - return RecentMessage; - } - } -} diff --git a/Library/PresentationLayerTests/PresentationLayerTests.cs b/Library/PresentationLayerTests/PresentationLayerTests.cs index dbdf237..916ec22 100644 --- a/Library/PresentationLayerTests/PresentationLayerTests.cs +++ b/Library/PresentationLayerTests/PresentationLayerTests.cs @@ -1,7 +1,6 @@ using Presentation; using Presentation.Model.API; using Presentation.ViewModel; -using Presentationion.ViewModel; using PresentationLayerTests.MockClasses; using Service.API; using System; @@ -15,14 +14,12 @@ namespace PresentationLayerTests [TestClass] public class PresentationLayerTests { - private readonly IErrorInformer _informer = new MockErrorInformer(); - [TestMethod] public void UserMasterViewModelTest() { IUserCRUD fakeUserCrud = new MockUserCRUD(); IUserModelOperation operation = IUserModelOperation.CreateModelOperation(fakeUserCrud); - IUserMasterViewModel viewModel = IUserMasterViewModel.CreateViewModel(operation, _informer); + IUserMasterViewModel viewModel = IUserMasterViewModel.CreateViewModel(operation); viewModel.FirstName = "Alice"; viewModel.LastName = "Jane"; @@ -41,7 +38,7 @@ public void UserDetailViewModelTests() { IUserCRUD mockUserCrud = new MockUserCRUD(); IUserModelOperation operation = IUserModelOperation.CreateModelOperation(mockUserCrud); - IUserDetailViewModel viewModel = IUserDetailViewModel.CreateViewModel("1", "Alice", "Jane", "Test@test.mail", 100, "123456789", operation, _informer); + IUserDetailViewModel viewModel = IUserDetailViewModel.CreateViewModel("1", "Alice", "Jane", "Test@test.mail", 100, "123456789", operation); Assert.AreEqual("1", viewModel.Guid); Assert.AreEqual("Alice", viewModel.FirstName); @@ -57,7 +54,7 @@ public void ProductMasterViewModelTests() { IProductCRUD mockProductCrud = new MockProductCRUD(); IProductModelOperation operation = IProductModelOperation.CreateModelOperation(mockProductCrud); - IProductMasterViewModel viewModel = IProductMasterViewModel.CreateViewModel(operation, _informer); + IProductMasterViewModel viewModel = IProductMasterViewModel.CreateViewModel(operation); viewModel.Name = "Product"; viewModel.Price = 100; @@ -77,7 +74,7 @@ public void ProductDetailViewModelTests() { IProductCRUD mockProductCrud = new MockProductCRUD(); IProductModelOperation operation = IProductModelOperation.CreateModelOperation(mockProductCrud); - IProductDetailViewModel viewModel = IProductDetailViewModel.CreateViewModel("1", "Product", 100, "Author", "Publisher", 100, new DateTime(2020,12,12), operation, _informer); + IProductDetailViewModel viewModel = IProductDetailViewModel.CreateViewModel("1", "Product", 100, "Author", "Publisher", 100, new DateTime(2020,12,12), operation); Assert.AreEqual("1", viewModel.Guid); Assert.AreEqual("Product", viewModel.Name); @@ -94,7 +91,7 @@ public void StateMasterViewModelTests() { IStateCRUD mockStateCrud = new MockStateCRUD(); IStateModelOperation operation = IStateModelOperation.CreateModelOperation(mockStateCrud); - IStateMasterViewModel viewModel = IStateMasterViewModel.CreateViewModel(operation, _informer); + IStateMasterViewModel viewModel = IStateMasterViewModel.CreateViewModel(operation); viewModel.ProductGuid = "1"; viewModel.Quantity = 10; @@ -110,7 +107,7 @@ public void StateDetailViewModelTests() { IStateCRUD mockStateCrud = new MockStateCRUD(); IStateModelOperation operation = IStateModelOperation.CreateModelOperation(mockStateCrud); - IStateDetailViewModel viewModel = IStateDetailViewModel.CreateViewModel("1", "1", 10, operation, _informer); + IStateDetailViewModel viewModel = IStateDetailViewModel.CreateViewModel("1", "1", 10, operation); Assert.AreEqual("1", viewModel.Guid); Assert.AreEqual("1", viewModel.ProductGuid); @@ -123,7 +120,7 @@ public void EventMasterViewModelTests() { IEventCRUD mockEventCrud = new MockEventCRUD(); IEventModelOperation operation = IEventModelOperation.CreateModelOperation(mockEventCrud); - IEventMasterViewModel viewModel = IEventMasterViewModel.CreateViewModel(operation, _informer); + IEventMasterViewModel viewModel = IEventMasterViewModel.CreateViewModel(operation); viewModel.StateGuid = "1"; viewModel.UserGuid = "1"; @@ -143,7 +140,7 @@ public void EventDetailViewModelTests() { IEventCRUD mockEventCrud = new MockEventCRUD(); IEventModelOperation operation = IEventModelOperation.CreateModelOperation(mockEventCrud); - IEventDetailViewModel viewModel = IEventDetailViewModel.CreateViewModel("1", "1", "1", new DateTime(2020,12,12), "Delivery", operation, _informer); + IEventDetailViewModel viewModel = IEventDetailViewModel.CreateViewModel("1", "1", "1", new DateTime(2020,12,12), "Delivery", operation); Assert.AreEqual("1", viewModel.Guid); Assert.AreEqual("1", viewModel.StateGuid); diff --git a/Library/PresentationLayerTests/PresetSeeder.cs b/Library/PresentationLayerTests/PresetSeeder.cs index 866cf32..a567cf3 100644 --- a/Library/PresentationLayerTests/PresetSeeder.cs +++ b/Library/PresentationLayerTests/PresetSeeder.cs @@ -1,7 +1,6 @@ using Presentation; using Presentation.Model.API; using Presentation.ViewModel; -using Presentationion.ViewModel; using PresentationLayerTests.MockClasses; using System; using System.Collections.Generic; @@ -13,51 +12,49 @@ namespace PresentationLayerTests { internal class PresetSeeder : ISeeder { - private IErrorInformer _informer = new MockErrorInformer(); - public void GenerateUserModels(IUserMasterViewModel viewModel) { IUserModelOperation operation = IUserModelOperation.CreateModelOperation(new MockUserCRUD()); - viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("1", "Alice", "Jane", "alice@example.com", 12, "123456789", operation, _informer)); - viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("2", "Bob", "Smith", "bob@example.com", 34, "987654321", operation, _informer)); - viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("3", "Charlie", "Brown", "charlie@example.com", 56, "456123789", operation, _informer)); - viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("4", "Diana", "Prince", "diana@example.com", 78, "321654987", operation, _informer)); - viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("5", "Eve", "Adams", "eve@example.com", 90, "654789123", operation, _informer)); + viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("1", "Alice", "Jane", "alice@example.com", 12, "123456789", operation)); + viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("2", "Bob", "Smith", "bob@example.com", 34, "987654321", operation)); + viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("3", "Charlie", "Brown", "charlie@example.com", 56, "456123789", operation)); + viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("4", "Diana", "Prince", "diana@example.com", 78, "321654987", operation)); + viewModel.Users.Add(IUserDetailViewModel.CreateViewModel("5", "Eve", "Adams", "eve@example.com", 90, "654789123", operation)); } public void GenerateProductModels(IProductMasterViewModel viewModel) { IProductModelOperation operation = IProductModelOperation.CreateModelOperation(new MockProductCRUD()); - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("1", "Old Man and the Sea", 100, "Ernest Hemingway", "Publisher1", 100, new DateTime(1972, 12, 12), operation, _informer)); - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("2", "The Great Gatsby", 200, "F. Scott Fitzgerald", "Publisher2", 200, new DateTime(1982, 11, 11), operation, _informer)); - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("3", "The Catcher in the Rye", 300, "J.D. Salinger", "Publisher3", 300, new DateTime(1992, 10, 10), operation, _informer)); - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("4", "To Kill a Mockingbird", 400, "Harper Lee", "Publisher4", 400, new DateTime(2002, 9, 9), operation, _informer)); - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("5", "1984", 500, "George Orwell", "Publisher5", 500, new DateTime(2012, 8, 8), operation, _informer)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("1", "Old Man and the Sea", 100, "Ernest Hemingway", "Publisher1", 100, new DateTime(1972, 12, 12), operation)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("2", "The Great Gatsby", 200, "F. Scott Fitzgerald", "Publisher2", 200, new DateTime(1982, 11, 11), operation)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("3", "The Catcher in the Rye", 300, "J.D. Salinger", "Publisher3", 300, new DateTime(1992, 10, 10), operation)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("4", "To Kill a Mockingbird", 400, "Harper Lee", "Publisher4", 400, new DateTime(2002, 9, 9), operation)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel("5", "1984", 500, "George Orwell", "Publisher5", 500, new DateTime(2012, 8, 8), operation)); } public void GenerateStateModels(IStateMasterViewModel viewModel) { IStateModelOperation operation = IStateModelOperation.CreateModelOperation(new MockStateCRUD()); - viewModel.States.Add(IStateDetailViewModel.CreateViewModel("1", "1", 10, operation, _informer)); - viewModel.States.Add(IStateDetailViewModel.CreateViewModel("2", "2", 20, operation, _informer)); - viewModel.States.Add(IStateDetailViewModel.CreateViewModel("3", "3", 30, operation, _informer)); - viewModel.States.Add(IStateDetailViewModel.CreateViewModel("4", "4", 40, operation, _informer)); - viewModel.States.Add(IStateDetailViewModel.CreateViewModel("5", "5", 50, operation, _informer)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel("1", "1", 10, operation)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel("2", "2", 20, operation)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel("3", "3", 30, operation)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel("4", "4", 40, operation)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel("5", "5", 50, operation)); } public void GenerateEventModels(IEventMasterViewModel viewModel) { IEventModelOperation operation = IEventModelOperation.CreateModelOperation(new MockEventCRUD()); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("1", "1", "1", DateTime.Now, "Return", operation, _informer)); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("2", "2", "2", DateTime.Now, "Delivery", operation, _informer)); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("3", "3", "3", DateTime.Now, "Borrow", operation, _informer)); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("4", "4", "4", DateTime.Now, "Delivery", operation, _informer)); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("5", "5", "5", DateTime.Now, "Borrow", operation, _informer)); - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("6", "3", "5", DateTime.Now, "Delivery", operation, _informer)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("1", "1", "1", DateTime.Now, "Return", operation)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("2", "2", "2", DateTime.Now, "Delivery", operation)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("3", "3", "3", DateTime.Now, "Borrow", operation)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("4", "4", "4", DateTime.Now, "Delivery", operation)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("5", "5", "5", DateTime.Now, "Borrow", operation)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel("6", "3", "5", DateTime.Now, "Delivery", operation)); } } } diff --git a/Library/PresentationLayerTests/RandomSeeder.cs b/Library/PresentationLayerTests/RandomSeeder.cs index f75d13d..34f36a5 100644 --- a/Library/PresentationLayerTests/RandomSeeder.cs +++ b/Library/PresentationLayerTests/RandomSeeder.cs @@ -1,7 +1,6 @@ using Presentation.Model.API; using Presentation.ViewModel; using Presentation; -using Presentationion.ViewModel; using PresentationLayerTests.MockClasses; using System; using System.Collections.Generic; @@ -12,9 +11,7 @@ namespace PresentationLayerTests { internal class RandomSeeder : ISeeder - { - private IErrorInformer _informer = new MockErrorInformer(); - + { public void GenerateUserModels(IUserMasterViewModel viewModel) { IUserModelOperation operation = IUserModelOperation.CreateModelOperation(new MockUserCRUD()); @@ -23,7 +20,7 @@ public void GenerateUserModels(IUserMasterViewModel viewModel) { viewModel.Users.Add(IUserDetailViewModel.CreateViewModel(i.ToString(), RandomString(10), RandomString(10), RandomString(10) + "@" + RandomString(10), RandomNumber(1, 101), RandomPhoneNumber(), - operation, _informer)); + operation)); } } @@ -33,7 +30,7 @@ public void GenerateProductModels(IProductMasterViewModel viewModel) for (int i = 0; i < 5; i++) { - viewModel.Products.Add(IProductDetailViewModel.CreateViewModel(i.ToString(), RandomString(10), RandomNumber(1, 101), RandomString(10), RandomString(10), RandomNumber(1, 101), RandomDateTime(), operation, _informer)); + viewModel.Products.Add(IProductDetailViewModel.CreateViewModel(i.ToString(), RandomString(10), RandomNumber(1, 101), RandomString(10), RandomString(10), RandomNumber(1, 101), RandomDateTime(), operation)); } } @@ -43,7 +40,7 @@ public void GenerateStateModels(IStateMasterViewModel viewModel) for (int i = 0; i < 5; i++) { - viewModel.States.Add(IStateDetailViewModel.CreateViewModel(i.ToString(), i.ToString(), RandomNumber(1, 101), operation, _informer)); + viewModel.States.Add(IStateDetailViewModel.CreateViewModel(i.ToString(), i.ToString(), RandomNumber(1, 101), operation)); } } @@ -53,7 +50,7 @@ public void GenerateEventModels(IEventMasterViewModel viewModel) for (int i = 0; i < 5; i++) { - viewModel.Events.Add(IEventDetailViewModel.CreateViewModel(i.ToString(), i.ToString(), i.ToString(), DateTime.Now, "Delivery", operation, _informer)); + viewModel.Events.Add(IEventDetailViewModel.CreateViewModel(i.ToString(), i.ToString(), i.ToString(), DateTime.Now, "Delivery", operation)); } }