From 9343be009d6a3bbe9f4ceb978087e6905b0574c7 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 01:05:51 +0300 Subject: [PATCH 01/17] Added button DeleteDetails --- .../DeleteDetailWindowOfOrderInfoCommand.cs | 37 +++++++++++++++++++ Alligator/TabItems/TabItemOrders.xaml | 16 +++++--- Alligator/TabItems/TabItemOrders.xaml.cs | 5 ++- .../TabItemOrdersViewModel.cs | 14 +++++++ 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs diff --git a/Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs new file mode 100644 index 0000000..c6dde79 --- /dev/null +++ b/Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs @@ -0,0 +1,37 @@ +using Alligator.BusinessLayer; +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Alligator.UI.Commands.TabItemOrders +{ + class DeleteDetailWindowOfOrderInfoCommand : CommandBase + { + + private TabItemOrdersViewModel _viewModel; + private OrderDetailService _orderDetailService; + + + public DeleteDetailWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) + { + _viewModel = viewModel; + _orderDetailService = orderDetailService; + } + public override bool CanExecute(object parameter) + { + return _viewModel.SelectedOrderDetail is not null; + } + + public override void Execute(object parameter) + { + _orderDetailService.DeleteOrderDetailModel(_viewModel.SelectedOrderDetail.Id); + _viewModel.OrderDetails.Remove(_viewModel.SelectedOrderDetail); + } + + + + } +} diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index d8fcd05..44b1569 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -105,6 +105,7 @@ + @@ -121,15 +122,20 @@ - + + + + + - - - + + + + @@ -137,7 +143,7 @@ - + diff --git a/Alligator/TabItems/TabItemOrders.xaml.cs b/Alligator/TabItems/TabItemOrders.xaml.cs index df407e7..e83668e 100644 --- a/Alligator/TabItems/TabItemOrders.xaml.cs +++ b/Alligator/TabItems/TabItemOrders.xaml.cs @@ -17,8 +17,11 @@ public TabItemOrders() InitializeComponent(); _viewModel = new TabItemOrdersViewModel(); DataContext = _viewModel; - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + //_viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + //_viewModel.OrdersInfoWindowVisibility = Visibility.Visible; + //_viewModel.OrdersWindowVisibility = Visibility.Collapsed; } } } diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 8e02197..9ba0851 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -48,6 +48,7 @@ public class TabItemOrdersViewModel : BaseViewModel public ICommand AddReviewWindowOfAddOrder { get; set; } public ICommand DeleteReviewWindowOfAddOrder { get; set; } public ICommand AddProductWindowOfAddOrder { get; set; } + public ICommand DeleteDetailWindowOfOrderInfo { get; set; } public TabItemOrdersViewModel() { @@ -78,6 +79,7 @@ public TabItemOrdersViewModel() AddReviewWindowOfAddOrder = new AddReviewWindowOfAddOrderCommand(this); DeleteReviewWindowOfAddOrder = new DeleteReviewWindowOfAddOrderCommand(this); AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); + DeleteDetailWindowOfOrderInfo = new DeleteDetailWindowOfOrderInfoCommand(this, _orderDetailService); } @@ -176,6 +178,7 @@ public OrderDetailModel SelectedOrderDetail set { _selectedOrderDetailModel = value; + ((CommandBase)DeleteDetailWindowOfOrderInfo).RaiseCanExecuteChanged(); OnPropertyChanged(nameof(SelectedOrderDetail)); } } @@ -356,5 +359,16 @@ public Visibility ButtonDeleteNewReview OnPropertyChanged(nameof(ButtonDeleteNewReview)); } } + + private Visibility _buttonDeleteDetail; + public Visibility ButtonDeleteDetail + { + get { return _buttonDeleteDetail; } + set + { + _buttonDeleteDetail = value; + OnPropertyChanged(nameof(ButtonDeleteDetail)); + } + } } } From 64b81cd692c9081b371eb1ef841a46df9c95b26a Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 01:15:43 +0300 Subject: [PATCH 02/17] Edit xaml --- Alligator/TabItems/TabItemOrders.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index 44b1569..bf6fdc5 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -184,7 +184,7 @@ - + @@ -197,7 +197,7 @@ - + From cbe3770b08d819d87d88a19ac53426182294de63 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 01:39:17 +0300 Subject: [PATCH 03/17] Add DeleteNewDetailCommand --- .../TabItemOrders/DeleteNewDetailCommand.cs | 28 +++++++++++++++++++ Alligator/TabItems/TabItemOrders.xaml | 5 ++++ Alligator/TabItems/TabItemOrders.xaml.cs | 8 +++--- .../TabItemOrdersViewModel.cs | 15 +++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs diff --git a/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs b/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs new file mode 100644 index 0000000..5a86144 --- /dev/null +++ b/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs @@ -0,0 +1,28 @@ +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Alligator.UI.Commands.TabItemOrders +{ + public class DeleteNewDetailCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + + public DeleteNewDetailCommand(TabItemOrdersViewModel viewModel) + { + _viewModel = viewModel; + } + + public override bool CanExecute(object parameter) + { + return _viewModel.SelectedNewOrderDetail is not null; + } + public override void Execute(object parameter) + { + _viewModel.NewOrderDetails.Remove(_viewModel.SelectedNewOrderDetail); + } + } +} diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index bf6fdc5..ffd2b1e 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -229,12 +229,17 @@ + + + + + diff --git a/Alligator/TabItems/TabItemOrders.xaml.cs b/Alligator/TabItems/TabItemOrders.xaml.cs index e83668e..0b5bf9a 100644 --- a/Alligator/TabItems/TabItemOrders.xaml.cs +++ b/Alligator/TabItems/TabItemOrders.xaml.cs @@ -17,11 +17,11 @@ public TabItemOrders() InitializeComponent(); _viewModel = new TabItemOrdersViewModel(); DataContext = _viewModel; - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; //_viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - //_viewModel.OrdersInfoWindowVisibility = Visibility.Visible; - //_viewModel.OrdersWindowVisibility = Visibility.Collapsed; + //_viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.AddOrderWindowVisibility = Visibility.Visible; + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; } } } diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 9ba0851..098c814 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -49,6 +49,7 @@ public class TabItemOrdersViewModel : BaseViewModel public ICommand DeleteReviewWindowOfAddOrder { get; set; } public ICommand AddProductWindowOfAddOrder { get; set; } public ICommand DeleteDetailWindowOfOrderInfo { get; set; } + public ICommand DeleteNewDetail { get; set; } public TabItemOrdersViewModel() { @@ -80,7 +81,7 @@ public TabItemOrdersViewModel() DeleteReviewWindowOfAddOrder = new DeleteReviewWindowOfAddOrderCommand(this); AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); DeleteDetailWindowOfOrderInfo = new DeleteDetailWindowOfOrderInfoCommand(this, _orderDetailService); - + DeleteNewDetail = new DeleteNewDetailCommand(this); } @@ -199,6 +200,7 @@ public OrderDetailModel SelectedNewOrderDetail set { _selectedNewOrderDetailModel = value; + ((CommandBase)DeleteNewDetail).RaiseCanExecuteChanged(); OnPropertyChanged(nameof(SelectedNewOrderDetail)); } } @@ -370,5 +372,16 @@ public Visibility ButtonDeleteDetail OnPropertyChanged(nameof(ButtonDeleteDetail)); } } + + private Visibility _buttonDeleteNewDetail; + public Visibility ButtonDeleteNewDetail + { + get { return _buttonDeleteNewDetail; } + set + { + _buttonDeleteNewDetail = value; + OnPropertyChanged(nameof(ButtonDeleteNewDetail)); + } + } } } From e93aeda4589b2a278a11c9773442e9403173e069 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 18:09:55 +0300 Subject: [PATCH 04/17] edit view model, added new command --- Alligator.DB/Procedures/Order_SelectAll.sql | 12 ++++--- .../Repositories/OrderDetailRepository.cs | 2 +- .../Repositories/OrderRepository.cs | 2 +- .../Commands/TabItemOrders/AddOrderCommand.cs | 15 +++++++- .../AddProductWindowOfAddOrderCommand.cs | 3 +- .../AddReviewWindowOfAddOrderCommand.cs | 2 +- ...ackFirstWindowFromAddOrderWindowCommand.cs | 34 +++++++++++++++++++ .../DeleteOrderWindowOfOrderInfoCommand.cs | 2 +- .../DeleteReviewWindowOfAddOrderCommand.cs | 2 +- .../DeleteReviewWindowOfOrderInfoCommand.cs | 2 +- Alligator/TabItems/TabItemOrders.xaml | 4 +-- Alligator/TabItems/TabItemOrders.xaml.cs | 8 ++--- .../TabItemOrdersViewModel.cs | 5 ++- 13 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs diff --git a/Alligator.DB/Procedures/Order_SelectAll.sql b/Alligator.DB/Procedures/Order_SelectAll.sql index ae45d42..b42bf2c 100644 --- a/Alligator.DB/Procedures/Order_SelectAll.sql +++ b/Alligator.DB/Procedures/Order_SelectAll.sql @@ -2,9 +2,11 @@ AS BEGIN select - id, - date, - clientId, - Address - from dbo.[Order] + o.id, + o.date, + o.Address, + c.Id, + c.FirstName, + c.LastName + from dbo.[Order] o inner join dbo.[Client] c on o.ClientId=c.Id END \ No newline at end of file diff --git a/Alligator.DataLayer/Repositories/OrderDetailRepository.cs b/Alligator.DataLayer/Repositories/OrderDetailRepository.cs index 1bcb571..04c9ae1 100644 --- a/Alligator.DataLayer/Repositories/OrderDetailRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderDetailRepository.cs @@ -69,7 +69,7 @@ public void AddOrderDetail(int amount, int orderId, int productId) using var connection = ProvideConnection(); string procString = "dbo.OrderDetail_Insert"; connection.Execute(procString, - new { Amount = amount, OrdertId = orderId, ProductId = productId }, + new { amount, orderId, productId }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index f898cbc..6c19c7b 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -58,7 +58,7 @@ public int AddOrder(DateTime date, int clientId, string address) using var connection = ProvideConnection(); string procString = "dbo.Order_Insert"; return connection.QueryFirstOrDefault(procString, - new { Date = date, ClientId = clientId, Address = address }, + new { date,clientId, address }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index 571bed2..91a490e 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -36,16 +36,29 @@ public override void Execute(object parameter) _viewModel.NewAddressText = string.Empty; } newAddress = _viewModel.NewAddressText.Trim(); + if (_viewModel.SelectedClient is null) { MessageBox.Show("Выберите клиента"); return; - } + } + + if (_viewModel.NewOrder.OrderDetails is null) + { + List orderDetails = new List(); + + _viewModel.NewOrder.OrderDetails = orderDetails; + } + if (_viewModel.NewOrderDetails is null) + { + _viewModel.NewOrderDetails = new ObservableCollection(); + } if (_viewModel.NewOrder.OrderDetails.Count==0) { MessageBox.Show("Выберите продукты и их количество"); return; } + int orderId = _orderService.AddOrderModel(_viewModel.NewDate, _viewModel.SelectedClient.Id, newAddress); foreach (var orderReview in _viewModel.NewOrderReviews) { diff --git a/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs index a37a53a..0fecead 100644 --- a/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs @@ -10,7 +10,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - class AddProductWindowOfAddOrderCommand : CommandBase + public class AddProductWindowOfAddOrderCommand : CommandBase { private TabItemOrdersViewModel _viewModel; public AddProductWindowOfAddOrderCommand(TabItemOrdersViewModel viewModel) @@ -27,6 +27,7 @@ public override void Execute(object parameter) return; } int amount = Convert.ToInt32(newAmount); + if (_viewModel.SelectedProduct is null) { MessageBox.Show("Выберите продукт"); diff --git a/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs index 1866d64..af11801 100644 --- a/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs @@ -11,7 +11,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - class AddReviewWindowOfAddOrderCommand : CommandBase + public class AddReviewWindowOfAddOrderCommand : CommandBase { private TabItemOrdersViewModel _viewModel; diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs new file mode 100644 index 0000000..7a17fa3 --- /dev/null +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs @@ -0,0 +1,34 @@ +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Alligator.UI.Commands.TabItemOrders +{ + class ComeBackFirstWindowFromAddOrderWindowCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + + public ComeBackFirstWindowFromAddOrderWindowCommand(TabItemOrdersViewModel viewModel) + { + _viewModel = viewModel; + } + + public override void Execute(object parameter) + { + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersWindowVisibility = Visibility.Visible; + _viewModel.NewReviewText = string.Empty; + _viewModel.NewAmount = string.Empty; + _viewModel.NewAddressText = string.Empty; + _viewModel.NewOrderReviews.Clear(); + _viewModel.NewOrderDetails.Clear(); + } + } + + +} diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs index 8df8cfa..1a10e51 100644 --- a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs @@ -9,7 +9,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - class DeleteOrderWindowOfOrderInfoCommand : CommandBase + public class DeleteOrderWindowOfOrderInfoCommand : CommandBase { private TabItemOrdersViewModel _viewModel; diff --git a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs index 0189447..11033cb 100644 --- a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs @@ -8,7 +8,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - class DeleteReviewWindowOfAddOrderCommand : CommandBase + public class DeleteReviewWindowOfAddOrderCommand : CommandBase { private TabItemOrdersViewModel _viewModel; diff --git a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs index 9c9e80f..98c4a97 100644 --- a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs @@ -8,7 +8,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - class DeleteReviewWindowOfOrderInfoCommand : CommandBase + public class DeleteReviewWindowOfOrderInfoCommand : CommandBase { private TabItemOrdersViewModel _viewModel; private OrderReviewService _orderReviewService; diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index ffd2b1e..56b933d 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -184,7 +184,7 @@ - + @@ -248,7 +248,7 @@ - + diff --git a/Alligator/TabItems/TabItemOrders.xaml.cs b/Alligator/TabItems/TabItemOrders.xaml.cs index 0b5bf9a..f0bd384 100644 --- a/Alligator/TabItems/TabItemOrders.xaml.cs +++ b/Alligator/TabItems/TabItemOrders.xaml.cs @@ -17,11 +17,11 @@ public TabItemOrders() InitializeComponent(); _viewModel = new TabItemOrdersViewModel(); DataContext = _viewModel; - //_viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - //_viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - _viewModel.AddOrderWindowVisibility = Visibility.Visible; - _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + //_viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + //_viewModel.AddOrderWindowVisibility = Visibility.Visible; + //_viewModel.OrdersWindowVisibility = Visibility.Collapsed; } } } diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 098c814..49653fc 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -50,6 +50,7 @@ public class TabItemOrdersViewModel : BaseViewModel public ICommand AddProductWindowOfAddOrder { get; set; } public ICommand DeleteDetailWindowOfOrderInfo { get; set; } public ICommand DeleteNewDetail { get; set; } + public ICommand ComeBackFirstWindowFromAddOrderWindow { get; set; } public TabItemOrdersViewModel() { @@ -57,6 +58,8 @@ public TabItemOrdersViewModel() _orderReviewService = new OrderReviewService(); _orderDetailService = new OrderDetailService(); _clientService = new ClientService(); + + //NewOrder = new OrderModel(); AllOrders = new ObservableCollection(); Clients = new ObservableCollection(); @@ -65,7 +68,6 @@ public TabItemOrdersViewModel() OrderReviews = new ObservableCollection(); OrderDetails = new ObservableCollection(); NewOrderDetails = new ObservableCollection(); - NewOrder = new OrderModel(); AddReviewWindowOfOrderInfo = new AddReviewWindowOfOrderInfoCommand(this, _orderReviewService); DeleteReviewWindowOfOrderInfo = new DeleteReviewWindowOfOrderInfoCommand(this, _orderReviewService); @@ -82,6 +84,7 @@ public TabItemOrdersViewModel() AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); DeleteDetailWindowOfOrderInfo = new DeleteDetailWindowOfOrderInfoCommand(this, _orderDetailService); DeleteNewDetail = new DeleteNewDetailCommand(this); + ComeBackFirstWindowFromAddOrderWindow = new ComeBackFirstWindowFromAddOrderWindowCommand(this); } From 2f78f5819020cdff964cbdd3cd83c9041a62423a Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 18:52:44 +0300 Subject: [PATCH 05/17] fixed what I broke --- Alligator.DB/Procedures/Order_SelectAll.sql | 12 +++++------- .../Repositories/OrderDetailRepository.cs | 14 +++++++------- .../Repositories/OrderRepository.cs | 6 +++--- .../Repositories/OrderReviewRepository.cs | 14 ++++++-------- Alligator/TabItems/TabItemOrders.xaml | 2 +- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Alligator.DB/Procedures/Order_SelectAll.sql b/Alligator.DB/Procedures/Order_SelectAll.sql index b42bf2c..d7c4c46 100644 --- a/Alligator.DB/Procedures/Order_SelectAll.sql +++ b/Alligator.DB/Procedures/Order_SelectAll.sql @@ -2,11 +2,9 @@ AS BEGIN select - o.id, - o.date, - o.Address, - c.Id, - c.FirstName, - c.LastName - from dbo.[Order] o inner join dbo.[Client] c on o.ClientId=c.Id + id, + date, + Address, + ClientId + from dbo.[Order] END \ No newline at end of file diff --git a/Alligator.DataLayer/Repositories/OrderDetailRepository.cs b/Alligator.DataLayer/Repositories/OrderDetailRepository.cs index 04c9ae1..40cb26d 100644 --- a/Alligator.DataLayer/Repositories/OrderDetailRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderDetailRepository.cs @@ -24,7 +24,7 @@ public OrderDetail GetOrderDetailById(int id) orderdetail.Product = product; return orderdetail; }, - new { Id = id }, + new { id }, commandType: CommandType.StoredProcedure, splitOn: "Id") .FirstOrDefault(); @@ -41,7 +41,7 @@ public List GetOrderDetailsByOrderId(int id) orderdetail.Product = product; return orderdetail; }, - new { OrderId = id }, + new { orderId=id }, commandType: CommandType.StoredProcedure, splitOn: "Id") .Distinct().ToList(); @@ -58,7 +58,7 @@ public List GetOrderDetailsByProductId(int id) orderdetail.Product = product; return orderdetail; }, - new { ProductId = id }, + new { id }, commandType: CommandType.StoredProcedure, splitOn: "Id") .Distinct().ToList(); @@ -77,7 +77,7 @@ public void EditOrderDetail(int id, int amount) { using var connection = ProvideConnection(); string procString = "dbo.OrderDetail_Update"; - connection.Execute(procString, new { Id = id, Amount = amount }, + connection.Execute(procString, new { id, amount }, commandType: CommandType.StoredProcedure); } @@ -85,7 +85,7 @@ public void DeleteOrderDetail(int id) { using var connection = ProvideConnection(); string procString = "dbo.OrderDetail_Delete"; - connection.Execute(procString, new { Id = id }, + connection.Execute(procString, new { id }, commandType: CommandType.StoredProcedure); } @@ -93,14 +93,14 @@ public void DeleteOrderDetailByOrderId(int id) { using var connection = ProvideConnection(); string procString = "dbo.OrderDetail_DeleteByOrderId"; - connection.Execute(procString, new { OrderId=id }, + connection.Execute(procString, new { orderId=id }, commandType: CommandType.StoredProcedure); } public void DeleteOrderDetailByProductId(int id) { using var connection = ProvideConnection(); string procString = "dbo.OrderDetail_DeleteByProductId"; - connection.Execute(procString, new { ProductId = id }, + connection.Execute(procString, new { id }, commandType: CommandType.StoredProcedure); } } diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 6c19c7b..8e561cd 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -31,7 +31,7 @@ public Order GetOrderById(int id) return order; }, - new { Id = id }, + new { id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). FirstOrDefault(); @@ -47,7 +47,7 @@ public List GetOrdersByClientId(int id) order.Client = client; return order; }, - new { ClientId = id }, + new { id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). Distinct().ToList(); @@ -76,7 +76,7 @@ public void EditOrder(DateTime date, int id, string address) using var connection = ProvideConnection(); string procString = "dbo.Order_Update"; connection.Execute(procString, - new { Date = date, Id = id, Address = address }, + new { date, id, address }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator.DataLayer/Repositories/OrderReviewRepository.cs b/Alligator.DataLayer/Repositories/OrderReviewRepository.cs index c18bedd..a33204a 100644 --- a/Alligator.DataLayer/Repositories/OrderReviewRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderReviewRepository.cs @@ -18,11 +18,10 @@ public OrderReview GetOrderReviewById(int id) return connection.Query ("dbo.OrderReview_SelectById", (orderreview, order, client) => { - orderreview.Order = order; - //orderreview.Client = client; + orderreview.Order = order; return orderreview; }, - new { Id = id }, + new { id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). FirstOrDefault(); @@ -36,10 +35,9 @@ public List GetOrderReviewsByOrderId(int id) ("dbo.OrderReview_SelectByOrderId", (orderreview, order, client) => { orderreview.Order = order; - //orderreview.Client = client; return orderreview; }, - new { OrderId = id }, + new { OrderId=id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). Distinct().ToList(); @@ -59,7 +57,7 @@ public void DeleteOrderReview(int id) using var connection = ProvideConnection(); string procString = "dbo.OrderReview_Delete"; connection.Execute(procString, - new { Id = id }, + new { id }, commandType: CommandType.StoredProcedure); } @@ -67,7 +65,7 @@ public void DeleteOrderReviewByOrderId(int orderId) { using var connection = ProvideConnection(); string procString = "dbo.OrderReview_DeleteByOrderId"; - connection.Execute(procString, new { OrderId = orderId }, + connection.Execute(procString, new { orderId }, commandType: CommandType.StoredProcedure); } @@ -75,7 +73,7 @@ public void EditOrderReview(int id, string text) { using var connection = ProvideConnection(); string procString = "dbo.OrderReview_Update"; - connection.Execute(procString, new { Id = id, Text = text }, + connection.Execute(procString, new { id, text }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index 56b933d..7075961 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -28,7 +28,7 @@ - + From 995839990968020fa0585842758614aad4daa344 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Sun, 9 Jan 2022 21:46:51 +0300 Subject: [PATCH 06/17] Added new grid for edit of order, new commands --- Alligator.BusinessLayer/OrderService.cs | 4 +- Alligator.DB/Procedures/Order_Update.sql | 4 +- .../Repositories/IOrderRepository.cs | 2 +- .../Repositories/OrderRepository.cs | 4 +- .../AddProductWindowOfChangeOrderCommand.cs | 58 +++++++++ .../ComeBackFirstWindowCommand.cs | 1 + ...ackFirstWindowFromAddOrderWindowCommand.cs | 1 + ...OfOrderInfoFromChangeOrderWindowCommand.cs | 28 +++++ ...rInfoCommand.cs => DeleteDetailCommand.cs} | 4 +- .../OpenAddOrderWindowCommand.cs | 1 + ...OpenChangeOrderWindowOfOrderInfoCommand.cs | 60 +++++++++ .../OpenOrderInfoWindowCommand.cs | 1 + .../TabItemOrders/SaveChangedOrderCommand.cs | 58 +++++++++ .../SaveChangesWindowOfOrderInfoCommand.cs | 37 ------ Alligator/TabItems/TabItemOrders.xaml | 115 +++++++++++++++++- Alligator/TabItems/TabItemOrders.xaml.cs | 1 + .../TabItemOrdersViewModel.cs | 112 +++++++++++++++-- 17 files changed, 430 insertions(+), 61 deletions(-) create mode 100644 Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs create mode 100644 Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs rename Alligator/Commands/TabItemOrders/{DeleteDetailWindowOfOrderInfoCommand.cs => DeleteDetailCommand.cs} (82%) create mode 100644 Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs create mode 100644 Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs delete mode 100644 Alligator/Commands/TabItemOrders/SaveChangesWindowOfOrderInfoCommand.cs diff --git a/Alligator.BusinessLayer/OrderService.cs b/Alligator.BusinessLayer/OrderService.cs index ff13ca7..4bed749 100644 --- a/Alligator.BusinessLayer/OrderService.cs +++ b/Alligator.BusinessLayer/OrderService.cs @@ -63,9 +63,9 @@ public void DeleteOrderModel(int id) _repositoryOrder.DeleteOrder(id); } - public void EditOrderModel(DateTime date, int id, string address) + public void EditOrderModel(DateTime date, int orderId, int clientId, string address) { - _repositoryOrder.EditOrder(date, id, address); + _repositoryOrder.EditOrder(date, orderId, clientId, address); } } } diff --git a/Alligator.DB/Procedures/Order_Update.sql b/Alligator.DB/Procedures/Order_Update.sql index c463e54..b9e28c3 100644 --- a/Alligator.DB/Procedures/Order_Update.sql +++ b/Alligator.DB/Procedures/Order_Update.sql @@ -1,10 +1,12 @@ create proc dbo.Order_Update @Id int, +@ClientId int, @Address varchar(200), @Date date AS BEGIN - update dbo.[Order] set Address=@Address, + update dbo.[Order] set ClientId=@ClientId, + Address=@Address, Date=@Date where Id=@Id END \ No newline at end of file diff --git a/Alligator.DataLayer/Repositories/IOrderRepository.cs b/Alligator.DataLayer/Repositories/IOrderRepository.cs index ff57508..d8ea6b9 100644 --- a/Alligator.DataLayer/Repositories/IOrderRepository.cs +++ b/Alligator.DataLayer/Repositories/IOrderRepository.cs @@ -8,7 +8,7 @@ public interface IOrderRepository { int AddOrder(DateTime date, int clientId, string address); void DeleteOrder(int id); - void EditOrder(DateTime date, int id, string address); + void EditOrder(DateTime date, int orderId, int clientId, string address); List GetAllOrders(); Order GetOrderById(int id); List GetOrdersByClientId(int id); diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 8e561cd..4383bbd 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -71,12 +71,12 @@ public void DeleteOrder(int id) commandType: CommandType.StoredProcedure); } - public void EditOrder(DateTime date, int id, string address) + public void EditOrder(DateTime date, int orderId, int clientId, string address) { using var connection = ProvideConnection(); string procString = "dbo.Order_Update"; connection.Execute(procString, - new { date, id, address }, + new { date, orderId, clientId, address }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs new file mode 100644 index 0000000..bc35b86 --- /dev/null +++ b/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs @@ -0,0 +1,58 @@ +using Alligator.BusinessLayer; +using Alligator.BusinessLayer.Models; +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Alligator.UI.Commands.TabItemOrders +{ + class AddProductWindowOfChangeOrderCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + private OrderDetailService _orderDetailService; + public AddProductWindowOfChangeOrderCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) + { + _viewModel = viewModel; + _orderDetailService = orderDetailService; + } + + public override void Execute(object parameter) + { + var newAmount = _viewModel.NewAmount; + if (!int.TryParse(newAmount, out _) || string.IsNullOrEmpty(newAmount)) + { + MessageBox.Show("Введите количество продуктов"); + return; + } + int amount = Convert.ToInt32(newAmount); + + if (_viewModel.SelectedProduct is null) + { + MessageBox.Show("Выберите продукт"); + return; + } + if (_viewModel.SelectedOrder.OrderDetails is null) + { + List orderDetails = new List(); + + _viewModel.SelectedOrder.OrderDetails = orderDetails; + } + if (_viewModel.OrderDetails is null) + { + _viewModel.OrderDetails = new ObservableCollection(); + } + + var orderDetail = new OrderDetailModel() { Product = _viewModel.SelectedProduct, Amount = amount, Order = _viewModel.SelectedOrder }; + _viewModel.SelectedOrder.OrderDetails.Add(orderDetail); + _viewModel.OrderDetails.Add(orderDetail); + _orderDetailService.AddOrderDetailModel(amount, _viewModel.SelectedOrder.Id, _viewModel.SelectedProduct.Id); + } + } + + } + diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs index 36a5078..db0a5bb 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs @@ -21,6 +21,7 @@ public override void Execute(object parameter) { _viewModel.AddOrderWindowVisibility= Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersWindowVisibility = Visibility.Visible; } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs index 7a17fa3..a137913 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs @@ -21,6 +21,7 @@ public override void Execute(object parameter) { _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersWindowVisibility = Visibility.Visible; _viewModel.NewReviewText = string.Empty; _viewModel.NewAmount = string.Empty; diff --git a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs new file mode 100644 index 0000000..e10257e --- /dev/null +++ b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs @@ -0,0 +1,28 @@ +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Alligator.UI.Commands.TabItemOrders +{ + class ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + + public ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(TabItemOrdersViewModel viewModel) + { + _viewModel = viewModel; + } + + public override void Execute(object parameter) + { + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + } + } +} diff --git a/Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs similarity index 82% rename from Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs rename to Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs index c6dde79..d4038e6 100644 --- a/Alligator/Commands/TabItemOrders/DeleteDetailWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs @@ -8,14 +8,14 @@ namespace Alligator.UI.Commands.TabItemOrders { - class DeleteDetailWindowOfOrderInfoCommand : CommandBase + class DeleteDetailCommand : CommandBase { private TabItemOrdersViewModel _viewModel; private OrderDetailService _orderDetailService; - public DeleteDetailWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) + public DeleteDetailCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) { _viewModel = viewModel; _orderDetailService = orderDetailService; diff --git a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs index 76e32e8..76b0b72 100644 --- a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs @@ -44,6 +44,7 @@ public override void Execute(object parameter) //} _viewModel.OrdersWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.AddOrderWindowVisibility = Visibility.Visible; } } diff --git a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs new file mode 100644 index 0000000..2b1705a --- /dev/null +++ b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs @@ -0,0 +1,60 @@ +using Alligator.BusinessLayer; +using Alligator.BusinessLayer.Models; +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Alligator.UI.Commands.TabItemOrders +{ + public class OpenChangeOrderWindowOfOrderInfoCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + private OrderService _orderService; + private OrderDetailService _orderDetailService; + private OrderReviewService _orderReviewService; + private ClientService _clientService; + //private ProductService _productService; + + + public OpenChangeOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService, ClientService clientService) + { + _viewModel = viewModel; + _orderService = orderService; + _orderReviewService = orderReviewService; + _orderDetailService = orderDetailService; + _clientService = clientService; + } + + public override void Execute(object parameter) + { + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Visible; + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + _viewModel.ChangedDate = _viewModel.SelectedOrder.Date; + _viewModel.ChangedAddressText = _viewModel.SelectedOrder.Address; + _viewModel.Clients.Clear(); + if (_clientService.GetAllClients().Success is true) + { + var clients = _clientService.GetAllClients().Data; + foreach (var client in clients) + _viewModel.Clients.Add(client); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } + _viewModel.SelectedChangeClient = _viewModel.SelectedOrder.Client; + //пока нет productServic'а + //foreach (var product in _productService.GetAllProducts()) + //{ + // _viewModel.Products.Add(product); + //} + } + } +} diff --git a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs index fea4aa2..f6442b3 100644 --- a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs @@ -30,6 +30,7 @@ public override void Execute(object parameter) { _viewModel.OrdersWindowVisibility = Visibility.Collapsed; _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility= Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs new file mode 100644 index 0000000..d9400f3 --- /dev/null +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -0,0 +1,58 @@ +using Alligator.BusinessLayer; +using Alligator.BusinessLayer.Models; +using Alligator.UI.VIewModels.TabItemsViewModels; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Alligator.UI.Commands.TabItemOrders +{ + class SaveChangedOrderCommand : CommandBase + { + private TabItemOrdersViewModel _viewModel; + private OrderService _orderService; + + public SaveChangedOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderService) + { + _viewModel = viewModel; + _orderService = orderService; + } + + public override void Execute(object parameter) + { + var address = _viewModel.ChangedAddressText; + if (string.IsNullOrEmpty(address)) + { + MessageBox.Show("Введите адрес"); + _viewModel.NewAddressText = string.Empty; + } + address = _viewModel.ChangedAddressText.Trim(); + + if (_viewModel.SelectedClient is null) + { + MessageBox.Show("Выберите клиента"); + return; + } + + if (_viewModel.SelectedOrder.OrderDetails.Count==0) + { + MessageBox.Show("Выберите продукты и их количество"); + return; + } + _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedClient.Id, address); + _viewModel.SelectedOrder.Address = address; + _viewModel.SelectedOrder.Date = _viewModel.ChangedDate; + _viewModel.SelectedOrder.Client = _viewModel.SelectedClient; + //добавить сообщение, что всё успешно сохранено + //и проверку на связь с БД + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + } + } +} diff --git a/Alligator/Commands/TabItemOrders/SaveChangesWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangesWindowOfOrderInfoCommand.cs deleted file mode 100644 index 385ef37..0000000 --- a/Alligator/Commands/TabItemOrders/SaveChangesWindowOfOrderInfoCommand.cs +++ /dev/null @@ -1,37 +0,0 @@ -using Alligator.BusinessLayer; -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Alligator.UI.Commands.TabItemOrders -{ - public class SaveChangesWindowOfOrderInfoCommand : CommandBase - { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - private OrderDetailService _orderDetailService; - private OrderReviewService _orderReviewService; - - public SaveChangesWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService) - { - _viewModel = viewModel; - _orderService = orderService; - _orderReviewService = orderReviewService; - _orderDetailService = orderDetailService; - } - - public override void Execute(object parameter) - { - _orderService.EditOrderModel(_viewModel.SelectedOrder.Date, _viewModel.SelectedOrder.Id, _viewModel.SelectedOrder.Address); - _orderDetailService.EditOrderDetailModel(_viewModel.SelectedOrderDetail.Id, _viewModel.SelectedOrderDetail.Amount); - _orderReviewService.EditOrderReviewModel(_viewModel.SelectedOrderReview.Id, _viewModel.SelectedOrderReview.Text); - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Visible; - } - } -} diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index 7075961..10542c3 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -115,8 +115,8 @@ - - + + @@ -132,7 +132,7 @@ - + @@ -143,7 +143,7 @@ - + @@ -255,6 +255,113 @@ + + + + + + + + + + + + + + + + + + + Дата + Клиент + Адрес + Продукты + Количество + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Alligator/TabItems/TabItemOrders.xaml.cs b/Alligator/TabItems/TabItemOrders.xaml.cs index f0bd384..6c15e60 100644 --- a/Alligator/TabItems/TabItemOrders.xaml.cs +++ b/Alligator/TabItems/TabItemOrders.xaml.cs @@ -19,6 +19,7 @@ public TabItemOrders() DataContext = _viewModel; _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; //_viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; //_viewModel.AddOrderWindowVisibility = Visibility.Visible; //_viewModel.OrdersWindowVisibility = Visibility.Collapsed; diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 49653fc..033a342 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -26,31 +26,36 @@ public class TabItemOrdersViewModel : BaseViewModel private OrderReviewModel _selectedNewOrderReviewModel; private ProductModel _selectedProduct; private ClientModel _selectedClient; + private ClientModel _selectedChangeClient; private readonly OrderService _orderService; private readonly OrderReviewService _orderReviewService; private readonly OrderDetailService _orderDetailService; private readonly ClientService _clientService; private string _newReviewText; private string _newAdressText; + private string _changedAddressText; private DateTime _newDate; - - public ICommand AddReviewWindowOfOrderInfo { get; set; } - public ICommand DeleteReviewWindowOfOrderInfo { get; set; } + private DateTime _changedDate; + public ICommand AddReview { get; set; } + public ICommand DeleteReview { get; set; } public ICommand GetOrders { get; set; } public ICommand GetOrderInfo { get; set; } public ICommand DeleteOrderWindowOfAllOrders { get; set; } public ICommand DeleteOrderWindowOfOrderInfo { get; set; } public ICommand AddOrder { get; set; } - public ICommand SaveChangesWindowOfOrderInfo { get; set; } + public ICommand ChangeOrderWindowOfOrderInfo { get; set; } public ICommand OpenAddOrderWindow { get; set; } public ICommand OpenOrderInfoWindow { get; set; } public ICommand ComeBackFirstWindow { get; set; } public ICommand AddReviewWindowOfAddOrder { get; set; } public ICommand DeleteReviewWindowOfAddOrder { get; set; } public ICommand AddProductWindowOfAddOrder { get; set; } - public ICommand DeleteDetailWindowOfOrderInfo { get; set; } + public ICommand DeleteDetail { get; set; } public ICommand DeleteNewDetail { get; set; } public ICommand ComeBackFirstWindowFromAddOrderWindow { get; set; } + public ICommand ComeBackWindowOfOrderInfoFromChangeOrderWindow { get; set; } + public ICommand AddProductWindowOfChangeOrder { get; set; } + public ICommand SaveChangedOrder { get; set; } public TabItemOrdersViewModel() { @@ -65,26 +70,31 @@ public TabItemOrdersViewModel() Clients = new ObservableCollection(); Products = new ObservableCollection(); NewOrderReviews = new ObservableCollection(); + ChangeOrderReviews = new ObservableCollection(); OrderReviews = new ObservableCollection(); OrderDetails = new ObservableCollection(); NewOrderDetails = new ObservableCollection(); - - AddReviewWindowOfOrderInfo = new AddReviewWindowOfOrderInfoCommand(this, _orderReviewService); - DeleteReviewWindowOfOrderInfo = new DeleteReviewWindowOfOrderInfoCommand(this, _orderReviewService); + ChangeOrderDetails = new ObservableCollection(); + ChangeOrderReviews = new ObservableCollection(); + AddReview = new AddReviewWindowOfOrderInfoCommand(this, _orderReviewService); + DeleteReview = new DeleteReviewWindowOfOrderInfoCommand(this, _orderReviewService); GetOrders = new GetOrdersCommand(this, _orderService); DeleteOrderWindowOfAllOrders = new DeleteOrderWindowOfAllOrdersCommand(this, _orderService, _orderDetailService, _orderReviewService); DeleteOrderWindowOfOrderInfo=new DeleteOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService); AddOrder = new AddOrderCommand(this, _orderService, _orderReviewService, _orderDetailService); - SaveChangesWindowOfOrderInfo = new SaveChangesWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService); + ChangeOrderWindowOfOrderInfo = new OpenChangeOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService, _clientService); OpenAddOrderWindow = new OpenAddOrderWindowCommand(this, _clientService); OpenOrderInfoWindow = new OpenOrderInfoWindowCommand(this, _orderService); ComeBackFirstWindow = new ComeBackFirstWindowCommand(this); AddReviewWindowOfAddOrder = new AddReviewWindowOfAddOrderCommand(this); DeleteReviewWindowOfAddOrder = new DeleteReviewWindowOfAddOrderCommand(this); AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); - DeleteDetailWindowOfOrderInfo = new DeleteDetailWindowOfOrderInfoCommand(this, _orderDetailService); + DeleteDetail = new DeleteDetailCommand(this, _orderDetailService); DeleteNewDetail = new DeleteNewDetailCommand(this); + AddProductWindowOfChangeOrder = new AddProductWindowOfChangeOrderCommand(this, _orderDetailService); ComeBackFirstWindowFromAddOrderWindow = new ComeBackFirstWindowFromAddOrderWindowCommand(this); + ComeBackWindowOfOrderInfoFromChangeOrderWindow = new ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(this); + SaveChangedOrder = new SaveChangedOrderCommand(this, _orderService); } @@ -121,6 +131,17 @@ public ObservableCollection NewOrderDetails OnPropertyChanged(nameof(NewOrderDetails)); } } + + private ObservableCollection _changeOrderDetails; + public ObservableCollection ChangeOrderDetails + { + get { return _changeOrderDetails; } + set + { + _changeOrderDetails = value; + OnPropertyChanged(nameof(ChangeOrderDetails)); + } + } private ObservableCollection _newOrderReviews; public ObservableCollection NewOrderReviews @@ -133,6 +154,18 @@ public ObservableCollection NewOrderReviews } } + + private ObservableCollection _changeOrderReviews; + public ObservableCollection ChangeOrderReviews + { + get { return _changeOrderReviews; } + set + { + _changeOrderReviews = value; + OnPropertyChanged(nameof(ChangeOrderReviews)); + } + } + private OrderModel _newOrder; public OrderModel NewOrder { @@ -182,7 +215,7 @@ public OrderDetailModel SelectedOrderDetail set { _selectedOrderDetailModel = value; - ((CommandBase)DeleteDetailWindowOfOrderInfo).RaiseCanExecuteChanged(); + ((CommandBase)DeleteDetail).RaiseCanExecuteChanged(); OnPropertyChanged(nameof(SelectedOrderDetail)); } } @@ -192,10 +225,20 @@ public OrderReviewModel SelectedOrderReview set { _selectedOrderReviewModel = value; - ((CommandBase)DeleteReviewWindowOfOrderInfo).RaiseCanExecuteChanged(); + ((CommandBase)DeleteReview).RaiseCanExecuteChanged(); OnPropertyChanged(nameof(SelectedOrderReview)); } } + public OrderReviewModel SelectedChangeOrderReview + { + get { return _selectedOrderReviewModel; } + set + { + _selectedOrderReviewModel = value; + //((CommandBase)DeleteReviewWindowOfOrderInfo).RaiseCanExecuteChanged(); + OnPropertyChanged(nameof(SelectedChangeOrderReview)); + } + } public OrderDetailModel SelectedNewOrderDetail { @@ -228,6 +271,17 @@ public ClientModel SelectedClient } } + + public ClientModel SelectedChangeClient + { + get { return _selectedChangeClient; } + set + { + _selectedChangeClient = value; + OnPropertyChanged(nameof(SelectedChangeClient)); + } + } + public ProductModel SelectedProduct { get { return _selectedProduct; } @@ -257,6 +311,15 @@ public string NewAddressText OnPropertyChanged(nameof(NewAddressText)); } } + public string ChangedAddressText + { + get { return _changedAddressText; } + set + { + _changedAddressText = value; + OnPropertyChanged(nameof(ChangedAddressText)); + } + } public DateTime NewDate { @@ -268,6 +331,16 @@ public DateTime NewDate } } + public DateTime ChangedDate + { + get { return _changedDate; } + set + { + _changedDate = value; + OnPropertyChanged(nameof(ChangedDate)); + } + } + private string _newAmount; public string NewAmount { @@ -321,6 +394,21 @@ public Visibility AddOrderWindowVisibility } } + private Visibility _changeOrderWindowVisibility; + public Visibility ChangeOrderWindowVisibility + { + get + { + return _changeOrderWindowVisibility; + } + set + { + _changeOrderWindowVisibility = value; + + OnPropertyChanged(nameof(ChangeOrderWindowVisibility)); + } + } + private Visibility _buttonOpenOrderInfo; public Visibility ButtonOpenOrderInfo { From 8991c13bf42f884a6e5a44c21199caf5882ee55e Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 00:06:40 +0300 Subject: [PATCH 07/17] Fixed binding of clients (changed StoredProcedures, OrderRepository) --- Alligator.DB/Procedures/Order_SelectAll.sql | 12 +++++++----- Alligator.DataLayer/Repositories/OrderRepository.cs | 9 +++++++-- .../OpenChangeOrderWindowOfOrderInfoCommand.cs | 1 + .../TabItemOrders/SaveChangedOrderCommand.cs | 6 +++--- .../TabItemsViewModels/TabItemOrdersViewModel.cs | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Alligator.DB/Procedures/Order_SelectAll.sql b/Alligator.DB/Procedures/Order_SelectAll.sql index d7c4c46..5b6c154 100644 --- a/Alligator.DB/Procedures/Order_SelectAll.sql +++ b/Alligator.DB/Procedures/Order_SelectAll.sql @@ -2,9 +2,11 @@ AS BEGIN select - id, - date, - Address, - ClientId - from dbo.[Order] + o.id, + o.date, + o.Address, + c.Id, + c.FirstName, + c.LastName + from dbo.[Order] o inner join dbo.[Client] c on o.ClientId=c.Id END \ No newline at end of file diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 4383bbd..9dbef06 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -17,7 +17,12 @@ public List GetAllOrders() { using var connection = ProvideConnection(); var orderDictionary = new Dictionary(); - return connection.Query("dbo.Order_SelectAll", + return connection.Query("dbo.Order_SelectAll", (order, client) => + { + order.Client = client; + + return order; + }, commandType: CommandType.StoredProcedure) .ToList(); } @@ -76,7 +81,7 @@ public void EditOrder(DateTime date, int orderId, int clientId, string address) using var connection = ProvideConnection(); string procString = "dbo.Order_Update"; connection.Execute(procString, - new { date, orderId, clientId, address }, + new { date, Id=orderId, clientId, address }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs index 2b1705a..b4d72fa 100644 --- a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs @@ -50,6 +50,7 @@ public override void Execute(object parameter) MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); } _viewModel.SelectedChangeClient = _viewModel.SelectedOrder.Client; + _viewModel.SelectedOrder.OrderDetails = _orderDetailService.GetOrderDetailsByOrderId(_viewModel.SelectedOrder.Id); //пока нет productServic'а //foreach (var product in _productService.GetAllProducts()) //{ diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs index d9400f3..1cb9572 100644 --- a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -32,18 +32,18 @@ public override void Execute(object parameter) } address = _viewModel.ChangedAddressText.Trim(); - if (_viewModel.SelectedClient is null) + if (_viewModel.SelectedChangeClient is null) { MessageBox.Show("Выберите клиента"); return; } - if (_viewModel.SelectedOrder.OrderDetails.Count==0) + if (_viewModel.SelectedOrder.OrderDetails.Count == 0) { MessageBox.Show("Выберите продукты и их количество"); return; } - _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedClient.Id, address); + _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address); _viewModel.SelectedOrder.Address = address; _viewModel.SelectedOrder.Date = _viewModel.ChangedDate; _viewModel.SelectedOrder.Client = _viewModel.SelectedClient; diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 033a342..0291573 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -132,7 +132,7 @@ public ObservableCollection NewOrderDetails } } - private ObservableCollection _changeOrderDetails; + private ObservableCollection _changeOrderDetails; public ObservableCollection ChangeOrderDetails { get { return _changeOrderDetails; } @@ -272,7 +272,7 @@ public ClientModel SelectedClient } - public ClientModel SelectedChangeClient + public ClientModel SelectedChangeClient { get { return _selectedChangeClient; } set From 27d4f8c564daa5e041fb21090be382ea397d9870 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 01:26:22 +0300 Subject: [PATCH 08/17] removed unneeded viewModels (in folder "Entities"), edit commands & xaml --- .../ComeBackFirstWindowCommand.cs | 14 +++- ...ackFirstWindowFromAddOrderWindowCommand.cs | 12 ++- ...OfOrderInfoFromChangeOrderWindowCommand.cs | 17 +++- .../OpenOrderInfoWindowCommand.cs | 3 + .../TabItemOrders/SaveChangedOrderCommand.cs | 8 +- Alligator/TabItems/TabItemOrders.xaml | 9 +- Alligator/TabItems/TabItemOrders.xaml.cs | 5 +- .../OrderDetailViewModel.cs | 64 -------------- .../OrderReviewViewModel.cs | 63 -------------- .../EntitiesViewModels/OrderViewModel.cs | 83 ------------------ .../EntitiesViewModels/OrderViewShortModel.cs | 61 -------------- .../TabItemOrdersViewModel.cs | 84 +++++++++---------- 12 files changed, 90 insertions(+), 333 deletions(-) delete mode 100644 Alligator/VIewModels/EntitiesViewModels/OrderDetailViewModel.cs delete mode 100644 Alligator/VIewModels/EntitiesViewModels/OrderReviewViewModel.cs delete mode 100644 Alligator/VIewModels/EntitiesViewModels/OrderViewModel.cs delete mode 100644 Alligator/VIewModels/EntitiesViewModels/OrderViewShortModel.cs diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs index db0a5bb..27865b8 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs @@ -1,4 +1,5 @@ -using Alligator.UI.VIewModels.TabItemsViewModels; +using Alligator.BusinessLayer; +using Alligator.UI.VIewModels.TabItemsViewModels; using System; using System.Collections.Generic; using System.Linq; @@ -11,10 +12,12 @@ namespace Alligator.UI.Commands.TabItemOrders public class ComeBackFirstWindowCommand : CommandBase { private TabItemOrdersViewModel _viewModel; + private OrderService _orderService; - public ComeBackFirstWindowCommand(TabItemOrdersViewModel viewModel) + public ComeBackFirstWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { _viewModel = viewModel; + _orderService = orderService; } public override void Execute(object parameter) @@ -22,7 +25,12 @@ public override void Execute(object parameter) _viewModel.AddOrderWindowVisibility= Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Visible; + _viewModel.OrdersWindowVisibility = Visibility.Visible; + _viewModel.AllOrders.Clear(); + foreach (var order in _orderService.GetOrders()) + { + _viewModel.AllOrders.Add(order); + } } } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs index a137913..fb20d9c 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs @@ -1,4 +1,5 @@ -using Alligator.UI.VIewModels.TabItemsViewModels; +using Alligator.BusinessLayer; +using Alligator.UI.VIewModels.TabItemsViewModels; using System; using System.Collections.Generic; using System.Linq; @@ -11,10 +12,12 @@ namespace Alligator.UI.Commands.TabItemOrders class ComeBackFirstWindowFromAddOrderWindowCommand : CommandBase { private TabItemOrdersViewModel _viewModel; + private OrderService _orderService; - public ComeBackFirstWindowFromAddOrderWindowCommand(TabItemOrdersViewModel viewModel) + public ComeBackFirstWindowFromAddOrderWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { _viewModel = viewModel; + _orderService = orderService; } public override void Execute(object parameter) @@ -28,6 +31,11 @@ public override void Execute(object parameter) _viewModel.NewAddressText = string.Empty; _viewModel.NewOrderReviews.Clear(); _viewModel.NewOrderDetails.Clear(); + _viewModel.AllOrders.Clear(); + foreach (var order in _orderService.GetOrders()) + { + _viewModel.AllOrders.Add(order); + } } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs index e10257e..055d935 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs @@ -1,6 +1,9 @@ -using Alligator.UI.VIewModels.TabItemsViewModels; +using Alligator.BusinessLayer; +using Alligator.BusinessLayer.Models; +using Alligator.UI.VIewModels.TabItemsViewModels; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,10 +14,12 @@ namespace Alligator.UI.Commands.TabItemOrders class ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand : CommandBase { private TabItemOrdersViewModel _viewModel; + private OrderService _orderService; - public ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(TabItemOrdersViewModel viewModel) + public ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { _viewModel = viewModel; + _orderService = orderService; } public override void Execute(object parameter) @@ -22,7 +27,13 @@ public override void Execute(object parameter) _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); + _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; + _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; + _viewModel.SelectedOrderClient.FirstName = _viewModel.SelectedOrder.Client.FirstName; } } } diff --git a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs index f6442b3..03b3ed1 100644 --- a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs @@ -35,6 +35,9 @@ public override void Execute(object parameter) var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; + _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; + _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; } } } diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs index 1cb9572..faec20b 100644 --- a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -43,10 +43,16 @@ public override void Execute(object parameter) MessageBox.Show("Выберите продукты и их количество"); return; } - _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address); _viewModel.SelectedOrder.Address = address; _viewModel.SelectedOrder.Date = _viewModel.ChangedDate; _viewModel.SelectedOrder.Client = _viewModel.SelectedClient; + _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address); + var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); + _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; + _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; + _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; //добавить сообщение, что всё успешно сохранено //и проверку на связь с БД _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index 10542c3..f2fd9a1 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -77,9 +77,9 @@ - - - + + + @@ -199,8 +199,7 @@ - - + diff --git a/Alligator/TabItems/TabItemOrders.xaml.cs b/Alligator/TabItems/TabItemOrders.xaml.cs index 6c15e60..49c7eef 100644 --- a/Alligator/TabItems/TabItemOrders.xaml.cs +++ b/Alligator/TabItems/TabItemOrders.xaml.cs @@ -19,10 +19,7 @@ public TabItemOrders() DataContext = _viewModel; _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - //_viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - //_viewModel.AddOrderWindowVisibility = Visibility.Visible; - //_viewModel.OrdersWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; } } } diff --git a/Alligator/VIewModels/EntitiesViewModels/OrderDetailViewModel.cs b/Alligator/VIewModels/EntitiesViewModels/OrderDetailViewModel.cs deleted file mode 100644 index d142f68..0000000 --- a/Alligator/VIewModels/EntitiesViewModels/OrderDetailViewModel.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Alligator.BusinessLayer.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace Alligator.UI.VIewModels.EntitiesViewModels -{ - class OrderDetailViewModel: BaseViewModel - { - private int _id; - - public int Id - { - get => _id; - set - { - _id = value; - OnPropertyChanged(nameof(Id)); - } - } - - private OrderModel _order; - - public OrderModel Order - { - get => _order; - set - { - _order = value; - OnPropertyChanged(nameof(Order)); - } - } - - private ProductModel _product; - - public ProductModel Product - { - get => _product; - set - { - _product = value; - OnPropertyChanged(nameof(Product)); - } - } - - private int _amount; - - public int Amount - { - get => _amount; - set - { - _amount = value; - OnPropertyChanged(nameof(Amount)); - } - } - - - } -} diff --git a/Alligator/VIewModels/EntitiesViewModels/OrderReviewViewModel.cs b/Alligator/VIewModels/EntitiesViewModels/OrderReviewViewModel.cs deleted file mode 100644 index b569db1..0000000 --- a/Alligator/VIewModels/EntitiesViewModels/OrderReviewViewModel.cs +++ /dev/null @@ -1,63 +0,0 @@ -using Alligator.BusinessLayer.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace Alligator.UI.VIewModels.EntitiesViewModels -{ - class OrderReviewViewModel : BaseViewModel - { - - private int _id; - - public int Id - { - get => _id; - set - { - _id = value; - OnPropertyChanged(nameof(Id)); - } - } - - private OrderModel _order; - - public OrderModel Order - { - get => _order; - set - { - _order = value; - OnPropertyChanged(nameof(Order)); - } - } - - private ClientModel _clientModel; - - public ClientModel Client - { - get => _clientModel; - set - { - _clientModel = value; - OnPropertyChanged(nameof(Client)); - } - } - - private string _text; - public string Text - { - get => _text; - set - { - _text = value; - OnPropertyChanged(nameof(Text)); - } - } - - } -} diff --git a/Alligator/VIewModels/EntitiesViewModels/OrderViewModel.cs b/Alligator/VIewModels/EntitiesViewModels/OrderViewModel.cs deleted file mode 100644 index a128c6c..0000000 --- a/Alligator/VIewModels/EntitiesViewModels/OrderViewModel.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Alligator.BusinessLayer.Models; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace Alligator.UI.VIewModels.EntitiesViewModels -{ - public class OrderViewModel: BaseViewModel - { - - private int _id; - private DateTime _date; - private ClientModel _clientModel; - private string _address; - private ObservableCollection _orderDetails; - private ObservableCollection orderReviews; - public int Id - { - get => _id; - set - { - _id = value; - OnPropertyChanged(nameof(Id)); - } - } - - public DateTime Date - { - get => _date; - set - { - _date = value; - OnPropertyChanged(nameof(Date)); - } - } - - public ClientModel Client - { - get => _clientModel; - set - { - _clientModel = value; - OnPropertyChanged(nameof(Client)); - } - } - - public string Address - { - get => _address; - set - { - _address = value; - OnPropertyChanged(nameof(Address)); - } - } - - public ObservableCollection OrderDetails - { - get => _orderDetails; - set - { - _orderDetails = value; - OnPropertyChanged(nameof(OrderDetails)); - } - } - - public ObservableCollection OrderReviews - { - get => orderReviews; - set - { - orderReviews = value; - OnPropertyChanged(nameof(OrderReviews)); - } - } - - } -} diff --git a/Alligator/VIewModels/EntitiesViewModels/OrderViewShortModel.cs b/Alligator/VIewModels/EntitiesViewModels/OrderViewShortModel.cs deleted file mode 100644 index 489433f..0000000 --- a/Alligator/VIewModels/EntitiesViewModels/OrderViewShortModel.cs +++ /dev/null @@ -1,61 +0,0 @@ -using Alligator.BusinessLayer.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace Alligator.UI.VIewModels.EntitiesViewModels -{ - public class OrderViewShortModel : BaseViewModel - { - private int _id; - public int Id - { - get { return _id; } - set - { - _id = value; - OnPropertyChanged(nameof(Id)); - } - } - - private DateTime _date; - - public DateTime Date - { - get { return _date; } - set - { - _date = value; - OnPropertyChanged(nameof(Date)); - } - } - - - private string _address; - - public string Address - { - get { return _address; } - set - { - _address = value; - OnPropertyChanged(nameof(Address)); - } - } - - private int _clientId; - public int ClientId - { - get { return _clientId; } - set - { - _clientId = value; - OnPropertyChanged(nameof(ClientId)); - } - } - } -} diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index c9ee053..035bdcc 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -21,6 +21,9 @@ public class TabItemOrdersViewModel : BaseViewModel private ProductModel _selectedProduct; private ClientModel _selectedClient; private ClientModel _selectedChangeClient; + private ClientModel _selectedOrderClient; + private string _selectedOrderAddress; + private DateTime _selectedOrderDate; private readonly OrderService _orderService; private readonly OrderReviewService _orderReviewService; private readonly OrderDetailService _orderDetailService; @@ -57,19 +60,14 @@ public TabItemOrdersViewModel() _orderReviewService = new OrderReviewService(); _orderDetailService = new OrderDetailService(); _clientService = new ClientService(); - - //NewOrder = new OrderModel(); AllOrders = new ObservableCollection(); Clients = new ObservableCollection(); Products = new ObservableCollection(); NewOrderReviews = new ObservableCollection(); - ChangeOrderReviews = new ObservableCollection(); OrderReviews = new ObservableCollection(); OrderDetails = new ObservableCollection(); - NewOrderDetails = new ObservableCollection(); - ChangeOrderDetails = new ObservableCollection(); - ChangeOrderReviews = new ObservableCollection(); + NewOrderDetails = new ObservableCollection(); AddReview = new AddReviewWindowOfOrderInfoCommand(this, _orderReviewService); DeleteReview = new DeleteReviewWindowOfOrderInfoCommand(this, _orderReviewService); GetOrders = new GetOrdersCommand(this, _orderService); @@ -79,15 +77,15 @@ public TabItemOrdersViewModel() ChangeOrderWindowOfOrderInfo = new OpenChangeOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService, _clientService); OpenAddOrderWindow = new OpenAddOrderWindowCommand(this, _clientService); OpenOrderInfoWindow = new OpenOrderInfoWindowCommand(this, _orderService); - ComeBackFirstWindow = new ComeBackFirstWindowCommand(this); + ComeBackFirstWindow = new ComeBackFirstWindowCommand(this, _orderService); AddReviewWindowOfAddOrder = new AddReviewWindowOfAddOrderCommand(this); DeleteReviewWindowOfAddOrder = new DeleteReviewWindowOfAddOrderCommand(this); AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); DeleteDetail = new DeleteDetailCommand(this, _orderDetailService); DeleteNewDetail = new DeleteNewDetailCommand(this); AddProductWindowOfChangeOrder = new AddProductWindowOfChangeOrderCommand(this, _orderDetailService); - ComeBackFirstWindowFromAddOrderWindow = new ComeBackFirstWindowFromAddOrderWindowCommand(this); - ComeBackWindowOfOrderInfoFromChangeOrderWindow = new ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(this); + ComeBackFirstWindowFromAddOrderWindow = new ComeBackFirstWindowFromAddOrderWindowCommand(this, _orderService); + ComeBackWindowOfOrderInfoFromChangeOrderWindow = new ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(this, _orderService); SaveChangedOrder = new SaveChangedOrderCommand(this, _orderService); } @@ -126,17 +124,6 @@ public ObservableCollection NewOrderDetails } } - private ObservableCollection _changeOrderDetails; - public ObservableCollection ChangeOrderDetails - { - get { return _changeOrderDetails; } - set - { - _changeOrderDetails = value; - OnPropertyChanged(nameof(ChangeOrderDetails)); - } - } - private ObservableCollection _newOrderReviews; public ObservableCollection NewOrderReviews { @@ -147,19 +134,7 @@ public ObservableCollection NewOrderReviews OnPropertyChanged(nameof(NewOrderReviews)); } } - - - private ObservableCollection _changeOrderReviews; - public ObservableCollection ChangeOrderReviews - { - get { return _changeOrderReviews; } - set - { - _changeOrderReviews = value; - OnPropertyChanged(nameof(ChangeOrderReviews)); - } - } - + private OrderModel _newOrder; public OrderModel NewOrder { @@ -223,16 +198,7 @@ public OrderReviewModel SelectedOrderReview OnPropertyChanged(nameof(SelectedOrderReview)); } } - public OrderReviewModel SelectedChangeOrderReview - { - get { return _selectedOrderReviewModel; } - set - { - _selectedOrderReviewModel = value; - //((CommandBase)DeleteReviewWindowOfOrderInfo).RaiseCanExecuteChanged(); - OnPropertyChanged(nameof(SelectedChangeOrderReview)); - } - } + public OrderDetailModel SelectedNewOrderDetail { @@ -265,7 +231,26 @@ public ClientModel SelectedClient } } - + public ClientModel SelectedOrderClient + { + get { return _selectedOrderClient; } + set + { + _selectedOrderClient = value; + OnPropertyChanged(nameof(SelectedOrderClient)); + } + } + + public string SelectedOrderAddress + { + get { return _selectedOrderAddress; } + set + { + _selectedOrderAddress = value; + OnPropertyChanged(nameof(SelectedOrderAddress)); + } + } + public ClientModel SelectedChangeClient { get { return _selectedChangeClient; } @@ -325,6 +310,17 @@ public DateTime NewDate } } + public DateTime SelectedOrderDate + { + get { return _selectedOrderDate; } + set + { + _selectedOrderDate = value; + OnPropertyChanged(nameof(SelectedOrderDate)); + } + } + + public DateTime ChangedDate { get { return _changedDate; } From 11601fd4fa755ab20c35f4c9469dc009b3f70d4b Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 05:35:09 +0300 Subject: [PATCH 09/17] Added try-catch in orderService(works time to time), delete OrderShortModel --- .../Configuration/CustomMapper.cs | 5 +- Alligator.BusinessLayer/Models/OrderModel.cs | 8 +- .../Models/OrderShortModel.cs | 16 ---- Alligator.BusinessLayer/OrderService.cs | 76 ++++++++++++++----- .../Repositories/BaseRepository.cs | 7 +- .../Commands/TabItemOrders/AddOrderCommand.cs | 15 +++- .../ComeBackFirstWindowCommand.cs | 8 +- ...ackFirstWindowFromAddOrderWindowCommand.cs | 10 ++- ...OfOrderInfoFromChangeOrderWindowCommand.cs | 15 +++- .../TabItemOrders/GetOrdersCommand.cs | 11 ++- .../OpenOrderInfoWindowCommand.cs | 13 +++- .../TabItemOrders/SaveChangedOrderCommand.cs | 25 +++--- 12 files changed, 145 insertions(+), 64 deletions(-) delete mode 100644 Alligator.BusinessLayer/Models/OrderShortModel.cs diff --git a/Alligator.BusinessLayer/Configuration/CustomMapper.cs b/Alligator.BusinessLayer/Configuration/CustomMapper.cs index 76759d4..002d425 100644 --- a/Alligator.BusinessLayer/Configuration/CustomMapper.cs +++ b/Alligator.BusinessLayer/Configuration/CustomMapper.cs @@ -1,4 +1,5 @@ using Alligator.BusinessLayer.Models; +using Alligator.DataLayer; using Alligator.DataLayer.Entities; using AutoMapper; @@ -22,9 +23,7 @@ private static void InitializeInstance() cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); diff --git a/Alligator.BusinessLayer/Models/OrderModel.cs b/Alligator.BusinessLayer/Models/OrderModel.cs index a57d3f0..f255d10 100644 --- a/Alligator.BusinessLayer/Models/OrderModel.cs +++ b/Alligator.BusinessLayer/Models/OrderModel.cs @@ -6,8 +6,12 @@ namespace Alligator.BusinessLayer.Models { - public class OrderModel: OrderShortModel - { + public class OrderModel + { + public int Id { get; set; } + public DateTime Date { get; set; } + public string Address { get; set; } + public ClientModel Client { get; set; } public List OrderDetails { get; set; } public List OrderReviews { get; set; } } diff --git a/Alligator.BusinessLayer/Models/OrderShortModel.cs b/Alligator.BusinessLayer/Models/OrderShortModel.cs deleted file mode 100644 index 80e8e1f..0000000 --- a/Alligator.BusinessLayer/Models/OrderShortModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Alligator.BusinessLayer.Models -{ - public class OrderShortModel - { - public int Id { get; set; } - public DateTime Date { get; set; } - public string Address { get; set; } - public ClientModel Client { get; set; } - } -} diff --git a/Alligator.BusinessLayer/OrderService.cs b/Alligator.BusinessLayer/OrderService.cs index 4bed749..38c706a 100644 --- a/Alligator.BusinessLayer/OrderService.cs +++ b/Alligator.BusinessLayer/OrderService.cs @@ -26,46 +26,86 @@ public OrderService() _repositoryOrderReview = new OrderReviewRepository(); } - public List GetOrdersWithoutSensitiveData() + public ActionResult> GetOrders() { var orders = _repositoryOrder.GetAllOrders(); - return CustomMapper.GetInstance().Map>(orders); + try + { + return new ActionResult>(true, CustomMapper.GetInstance().Map>(orders)); + } + catch (Exception exception) + { + return new ActionResult>(false, null) { ErrorMessage = exception.Message }; + } } - public List GetOrders() - { - var orders = _repositoryOrder.GetAllOrders(); - return CustomMapper.GetInstance().Map>(orders); - } - - public List GetOrdersByClientId(int id) + public ActionResult> GetOrdersByClientId(int id) { var orders = _repositoryOrder.GetOrdersByClientId(id); - return CustomMapper.GetInstance().Map>(orders); + try + { + return new ActionResult>(true, CustomMapper.GetInstance().Map>(orders)); + } + catch (Exception exception) + { + return new ActionResult>(false, null) { ErrorMessage = exception.Message }; + } } - public OrderModel GetOrderByIdWithDetailsAndReviews(int id) + public ActionResult GetOrderByIdWithDetailsAndReviews(int id) { var order = _repositoryOrder.GetOrderById(id); order.OrderDetails = _repositoryOrderDetail.GetOrderDetailsByOrderId(id); order.OrderReviews = _repositoryOrderReview.GetOrderReviewsByOrderId(id); - return CustomMapper.GetInstance().Map(order); + try + { + return new ActionResult(true, CustomMapper.GetInstance().Map(order)); + } + catch + (Exception exception) + { + return new ActionResult(false, null) { ErrorMessage = exception.Message }; + + } } public int AddOrderModel(DateTime date, int clientId, string address) { - int id =_repositoryOrder.AddOrder(date, clientId, address); - return id; + try + { + int id =_repositoryOrder.AddOrder(date, clientId, address); + return id; + } + catch + { + return -1; + } } - public void DeleteOrderModel(int id) + public bool DeleteOrderModel(int id) { - _repositoryOrder.DeleteOrder(id); + try + { + _repositoryOrder.DeleteOrder(id); + return true; + } + catch + { + return false; + } } - public void EditOrderModel(DateTime date, int orderId, int clientId, string address) + public bool EditOrderModel(DateTime date, int orderId, int clientId, string address) { - _repositoryOrder.EditOrder(date, orderId, clientId, address); + try + { + _repositoryOrder.EditOrder(date, orderId, clientId, address); + return true; + } + catch + { + return false; + } } } } diff --git a/Alligator.DataLayer/Repositories/BaseRepository.cs b/Alligator.DataLayer/Repositories/BaseRepository.cs index 1785ed8..60a44f5 100644 --- a/Alligator.DataLayer/Repositories/BaseRepository.cs +++ b/Alligator.DataLayer/Repositories/BaseRepository.cs @@ -1,4 +1,5 @@ -using System.Data.SqlClient; + +using System.Data.SqlClient; namespace Alligator.DataLayer.Repositories { @@ -6,7 +7,7 @@ public abstract class BaseRepository { private const string _connection = "Data Source=80.78.240.16;Database=AggregatorAlligator;User Id=student;Password=qwe!23;"; - protected static SqlConnection ProvideConnection() => new SqlConnection(_connection); + public static SqlConnection ProvideConnection() => new SqlConnection(_connection); protected enum AffectedRows { @@ -14,4 +15,4 @@ protected enum AffectedRows One } } -} +} \ No newline at end of file diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index 91a490e..a997cbe 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -60,6 +60,11 @@ public override void Execute(object parameter) } int orderId = _orderService.AddOrderModel(_viewModel.NewDate, _viewModel.SelectedClient.Id, newAddress); + if (orderId == -1) + { + MessageBox.Show("Ошибка при добавлении клиента в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } foreach (var orderReview in _viewModel.NewOrderReviews) { _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); @@ -68,7 +73,15 @@ public override void Execute(object parameter) { _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); } - _viewModel.AllOrders.Add(_orderService.GetOrderByIdWithDetailsAndReviews(orderId)); + if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success is true) + { + var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; + _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } } } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs index 27865b8..0145f1d 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs @@ -27,10 +27,16 @@ public override void Execute(object parameter) _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersWindowVisibility = Visibility.Visible; _viewModel.AllOrders.Clear(); - foreach (var order in _orderService.GetOrders()) + if (_orderService.GetOrders().Success is true) { + var orders = _orderService.GetOrders().Data; + foreach (var order in orders) _viewModel.AllOrders.Add(order); } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } } } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs index fb20d9c..fb72653 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs @@ -32,9 +32,15 @@ public override void Execute(object parameter) _viewModel.NewOrderReviews.Clear(); _viewModel.NewOrderDetails.Clear(); _viewModel.AllOrders.Clear(); - foreach (var order in _orderService.GetOrders()) + if (_orderService.GetOrders().Success is true) { - _viewModel.AllOrders.Add(order); + var orders = _orderService.GetOrders().Data; + foreach (var order in orders) + _viewModel.AllOrders.Add(order); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); } } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs index 055d935..4e80190 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs @@ -27,10 +27,17 @@ public override void Execute(object parameter) _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Collapsed; - var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); - _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); - _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + _viewModel.OrdersWindowVisibility = Visibility.Collapsed; + if (_orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Success is true) + { + var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; + _viewModel.OrderReviews = new ObservableCollection(ordersWithDetailsAndReviews.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(ordersWithDetailsAndReviews.OrderDetails); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; _viewModel.SelectedOrderClient.FirstName = _viewModel.SelectedOrder.Client.FirstName; diff --git a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs index 3e8b48e..99141cb 100644 --- a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs +++ b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { @@ -25,9 +26,15 @@ public override void Execute(object parameter) { _viewModel.AllOrders.Clear(); - foreach (var order in _orderService.GetOrders()) + if (_orderService.GetOrders().Success is true) { - _viewModel.AllOrders.Add(order); + var orders = _orderService.GetOrders().Data; + foreach (var order in orders) + _viewModel.AllOrders.Add(order); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); } } diff --git a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs index 03b3ed1..fdec422 100644 --- a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs @@ -32,9 +32,16 @@ public override void Execute(object parameter) _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility= Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; - var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); - _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); - _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + if (_orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Success is true) + { + var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; + _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs index faec20b..22081c9 100644 --- a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -46,15 +46,22 @@ public override void Execute(object parameter) _viewModel.SelectedOrder.Address = address; _viewModel.SelectedOrder.Date = _viewModel.ChangedDate; _viewModel.SelectedOrder.Client = _viewModel.SelectedClient; - _orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address); - var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id); - _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); - _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); - _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; - _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; - _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; - //добавить сообщение, что всё успешно сохранено - //и проверку на связь с БД + + if (!_orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address)) + { + MessageBox.Show("Ошибка при сохранении данных", "Error", MessageBoxButton.OK); + return; + } + else + { + var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; + _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); + _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; + _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; + _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; + MessageBox.Show("Данные заказа изменены"); + } _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; From 80f7328e7e7538915c26c38e334133ab7be62ccb Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 05:57:14 +0300 Subject: [PATCH 10/17] Added question messages --- .../Commands/TabItemOrders/AddOrderCommand.cs | 49 ++++++++++--------- .../DeleteOrderWindowOfAllOrdersCommand.cs | 13 +++-- .../DeleteOrderWindowOfOrderInfoCommand.cs | 19 ++++--- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index a997cbe..3f5178a 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -60,28 +60,33 @@ public override void Execute(object parameter) } int orderId = _orderService.AddOrderModel(_viewModel.NewDate, _viewModel.SelectedClient.Id, newAddress); - if (orderId == -1) - { - MessageBox.Show("Ошибка при добавлении клиента в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - foreach (var orderReview in _viewModel.NewOrderReviews) - { - _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); - } - foreach (var orderDetail in _viewModel.NewOrderDetails) - { - _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); - } - if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success is true) - { - var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; - _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } + if (orderId == -1) + { + MessageBox.Show("Ошибка при добавлении заказа в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + else + { + foreach (var orderReview in _viewModel.NewOrderReviews) + { + _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); + } + foreach (var orderDetail in _viewModel.NewOrderDetails) + { + _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); + } + if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success is true) + { + var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; + _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); + MessageBox.Show("Заказ добавлен"); + _viewModel.ComeBackFirstWindow.Execute(null); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } + } } } } diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs index 3d0ce95..a2f3534 100644 --- a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { @@ -30,10 +31,14 @@ public override bool CanExecute(object parameter) public override void Execute(object parameter) { - _orderReviewService.DeleteOrderReviewModelByOrderId(_viewModel.SelectedOrder.Id); - _orderDetailService.DeleteOrderDetailModelByOrderId(_viewModel.SelectedOrder.Id); - _orderService.DeleteOrderModel(_viewModel.SelectedOrder.Id); - _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); + var userAnswer = MessageBox.Show("Удалить заказ?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (userAnswer == MessageBoxResult.Yes) + { + _orderReviewService.DeleteOrderReviewModelByOrderId(_viewModel.SelectedOrder.Id); + _orderDetailService.DeleteOrderDetailModelByOrderId(_viewModel.SelectedOrder.Id); + _orderService.DeleteOrderModel(_viewModel.SelectedOrder.Id); + _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); + } } } } diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs index 1a10e51..0382eb2 100644 --- a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs @@ -27,13 +27,18 @@ public DeleteOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, Ord public override void Execute(object parameter) { - _orderReviewService.DeleteOrderReviewModelByOrderId(_viewModel.SelectedOrder.Id); - _orderDetailService.DeleteOrderDetailModelByOrderId(_viewModel.SelectedOrder.Id); - _orderService.DeleteOrderModel(_viewModel.SelectedOrder.Id); - _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Visible; + + var userAnswer = MessageBox.Show("Удалить заказ?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question); + if (userAnswer == MessageBoxResult.Yes) + { + _orderReviewService.DeleteOrderReviewModelByOrderId(_viewModel.SelectedOrder.Id); + _orderDetailService.DeleteOrderDetailModelByOrderId(_viewModel.SelectedOrder.Id); + _orderService.DeleteOrderModel(_viewModel.SelectedOrder.Id); + _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.OrdersWindowVisibility = Visibility.Visible; + } } } From fe9b6ef62a5899688c57b8d2c6574741aef63bc5 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 17:41:25 +0300 Subject: [PATCH 11/17] Delete unnessassary commands --- .../Commands/TabItemOrders/AddOrderCommand.cs | 5 ++ ...ackFirstWindowFromAddOrderWindowCommand.cs | 49 ------------------- ...OfOrderInfoFromChangeOrderWindowCommand.cs | 46 ----------------- ...erInfoCommand.cs => DeleteOrderCommand.cs} | 11 +++-- .../DeleteOrderWindowOfAllOrdersCommand.cs | 44 ----------------- Alligator/TabItems/TabItemOrders.xaml | 8 +-- .../TabItemOrdersViewModel.cs | 16 ++---- 7 files changed, 21 insertions(+), 158 deletions(-) delete mode 100644 Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs delete mode 100644 Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs rename Alligator/Commands/TabItemOrders/{DeleteOrderWindowOfOrderInfoCommand.cs => DeleteOrderCommand.cs} (78%) delete mode 100644 Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index 3f5178a..f8b5845 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -80,6 +80,11 @@ public override void Execute(object parameter) var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); MessageBox.Show("Заказ добавлен"); + _viewModel.NewReviewText = string.Empty; + _viewModel.NewAmount = string.Empty; + _viewModel.NewAddressText = string.Empty; + _viewModel.NewOrderReviews.Clear(); + _viewModel.NewOrderDetails.Clear(); _viewModel.ComeBackFirstWindow.Execute(null); } else diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs deleted file mode 100644 index fb72653..0000000 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowFromAddOrderWindowCommand.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Alligator.BusinessLayer; -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Alligator.UI.Commands.TabItemOrders -{ - class ComeBackFirstWindowFromAddOrderWindowCommand : CommandBase - { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - - public ComeBackFirstWindowFromAddOrderWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) - { - _viewModel = viewModel; - _orderService = orderService; - } - - public override void Execute(object parameter) - { - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; - _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Visible; - _viewModel.NewReviewText = string.Empty; - _viewModel.NewAmount = string.Empty; - _viewModel.NewAddressText = string.Empty; - _viewModel.NewOrderReviews.Clear(); - _viewModel.NewOrderDetails.Clear(); - _viewModel.AllOrders.Clear(); - if (_orderService.GetOrders().Success is true) - { - var orders = _orderService.GetOrders().Data; - foreach (var order in orders) - _viewModel.AllOrders.Add(order); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } - } - } - - -} diff --git a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs deleted file mode 100644 index 4e80190..0000000 --- a/Alligator/Commands/TabItemOrders/ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Alligator.UI.Commands.TabItemOrders -{ - class ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand : CommandBase - { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - - public ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) - { - _viewModel = viewModel; - _orderService = orderService; - } - - public override void Execute(object parameter) - { - _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; - _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.OrdersWindowVisibility = Visibility.Collapsed; - if (_orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Success is true) - { - var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; - _viewModel.OrderReviews = new ObservableCollection(ordersWithDetailsAndReviews.OrderReviews); - _viewModel.OrderDetails = new ObservableCollection(ordersWithDetailsAndReviews.OrderDetails); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } - _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; - _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; - _viewModel.SelectedOrderClient.FirstName = _viewModel.SelectedOrder.Client.FirstName; - } - } -} diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs similarity index 78% rename from Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs rename to Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs index 0382eb2..aa00391 100644 --- a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs @@ -9,7 +9,7 @@ namespace Alligator.UI.Commands.TabItemOrders { - public class DeleteOrderWindowOfOrderInfoCommand : CommandBase + public class DeleteOrderCommand : CommandBase { private TabItemOrdersViewModel _viewModel; @@ -17,17 +17,20 @@ public class DeleteOrderWindowOfOrderInfoCommand : CommandBase private OrderDetailService _orderDetailService; private OrderReviewService _orderReviewService; - public DeleteOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService) + public DeleteOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService) { _viewModel = viewModel; _orderService = orderService; _orderReviewService = orderReviewService; _orderDetailService = orderDetailService; } + public override bool CanExecute(object parameter) + { + return _viewModel.SelectedOrder is not null; + } public override void Execute(object parameter) { - var userAnswer = MessageBox.Show("Удалить заказ?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question); if (userAnswer == MessageBoxResult.Yes) { @@ -37,9 +40,9 @@ public override void Execute(object parameter) _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersWindowVisibility = Visibility.Visible; } } - } } diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs deleted file mode 100644 index a2f3534..0000000 --- a/Alligator/Commands/TabItemOrders/DeleteOrderWindowOfAllOrdersCommand.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Alligator.BusinessLayer; -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace Alligator.UI.Commands.TabItemOrders -{ - public class DeleteOrderWindowOfAllOrdersCommand : CommandBase - { - - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - private OrderDetailService _orderDetailService; - private OrderReviewService _orderReviewService; - - public DeleteOrderWindowOfAllOrdersCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService) - { - _viewModel = viewModel; - _orderService = orderService; - _orderReviewService = orderReviewService; - _orderDetailService = orderDetailService; - } - public override bool CanExecute(object parameter) - { - return _viewModel.SelectedOrder is not null; - } - - public override void Execute(object parameter) - { - var userAnswer = MessageBox.Show("Удалить заказ?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question); - if (userAnswer == MessageBoxResult.Yes) - { - _orderReviewService.DeleteOrderReviewModelByOrderId(_viewModel.SelectedOrder.Id); - _orderDetailService.DeleteOrderDetailModelByOrderId(_viewModel.SelectedOrder.Id); - _orderService.DeleteOrderModel(_viewModel.SelectedOrder.Id); - _viewModel.AllOrders.Remove(_viewModel.SelectedOrder); - } - } - } -} diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index f2fd9a1..3773aa6 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -42,7 +42,7 @@ - + @@ -142,7 +142,7 @@ - + @@ -247,7 +247,7 @@ - + @@ -354,7 +354,7 @@ - + diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 035bdcc..9a13103 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -37,8 +37,7 @@ public class TabItemOrdersViewModel : BaseViewModel public ICommand DeleteReview { get; set; } public ICommand GetOrders { get; set; } public ICommand GetOrderInfo { get; set; } - public ICommand DeleteOrderWindowOfAllOrders { get; set; } - public ICommand DeleteOrderWindowOfOrderInfo { get; set; } + public ICommand DeleteOrder { get; set; } public ICommand AddOrder { get; set; } public ICommand ChangeOrderWindowOfOrderInfo { get; set; } public ICommand OpenAddOrderWindow { get; set; } @@ -48,9 +47,7 @@ public class TabItemOrdersViewModel : BaseViewModel public ICommand DeleteReviewWindowOfAddOrder { get; set; } public ICommand AddProductWindowOfAddOrder { get; set; } public ICommand DeleteDetail { get; set; } - public ICommand DeleteNewDetail { get; set; } - public ICommand ComeBackFirstWindowFromAddOrderWindow { get; set; } - public ICommand ComeBackWindowOfOrderInfoFromChangeOrderWindow { get; set; } + public ICommand DeleteNewDetail { get; set; } public ICommand AddProductWindowOfChangeOrder { get; set; } public ICommand SaveChangedOrder { get; set; } public TabItemOrdersViewModel() @@ -71,8 +68,7 @@ public TabItemOrdersViewModel() AddReview = new AddReviewWindowOfOrderInfoCommand(this, _orderReviewService); DeleteReview = new DeleteReviewWindowOfOrderInfoCommand(this, _orderReviewService); GetOrders = new GetOrdersCommand(this, _orderService); - DeleteOrderWindowOfAllOrders = new DeleteOrderWindowOfAllOrdersCommand(this, _orderService, _orderDetailService, _orderReviewService); - DeleteOrderWindowOfOrderInfo = new DeleteOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService); + DeleteOrder = new DeleteOrderCommand(this, _orderService, _orderDetailService, _orderReviewService); AddOrder = new AddOrderCommand(this, _orderService, _orderReviewService, _orderDetailService); ChangeOrderWindowOfOrderInfo = new OpenChangeOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService, _clientService); OpenAddOrderWindow = new OpenAddOrderWindowCommand(this, _clientService); @@ -83,9 +79,7 @@ public TabItemOrdersViewModel() AddProductWindowOfAddOrder = new AddProductWindowOfAddOrderCommand(this); DeleteDetail = new DeleteDetailCommand(this, _orderDetailService); DeleteNewDetail = new DeleteNewDetailCommand(this); - AddProductWindowOfChangeOrder = new AddProductWindowOfChangeOrderCommand(this, _orderDetailService); - ComeBackFirstWindowFromAddOrderWindow = new ComeBackFirstWindowFromAddOrderWindowCommand(this, _orderService); - ComeBackWindowOfOrderInfoFromChangeOrderWindow = new ComeBackWindowOfOrderInfoFromChangeOrderWindowCommand(this, _orderService); + AddProductWindowOfChangeOrder = new AddProductWindowOfChangeOrderCommand(this, _orderDetailService); SaveChangedOrder = new SaveChangedOrderCommand(this, _orderService); } @@ -174,7 +168,7 @@ public OrderModel SelectedOrder { _selectedOrder = value; ((CommandBase)OpenOrderInfoWindow).RaiseCanExecuteChanged(); - ((CommandBase)DeleteOrderWindowOfAllOrders).RaiseCanExecuteChanged(); + ((CommandBase)DeleteOrder).RaiseCanExecuteChanged(); OnPropertyChanged(nameof(SelectedOrder)); } } From a30913a31247831325e6c0d14a0d8520b3d57112 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Mon, 10 Jan 2022 23:43:00 +0300 Subject: [PATCH 12/17] Edit xaml --- .../OrderServiceTests.cs | 15 ++++++++++++ Alligator.BusinessLayer/OrderDetailService.cs | 24 +++++++++---------- Alligator/TabItems/TabItemOrders.xaml | 14 +++++------ 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 Alligator.BusinessLayer.Tests/OrderServiceTests.cs diff --git a/Alligator.BusinessLayer.Tests/OrderServiceTests.cs b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs new file mode 100644 index 0000000..b3eb702 --- /dev/null +++ b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Moq; +using NUnit.Framework; + +namespace Alligator.BusinessLayer.Tests +{ + public class OrderServiceTests + { + // private readonly Mock _productTagRepositoryMock; + } +} diff --git a/Alligator.BusinessLayer/OrderDetailService.cs b/Alligator.BusinessLayer/OrderDetailService.cs index a3170a3..8f637be 100644 --- a/Alligator.BusinessLayer/OrderDetailService.cs +++ b/Alligator.BusinessLayer/OrderDetailService.cs @@ -11,60 +11,60 @@ namespace Alligator.BusinessLayer { public class OrderDetailService { - private readonly IOrderDetailRepository _repositoryOrderdetail; + private readonly IOrderDetailRepository _repositoryOrderDetail; - public OrderDetailService(IOrderDetailRepository repositoryOrderdetail) + public OrderDetailService(IOrderDetailRepository repositoryOrderDetail) { - _repositoryOrderdetail = repositoryOrderdetail; + _repositoryOrderDetail = repositoryOrderDetail; } public OrderDetailService() { - _repositoryOrderdetail = new OrderDetailRepository(); + _repositoryOrderDetail = new OrderDetailRepository(); } public OrderDetailModel GetOrderDetailById(int id) { - var orderDetail = _repositoryOrderdetail.GetOrderDetailById(id); + var orderDetail = _repositoryOrderDetail.GetOrderDetailById(id); return CustomMapper.GetInstance().Map(orderDetail); } public List GetOrderDetailsByOrderId(int id) { - var orderDetails = _repositoryOrderdetail.GetOrderDetailsByOrderId(id); + var orderDetails = _repositoryOrderDetail.GetOrderDetailsByOrderId(id); return CustomMapper.GetInstance().Map>(orderDetails); } public List GetOrderDetailsByProductId(int id) { - var orderDetails = _repositoryOrderdetail.GetOrderDetailsByProductId(id); + var orderDetails = _repositoryOrderDetail.GetOrderDetailsByProductId(id); return CustomMapper.GetInstance().Map>(orderDetails); } public void AddOrderDetailModel(int amount, int orderId, int productId) { - _repositoryOrderdetail.AddOrderDetail(amount, orderId, productId); + _repositoryOrderDetail.AddOrderDetail(amount, orderId, productId); } public void EditOrderDetailModel(int id, int amount) { - _repositoryOrderdetail.EditOrderDetail(id, amount); + _repositoryOrderDetail.EditOrderDetail(id, amount); } public void DeleteOrderDetailModel(int id) { - _repositoryOrderdetail.DeleteOrderDetail(id); + _repositoryOrderDetail.DeleteOrderDetail(id); } public void DeleteOrderDetailModelByOrderId(int orderId) { - _repositoryOrderdetail.DeleteOrderDetailByOrderId(orderId); + _repositoryOrderDetail.DeleteOrderDetailByOrderId(orderId); } public void DeleteOrderDetailByProductId(int id) { - _repositoryOrderdetail.DeleteOrderDetailByProductId(id); + _repositoryOrderDetail.DeleteOrderDetailByProductId(id); } } } diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index 3773aa6..d5d5dfb 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -77,9 +77,9 @@ - - - + + + @@ -102,7 +102,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -232,7 +232,7 @@ - + @@ -339,7 +339,7 @@ - + From 135ecb7f1206288142ef34524770f328b649c62d Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Tue, 11 Jan 2022 01:05:14 +0300 Subject: [PATCH 13/17] Fixed --- .../OrderServiceTests.cs | 51 ++++++++++++++++- Alligator.BusinessLayer/OrderDetailService.cs | 4 +- Alligator.BusinessLayer/OrderReviewService.cs | 4 +- Alligator.BusinessLayer/OrderService.cs | 14 +++-- .../Repositories/BaseRepository.cs | 2 +- .../Repositories/IOrderRepository.cs | 2 +- .../Repositories/OrderRepository.cs | 4 +- .../Commands/TabItemOrders/AddOrderCommand.cs | 56 +++++++++---------- .../TabItemOrders/GetOrdersCommand.cs | 2 +- .../OpenAddOrderWindowCommand.cs | 2 +- ...OpenChangeOrderWindowOfOrderInfoCommand.cs | 2 +- .../TabItemOrders/SaveChangedOrderCommand.cs | 3 +- 12 files changed, 98 insertions(+), 48 deletions(-) diff --git a/Alligator.BusinessLayer.Tests/OrderServiceTests.cs b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs index b3eb702..3c91fd7 100644 --- a/Alligator.BusinessLayer.Tests/OrderServiceTests.cs +++ b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Alligator.DataLayer.Entities; +using Alligator.DataLayer.Repositories; using Moq; using NUnit.Framework; @@ -10,6 +12,53 @@ namespace Alligator.BusinessLayer.Tests { public class OrderServiceTests { - // private readonly Mock _productTagRepositoryMock; + private readonly Mock _orderRepositoryMock; + private readonly Mock _orderDetailRepositoryMock; + private readonly Mock _orderReviewRepositoryMock; + + public OrderServiceTests() + { + _orderRepositoryMock = new Mock(); + _orderDetailRepositoryMock = new Mock(); + _orderReviewRepositoryMock = new Mock(); + } + [SetUp] + public void Setup() + { + } + public void FillObjectMockForGetAllOrders() + { + _orderRepositoryMock.Setup(m => m.GetAllOrders()).Returns(new List + { + new Order + { + Id = 1, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails=new List(), + OrderReviews =new List() + + }, + new Order + { + Id = 2, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails=new List(), + OrderReviews =new List() + }, + new Order + { + Id = 3, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails=new List(), + OrderReviews =new List() + } + }); + } } } diff --git a/Alligator.BusinessLayer/OrderDetailService.cs b/Alligator.BusinessLayer/OrderDetailService.cs index 8f637be..a95ef1b 100644 --- a/Alligator.BusinessLayer/OrderDetailService.cs +++ b/Alligator.BusinessLayer/OrderDetailService.cs @@ -13,9 +13,9 @@ public class OrderDetailService { private readonly IOrderDetailRepository _repositoryOrderDetail; - public OrderDetailService(IOrderDetailRepository repositoryOrderDetail) + public OrderDetailService(IOrderDetailRepository fakeRepositoryOrderDetail) { - _repositoryOrderDetail = repositoryOrderDetail; + _repositoryOrderDetail = fakeRepositoryOrderDetail; } public OrderDetailService() diff --git a/Alligator.BusinessLayer/OrderReviewService.cs b/Alligator.BusinessLayer/OrderReviewService.cs index b75b10a..67cb77e 100644 --- a/Alligator.BusinessLayer/OrderReviewService.cs +++ b/Alligator.BusinessLayer/OrderReviewService.cs @@ -14,9 +14,9 @@ public class OrderReviewService { private readonly IOrderReviewRepository _repositoryOrderReview; - public OrderReviewService(IOrderReviewRepository repositoryOrderReview) + public OrderReviewService(IOrderReviewRepository fakeRepositoryOrderReview) { - _repositoryOrderReview = repositoryOrderReview; + _repositoryOrderReview = fakeRepositoryOrderReview; } public OrderReviewService() diff --git a/Alligator.BusinessLayer/OrderService.cs b/Alligator.BusinessLayer/OrderService.cs index 38c706a..e713f58 100644 --- a/Alligator.BusinessLayer/OrderService.cs +++ b/Alligator.BusinessLayer/OrderService.cs @@ -1,5 +1,6 @@ using Alligator.BusinessLayer.Configuration; using Alligator.BusinessLayer.Models; +using Alligator.DataLayer.Entities; using Alligator.DataLayer.Repositories; using System; using System.Collections.Generic; @@ -12,11 +13,11 @@ public class OrderService private readonly IOrderDetailRepository _repositoryOrderDetail; private readonly IOrderReviewRepository _repositoryOrderReview; - public OrderService(IOrderRepository repositoryOrder, IOrderDetailRepository repositoryOrderDetail, IOrderReviewRepository repositoryOrderReview) + public OrderService(IOrderRepository fakeRepositoryOrder, IOrderDetailRepository fakeRepositoryOrderDetail, IOrderReviewRepository fakeRepositoryOrderReview) { - _repositoryOrder = repositoryOrder; - _repositoryOrderDetail = repositoryOrderDetail; - _repositoryOrderReview = repositoryOrderReview; + _repositoryOrder = fakeRepositoryOrder; + _repositoryOrderDetail = fakeRepositoryOrderDetail; + _repositoryOrderReview = fakeRepositoryOrderReview; } public OrderService() @@ -95,11 +96,12 @@ public bool DeleteOrderModel(int id) } } - public bool EditOrderModel(DateTime date, int orderId, int clientId, string address) + public bool EditOrderModel(OrderModel editedOrder) { + var order = CustomMapper.GetInstance().Map(editedOrder); try { - _repositoryOrder.EditOrder(date, orderId, clientId, address); + _repositoryOrder.EditOrder(order); return true; } catch diff --git a/Alligator.DataLayer/Repositories/BaseRepository.cs b/Alligator.DataLayer/Repositories/BaseRepository.cs index 60a44f5..d7572b2 100644 --- a/Alligator.DataLayer/Repositories/BaseRepository.cs +++ b/Alligator.DataLayer/Repositories/BaseRepository.cs @@ -7,7 +7,7 @@ public abstract class BaseRepository { private const string _connection = "Data Source=80.78.240.16;Database=AggregatorAlligator;User Id=student;Password=qwe!23;"; - public static SqlConnection ProvideConnection() => new SqlConnection(_connection); + protected static SqlConnection ProvideConnection() => new SqlConnection(_connection); protected enum AffectedRows { diff --git a/Alligator.DataLayer/Repositories/IOrderRepository.cs b/Alligator.DataLayer/Repositories/IOrderRepository.cs index d8ea6b9..4cca6d5 100644 --- a/Alligator.DataLayer/Repositories/IOrderRepository.cs +++ b/Alligator.DataLayer/Repositories/IOrderRepository.cs @@ -8,7 +8,7 @@ public interface IOrderRepository { int AddOrder(DateTime date, int clientId, string address); void DeleteOrder(int id); - void EditOrder(DateTime date, int orderId, int clientId, string address); + void EditOrder(Order order); List GetAllOrders(); Order GetOrderById(int id); List GetOrdersByClientId(int id); diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 9dbef06..805a9d9 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -76,12 +76,12 @@ public void DeleteOrder(int id) commandType: CommandType.StoredProcedure); } - public void EditOrder(DateTime date, int orderId, int clientId, string address) + public void EditOrder(Order editedOrder) { using var connection = ProvideConnection(); string procString = "dbo.Order_Update"; connection.Execute(procString, - new { date, Id=orderId, clientId, address }, + new { Date=editedOrder.Date, Id= editedOrder.Id, ClientId=editedOrder.Client.Id, editedOrder.Address }, commandType: CommandType.StoredProcedure); } diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index f8b5845..10db12c 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -44,10 +44,8 @@ public override void Execute(object parameter) } if (_viewModel.NewOrder.OrderDetails is null) - { - List orderDetails = new List(); - - _viewModel.NewOrder.OrderDetails = orderDetails; + { + _viewModel.NewOrder.OrderDetails = new List(); } if (_viewModel.NewOrderDetails is null) { @@ -65,33 +63,33 @@ public override void Execute(object parameter) MessageBox.Show("Ошибка при добавлении заказа в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } - else + + + foreach (var orderReview in _viewModel.NewOrderReviews) { - foreach (var orderReview in _viewModel.NewOrderReviews) - { - _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); - } - foreach (var orderDetail in _viewModel.NewOrderDetails) - { - _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); - } - if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success is true) - { - var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; - _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); - MessageBox.Show("Заказ добавлен"); - _viewModel.NewReviewText = string.Empty; - _viewModel.NewAmount = string.Empty; - _viewModel.NewAddressText = string.Empty; - _viewModel.NewOrderReviews.Clear(); - _viewModel.NewOrderDetails.Clear(); - _viewModel.ComeBackFirstWindow.Execute(null); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } + _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); } + foreach (var orderDetail in _viewModel.NewOrderDetails) + { + _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); + } + if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success) + { + var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; + _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); + MessageBox.Show("Заказ добавлен"); + _viewModel.NewReviewText = string.Empty; + _viewModel.NewAmount = string.Empty; + _viewModel.NewAddressText = string.Empty; + _viewModel.NewOrderReviews.Clear(); + _viewModel.NewOrderDetails.Clear(); + _viewModel.ComeBackFirstWindow.Execute(null); + } + else + { + MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + } } } } + diff --git a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs index 99141cb..118f355 100644 --- a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs +++ b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs @@ -26,7 +26,7 @@ public override void Execute(object parameter) { _viewModel.AllOrders.Clear(); - if (_orderService.GetOrders().Success is true) + if (_orderService.GetOrders().Success) { var orders = _orderService.GetOrders().Data; foreach (var order in orders) diff --git a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs index 76b0b72..a0a00f4 100644 --- a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs @@ -27,7 +27,7 @@ public override void Execute(object parameter) _viewModel.NewDate = DateTime.Now; _viewModel.NewOrder = new OrderModel() { Address = _viewModel.NewAddressText, Client = _viewModel.SelectedClient, Date = _viewModel.NewDate }; _viewModel.Clients.Clear(); - if (_clientService.GetAllClients().Success is true) + if (_clientService.GetAllClients().Success) { var clients = _clientService.GetAllClients().Data; foreach (var client in clients) diff --git a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs index b4d72fa..1ccce73 100644 --- a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs @@ -39,7 +39,7 @@ public override void Execute(object parameter) _viewModel.ChangedDate = _viewModel.SelectedOrder.Date; _viewModel.ChangedAddressText = _viewModel.SelectedOrder.Address; _viewModel.Clients.Clear(); - if (_clientService.GetAllClients().Success is true) + if (_clientService.GetAllClients().Success) { var clients = _clientService.GetAllClients().Data; foreach (var client in clients) diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs index 22081c9..859766e 100644 --- a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -46,8 +46,9 @@ public override void Execute(object parameter) _viewModel.SelectedOrder.Address = address; _viewModel.SelectedOrder.Date = _viewModel.ChangedDate; _viewModel.SelectedOrder.Client = _viewModel.SelectedClient; + OrderModel editedOrder = new OrderModel() { Id = _viewModel.SelectedOrder.Id, Address = address, Client = _viewModel.SelectedChangeClient, Date = _viewModel.ChangedDate }; - if (!_orderService.EditOrderModel(_viewModel.ChangedDate, _viewModel.SelectedOrder.Id, _viewModel.SelectedChangeClient.Id, address)) + if (!_orderService.EditOrderModel(editedOrder)) { MessageBox.Show("Ошибка при сохранении данных", "Error", MessageBoxButton.OK); return; From 9d1eb4647fdd275b6bc01612476e8703951a3ca0 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Tue, 11 Jan 2022 01:28:05 +0300 Subject: [PATCH 14/17] Fixed foreach in AddOrderCommand --- Alligator.BusinessLayer/OrderDetailService.cs | 10 ++++++++++ Alligator.BusinessLayer/OrderReviewService.cs | 10 ++++++++++ Alligator.BusinessLayer/OrderService.cs | 2 ++ Alligator/Commands/TabItemOrders/AddOrderCommand.cs | 13 +++---------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Alligator.BusinessLayer/OrderDetailService.cs b/Alligator.BusinessLayer/OrderDetailService.cs index a95ef1b..370b129 100644 --- a/Alligator.BusinessLayer/OrderDetailService.cs +++ b/Alligator.BusinessLayer/OrderDetailService.cs @@ -3,6 +3,7 @@ using Alligator.DataLayer.Repositories; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -47,6 +48,15 @@ public void AddOrderDetailModel(int amount, int orderId, int productId) _repositoryOrderDetail.AddOrderDetail(amount, orderId, productId); } + public void AddOrderDetailModels(ObservableCollection orderDetails) + { + var newOrderDetails = CustomMapper.GetInstance().Map>(orderDetails); + foreach (var orderDetail in newOrderDetails) + { + _repositoryOrderDetail.AddOrderDetail(orderDetail.Amount, orderDetail.Order.Id, orderDetail.Product.Id); + } + } + public void EditOrderDetailModel(int id, int amount) { _repositoryOrderDetail.EditOrderDetail(id, amount); diff --git a/Alligator.BusinessLayer/OrderReviewService.cs b/Alligator.BusinessLayer/OrderReviewService.cs index 67cb77e..ca86b42 100644 --- a/Alligator.BusinessLayer/OrderReviewService.cs +++ b/Alligator.BusinessLayer/OrderReviewService.cs @@ -4,6 +4,7 @@ using Alligator.DataLayer.Repositories; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -41,6 +42,15 @@ public void AddOrderReviewModel(string text, int orderId) _repositoryOrderReview.AddOrderReview(text, orderId); } + public void AddOrderReviewModels(ObservableCollection orderReviews) + { + var newOrderReviews = CustomMapper.GetInstance().Map>(orderReviews); + foreach (var orderReview in newOrderReviews) + { + _repositoryOrderReview.AddOrderReview(orderReview.Text, orderReview.Order.Id); + } + } + public void EditOrderReviewModel(int id, string text) { _repositoryOrderReview.EditOrderReview(id, text); diff --git a/Alligator.BusinessLayer/OrderService.cs b/Alligator.BusinessLayer/OrderService.cs index e713f58..0bea61c 100644 --- a/Alligator.BusinessLayer/OrderService.cs +++ b/Alligator.BusinessLayer/OrderService.cs @@ -4,6 +4,7 @@ using Alligator.DataLayer.Repositories; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Alligator.BusinessLayer { @@ -109,5 +110,6 @@ public bool EditOrderModel(OrderModel editedOrder) return false; } } + } } diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index 10db12c..ed3b029 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -62,17 +62,10 @@ public override void Execute(object parameter) { MessageBox.Show("Ошибка при добавлении заказа в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; - } + } + _orderReviewService.AddOrderReviewModels(_viewModel.NewOrderReviews); + _orderDetailService.AddOrderDetailModels(_viewModel.NewOrderDetails); - - foreach (var orderReview in _viewModel.NewOrderReviews) - { - _orderReviewService.AddOrderReviewModel(orderReview.Text, orderId); - } - foreach (var orderDetail in _viewModel.NewOrderDetails) - { - _orderDetailService.AddOrderDetailModel(orderDetail.Amount, orderId, orderDetail.Product.Id); - } if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success) { var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; From 27525930f8b7fa5bddd7cdd0b595a84b3242cf51 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Tue, 11 Jan 2022 03:41:28 +0300 Subject: [PATCH 15/17] Edit xaml, edit commands (binding products) --- Alligator.BusinessLayer/OrderDetailService.cs | 4 +- Alligator.BusinessLayer/OrderReviewService.cs | 4 +- Alligator.BusinessLayer/OrderService.cs | 14 +++++- .../Repositories/OrderRepository.cs | 2 +- .../TabItemClients/DeleteClientCommand.cs | 10 ++-- .../Commands/TabItemOrders/AddOrderCommand.cs | 47 ++++--------------- .../TabItemOrders/GetOrdersCommand.cs | 11 +---- .../OpenAddOrderWindowCommand.cs | 29 ++++++++---- ...OpenChangeOrderWindowOfOrderInfoCommand.cs | 39 ++++++++------- .../OpenOrderInfoWindowCommand.cs | 15 ++---- Alligator/TabItems/TabItemOrders.xaml | 45 +++++++++--------- .../TabItemOrdersViewModel.cs | 6 ++- 12 files changed, 105 insertions(+), 121 deletions(-) diff --git a/Alligator.BusinessLayer/OrderDetailService.cs b/Alligator.BusinessLayer/OrderDetailService.cs index 370b129..1251fa1 100644 --- a/Alligator.BusinessLayer/OrderDetailService.cs +++ b/Alligator.BusinessLayer/OrderDetailService.cs @@ -48,12 +48,12 @@ public void AddOrderDetailModel(int amount, int orderId, int productId) _repositoryOrderDetail.AddOrderDetail(amount, orderId, productId); } - public void AddOrderDetailModels(ObservableCollection orderDetails) + public void AddOrderDetailModels(ObservableCollection orderDetails, int orderId) { var newOrderDetails = CustomMapper.GetInstance().Map>(orderDetails); foreach (var orderDetail in newOrderDetails) { - _repositoryOrderDetail.AddOrderDetail(orderDetail.Amount, orderDetail.Order.Id, orderDetail.Product.Id); + _repositoryOrderDetail.AddOrderDetail(orderDetail.Amount, orderId, orderDetail.Product.Id); } } diff --git a/Alligator.BusinessLayer/OrderReviewService.cs b/Alligator.BusinessLayer/OrderReviewService.cs index ca86b42..d1541eb 100644 --- a/Alligator.BusinessLayer/OrderReviewService.cs +++ b/Alligator.BusinessLayer/OrderReviewService.cs @@ -42,12 +42,12 @@ public void AddOrderReviewModel(string text, int orderId) _repositoryOrderReview.AddOrderReview(text, orderId); } - public void AddOrderReviewModels(ObservableCollection orderReviews) + public void AddOrderReviewModels(ObservableCollection orderReviews, int orderId) { var newOrderReviews = CustomMapper.GetInstance().Map>(orderReviews); foreach (var orderReview in newOrderReviews) { - _repositoryOrderReview.AddOrderReview(orderReview.Text, orderReview.Order.Id); + _repositoryOrderReview.AddOrderReview(orderReview.Text, orderId); } } diff --git a/Alligator.BusinessLayer/OrderService.cs b/Alligator.BusinessLayer/OrderService.cs index 0bea61c..abe86e9 100644 --- a/Alligator.BusinessLayer/OrderService.cs +++ b/Alligator.BusinessLayer/OrderService.cs @@ -110,6 +110,18 @@ public bool EditOrderModel(OrderModel editedOrder) return false; } } - + public bool DeleteOrdersByClientId(int clientId) + { + try + { + _repositoryOrder.DeleteOrdersByClientId(clientId); + return true; + } + catch + { + return false; + } + } + } } diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 31e7422..0d0fd16 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -52,7 +52,7 @@ public List GetOrdersByClientId(int id) order.Client = client; return order; }, - new { id }, + new { ClientId=id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). Distinct().ToList(); diff --git a/Alligator/Commands/TabItemClients/DeleteClientCommand.cs b/Alligator/Commands/TabItemClients/DeleteClientCommand.cs index 569bcfd..ff04182 100644 --- a/Alligator/Commands/TabItemClients/DeleteClientCommand.cs +++ b/Alligator/Commands/TabItemClients/DeleteClientCommand.cs @@ -39,14 +39,14 @@ public override void Execute(object parameter) var userAnswer = MessageBox.Show("Вы правда хотите удалить этого клиента?", "Удаление", MessageBoxButton.YesNo, MessageBoxImage.Question); if (userAnswer == MessageBoxResult.Yes) { + if (_orderService.DeleteOrdersByClientId(_viewModel.SelectedClient.Id) is false) + { + MessageBox.Show("VIP клиент", "Невозможно удалить", MessageBoxButton.OK); + return; + } if (_commentService.DeleteCommentsByClientId(_viewModel.SelectedClient.Id) ) { - if (_orderService.DeleteOrdersByClientId(_viewModel.SelectedClient.Id) is false) - { - MessageBox.Show("VIP клиент", "Невозможно удалить", MessageBoxButton.OK); - return; - } _clientService.DeleteClient(_viewModel.SelectedClient); _viewModel.Clients.Remove(_viewModel.SelectedClient); } diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index ed3b029..7396b41 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -28,7 +28,7 @@ public AddOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderServi } public override void Execute(object parameter) - { + { var newAddress = _viewModel.NewAddressText; if (string.IsNullOrEmpty(newAddress)) { @@ -36,53 +36,26 @@ public override void Execute(object parameter) _viewModel.NewAddressText = string.Empty; } newAddress = _viewModel.NewAddressText.Trim(); - if (_viewModel.SelectedClient is null) { MessageBox.Show("Выберите клиента"); return; } - - if (_viewModel.NewOrder.OrderDetails is null) - { - _viewModel.NewOrder.OrderDetails = new List(); - } - if (_viewModel.NewOrderDetails is null) - { - _viewModel.NewOrderDetails = new ObservableCollection(); - } - if (_viewModel.NewOrder.OrderDetails.Count==0) + if (_viewModel.NewOrder.OrderDetails.Count == 0) { MessageBox.Show("Выберите продукты и их количество"); return; } - - int orderId = _orderService.AddOrderModel(_viewModel.NewDate, _viewModel.SelectedClient.Id, newAddress); - if (orderId == -1) - { - MessageBox.Show("Ошибка при добавлении заказа в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - _orderReviewService.AddOrderReviewModels(_viewModel.NewOrderReviews); - _orderDetailService.AddOrderDetailModels(_viewModel.NewOrderDetails); - - if (_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Success) - { - var ordersWithDetailsAndReviews = _orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data; - _viewModel.AllOrders.Add(ordersWithDetailsAndReviews); - MessageBox.Show("Заказ добавлен"); - _viewModel.NewReviewText = string.Empty; - _viewModel.NewAmount = string.Empty; - _viewModel.NewAddressText = string.Empty; - _viewModel.NewOrderReviews.Clear(); - _viewModel.NewOrderDetails.Clear(); - _viewModel.ComeBackFirstWindow.Execute(null); - } - else + int orderId = _orderService.AddOrderModel(_viewModel.NewDate, _viewModel.SelectedClient.Id, newAddress); + if (orderId != -1) { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + _orderReviewService.AddOrderReviewModels(_viewModel.NewOrderReviews, orderId); + _orderDetailService.AddOrderDetailModels(_viewModel.NewOrderDetails, orderId); + _viewModel.AllOrders.Add(_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data); + MessageBox.Show("Заказ создан"); + _viewModel.NewAmount = string.Empty; + _viewModel.ComeBackFirstWindow.Execute(null); } } } } - diff --git a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs index 118f355..c46aaa6 100644 --- a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs +++ b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs @@ -7,7 +7,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { @@ -26,15 +25,9 @@ public override void Execute(object parameter) { _viewModel.AllOrders.Clear(); - if (_orderService.GetOrders().Success) + foreach (var order in _orderService.GetOrders().Data) { - var orders = _orderService.GetOrders().Data; - foreach (var order in orders) - _viewModel.AllOrders.Add(order); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); + _viewModel.AllOrders.Add(order); } } diff --git a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs index 7b64932..309de7a 100644 --- a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs @@ -15,34 +15,43 @@ public class OpenAddOrderWindowCommand : CommandBase { private TabItemOrdersViewModel _viewModel; private ClientService _clientService; - //private ProductService _productService; + private ProductService _productService; - public OpenAddOrderWindowCommand(TabItemOrdersViewModel viewModel, ClientService clientService) + public OpenAddOrderWindowCommand(TabItemOrdersViewModel viewModel, ClientService clientService, ProductService productService) { _viewModel = viewModel; _clientService = clientService; + _productService = productService; } public override void Execute(object parameter) { _viewModel.NewDate = DateTime.Now; + _viewModel.NewAmount = string.Empty; + _viewModel.NewAddressText = string.Empty; + _viewModel.NewOrderReviews.Clear(); + _viewModel.NewOrderDetails.Clear(); _viewModel.NewOrder = new OrderModel() { Address = _viewModel.NewAddressText, Client = _viewModel.SelectedClient, Date = _viewModel.NewDate }; _viewModel.Clients.Clear(); - if (_clientService.GetAllClients().Success) + var clientsActionResult = _clientService.GetAllClients(); + if (clientsActionResult.Success) { - var clients = _clientService.GetAllClients().Data; - foreach (var client in clients) + foreach (var client in clientsActionResult.Data) _viewModel.Clients.Add(client); } else { MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); } - //пока нет productServic'а - //foreach (var product in _productService.GetAllProducts()) - //{ - // _viewModel.Products.Add(product); - //} + _viewModel.Products.Clear(); + var productsActionResult = _productService.GetAllProducts(); + if (productsActionResult.Success) + { + foreach (var product in productsActionResult.Data) + { + _viewModel.Products.Add(product); + } + } _viewModel.OrdersWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; diff --git a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs index 1ccce73..e861416 100644 --- a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs @@ -1,5 +1,6 @@ using Alligator.BusinessLayer; using Alligator.BusinessLayer.Models; +using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; using System; using System.Collections.Generic; @@ -13,22 +14,20 @@ namespace Alligator.UI.Commands.TabItemOrders { public class OpenChangeOrderWindowOfOrderInfoCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; + private TabItemOrdersViewModel _viewModel; private OrderDetailService _orderDetailService; - private OrderReviewService _orderReviewService; private ClientService _clientService; - //private ProductService _productService; + private ProductService _productService; - public OpenChangeOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService, ClientService clientService) + public OpenChangeOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService, ClientService clientService, ProductService productService) { - _viewModel = viewModel; - _orderService = orderService; - _orderReviewService = orderReviewService; + _viewModel = viewModel; _orderDetailService = orderDetailService; _clientService = clientService; - } + _productService = productService; + + } public override void Execute(object parameter) { @@ -39,23 +38,27 @@ public override void Execute(object parameter) _viewModel.ChangedDate = _viewModel.SelectedOrder.Date; _viewModel.ChangedAddressText = _viewModel.SelectedOrder.Address; _viewModel.Clients.Clear(); - if (_clientService.GetAllClients().Success) + var clientsActionResult = _clientService.GetAllClients(); + if (clientsActionResult.Success) { - var clients = _clientService.GetAllClients().Data; - foreach (var client in clients) + foreach (var client in clientsActionResult.Data) _viewModel.Clients.Add(client); } else { MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } + } + _viewModel.Products.Clear(); + var productsActionResult = _productService.GetAllProducts(); + if (productsActionResult.Success) + { + foreach (var product in productsActionResult.Data) + { + _viewModel.Products.Add(product); + } + } _viewModel.SelectedChangeClient = _viewModel.SelectedOrder.Client; _viewModel.SelectedOrder.OrderDetails = _orderDetailService.GetOrderDetailsByOrderId(_viewModel.SelectedOrder.Id); - //пока нет productServic'а - //foreach (var product in _productService.GetAllProducts()) - //{ - // _viewModel.Products.Add(product); - //} } } } diff --git a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs index fdec422..ad1a6e3 100644 --- a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs @@ -30,21 +30,14 @@ public override void Execute(object parameter) { _viewModel.OrdersWindowVisibility = Visibility.Collapsed; _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; - _viewModel.ChangeOrderWindowVisibility= Visibility.Collapsed; + _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Visible; - if (_orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Success is true) - { - var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; - _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); - _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); - } - else - { - MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); - } _viewModel.SelectedOrderDate = _viewModel.SelectedOrder.Date; _viewModel.SelectedOrderAddress = _viewModel.SelectedOrder.Address; _viewModel.SelectedOrderClient = _viewModel.SelectedOrder.Client; + var order = _orderService.GetOrderByIdWithDetailsAndReviews(_viewModel.SelectedOrder.Id).Data; + _viewModel.OrderReviews = new ObservableCollection(order.OrderReviews); + _viewModel.OrderDetails = new ObservableCollection(order.OrderDetails); } } } diff --git a/Alligator/TabItems/TabItemOrders.xaml b/Alligator/TabItems/TabItemOrders.xaml index d5d5dfb..71c7564 100644 --- a/Alligator/TabItems/TabItemOrders.xaml +++ b/Alligator/TabItems/TabItemOrders.xaml @@ -69,7 +69,7 @@ Состав заказа - + @@ -77,9 +77,9 @@ - - - + + + @@ -174,31 +174,30 @@ - - + + - - - + + + - - + + - - + + @@ -280,31 +279,31 @@ - - + + - - - + + - - + + - - + + diff --git a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs index 6da8f4a..f6341ca 100644 --- a/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs +++ b/Alligator/VIewModels/TabItemsViewModels/TabItemOrdersViewModel.cs @@ -29,6 +29,7 @@ public class TabItemOrdersViewModel : BaseViewModel private readonly OrderReviewService _orderReviewService; private readonly OrderDetailService _orderDetailService; private readonly ClientService _clientService; + private readonly ProductService _productService; private string _newReviewText; private string _newAdressText; private string _changedAddressText; @@ -58,6 +59,7 @@ public TabItemOrdersViewModel() _orderReviewService = new OrderReviewService(); _orderDetailService = new OrderDetailService(); _clientService = new ClientService(); + _productService = new ProductService(); AllOrders = new ObservableCollection(); Clients = new ObservableCollection(); @@ -71,8 +73,8 @@ public TabItemOrdersViewModel() GetOrders = new GetOrdersCommand(this, _orderService); DeleteOrder = new DeleteOrderCommand(this, _orderService, _orderDetailService, _orderReviewService); AddOrder = new AddOrderCommand(this, _orderService, _orderReviewService, _orderDetailService); - ChangeOrderWindowOfOrderInfo = new OpenChangeOrderWindowOfOrderInfoCommand(this, _orderService, _orderDetailService, _orderReviewService, _clientService); - OpenAddOrderWindow = new OpenAddOrderWindowCommand(this, _clientService); + ChangeOrderWindowOfOrderInfo = new OpenChangeOrderWindowOfOrderInfoCommand(this, _orderDetailService, _clientService, _productService); + OpenAddOrderWindow = new OpenAddOrderWindowCommand(this, _clientService, _productService); OpenOrderInfoWindow = new OpenOrderInfoWindowCommand(this, _orderService); ComeBackFirstWindow = new ComeBackFirstWindowCommand(this, _orderService); AddReviewWindowOfAddOrder = new AddReviewWindowOfAddOrderCommand(this); From a3a5bd13f9c4044cb580715b2cac10b69ef78ef0 Mon Sep 17 00:00:00 2001 From: Breslavchik Date: Tue, 11 Jan 2022 05:38:46 +0300 Subject: [PATCH 16/17] Added tests for OrderService (not all) --- .../OrderServiceTests.cs | 173 +++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/Alligator.BusinessLayer.Tests/OrderServiceTests.cs b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs index 3c91fd7..b3e427d 100644 --- a/Alligator.BusinessLayer.Tests/OrderServiceTests.cs +++ b/Alligator.BusinessLayer.Tests/OrderServiceTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Alligator.BusinessLayer.Models; using Alligator.DataLayer.Entities; using Alligator.DataLayer.Repositories; using Moq; @@ -60,5 +61,175 @@ public void FillObjectMockForGetAllOrders() } }); } + + public void FillObjectMockForGetOrderById() + { + _orderRepositoryMock.Setup(m => m.GetOrderById(1)).Returns(new Order + { + Id = 1, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails = new List(), + OrderReviews = new List() + + }); + _orderRepositoryMock.Setup(m => m.GetOrderById(2)).Returns(new Order + { + Id = 2, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails = new List(), + OrderReviews = new List() + + }); + _orderRepositoryMock.Setup(m => m.GetOrderById(3)).Returns(new Order + { + Id = 3, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new Client(), + OrderDetails = new List(), + OrderReviews = new List() + + }); + } + + public OrderModel GetTestOrdersModelToFill(int key) + { + OrderModel order; + switch (key) + { + case 1: + order = new OrderModel + { + Id = 1, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new ClientModel(), + OrderDetails = new List(), + OrderReviews = new List() + }; + break; + + case 2: + order = new OrderModel + { + Id = 2, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new ClientModel(), + OrderDetails = new List(), + OrderReviews = new List() + }; + break; + case 3: + order = new OrderModel + { + Id = 3, + Date = DateTime.Now, + Address = "TestAdress1", + Client = new ClientModel(), + OrderDetails = new List(), + OrderReviews = new List() + }; + break; + default: + order = null; + break; + } + return order; + } + + [Test] + public void GetOrders_ShouldReturnAllOrders() + { + //arrange + + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object ); + FillObjectMockForGetAllOrders(); + //act + var actual = sut.GetOrders().Data; + //assert + Assert.IsNotNull(actual); + Assert.IsTrue(actual.Count > 0); + Assert.IsInstanceOf(typeof(OrderModel), actual[0]); + } + + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + public void GetOrderByOrderId_ShouldReturnOrder(int id) + { + //arrange + + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object); + FillObjectMockForGetOrderById(); + var actual = sut.GetOrderByIdWithDetailsAndReviews(id); + _orderRepositoryMock.Verify(m => m.GetOrderById(id), Times.Once()); + + Assert.IsTrue(actual.Success); + Assert.IsTrue(actual.Data.Id == id); + Assert.IsNotNull(actual.Data); + } + + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + public void GetOrderByClientId_ShouldReturnOrder(int id) + { + //arrange + + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object); + FillObjectMockForGetOrderById(); + var actual = sut.GetOrdersByClientId(id); + _orderRepositoryMock.Verify(m => m.GetOrdersByClientId(id), Times.Once()); + + Assert.IsTrue(actual.Success); + Assert.IsNotNull(actual.Data); + } + + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + + public void AddOrderModel(int id) + { + //arrange + var testOrder = GetTestOrdersModelToFill(id); + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object); + //act + var actual = sut.AddOrderModel(testOrder.Date, testOrder.Client.Id, testOrder.Address); + + //assert + Assert.IsNotNull(actual); + Assert.IsInstanceOf(typeof(int), actual); + } + + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + public void DeleteClient_ShouldReturnDeleted(int id) + { + //arrange + var testOrder = GetTestOrdersModelToFill(id); + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object); + //act + var a = sut.DeleteOrderModel(testOrder.Id); + //assert + Assert.That(a, Is.EqualTo(true)); + } + + [TestCase(1)] + [TestCase(2)] + public void EditOrderModel_ShouldEdited(int id) + { + var existingOrder = GetTestOrdersModelToFill(id); + var sut = new OrderService(_orderRepositoryMock.Object, _orderDetailRepositoryMock.Object, _orderReviewRepositoryMock.Object); + var actual = sut.EditOrderModel(existingOrder); + Assert.IsTrue(actual); + } } -} + } + From b2517e70788b4be97024c10e80057f56ac1f019b Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Tue, 11 Jan 2022 09:34:27 +0300 Subject: [PATCH 17/17] code cleanup --- .../Repositories/ClientRepository.cs | 1 - .../Repositories/OrderRepository.cs | 11 +++----- .../TabItemClients/AddClientPageCommand.cs | 4 +-- .../TabItemClients/AddCommentCommand.cs | 24 ++++++++---------- .../TabItemClients/AddNewClientCommand.cs | 15 +++-------- .../TabItemClients/DeleteClientCommand.cs | 8 +++--- .../TabItemClients/DeleteCommentCommand.cs | 15 +++-------- .../TabItemClients/LoadClientsCommand.cs | 10 ++++---- .../TabItemClients/OpenClientCardCommand.cs | 17 +++++-------- .../Commands/TabItemClients/ReturnCommand.cs | 7 +----- .../Commands/TabItemClients/SaveChanges.cs | 10 ++------ .../Commands/TabItemOrders/AddOrderCommand.cs | 17 ++++--------- .../AddProductWindowOfAddOrderCommand.cs | 15 +++++------ .../AddProductWindowOfChangeOrderCommand.cs | 11 +++----- .../AddReviewWindowOfAddOrderCommand.cs | 19 ++++++-------- .../AddReviewWindowOfOrderInfoCommand.cs | 23 +++++++---------- .../ComeBackFirstWindowCommand.cs | 15 ++++------- .../TabItemOrders/DeleteDetailCommand.cs | 9 ++----- .../TabItemOrders/DeleteNewDetailCommand.cs | 7 +----- .../TabItemOrders/DeleteOrderCommand.cs | 13 +++------- .../DeleteReviewWindowOfAddOrderCommand.cs | 14 +++-------- .../DeleteReviewWindowOfOrderInfoCommand.cs | 9 ++----- .../TabItemOrders/GetOrdersCommand.cs | 11 ++------ .../OpenAddOrderWindowCommand.cs | 12 +++------ ...OpenChangeOrderWindowOfOrderInfoCommand.cs | 25 +++++++------------ .../OpenOrderInfoWindowCommand.cs | 9 ++----- .../TabItemOrders/SaveChangedOrderCommand.cs | 9 ++----- .../Commands/TabItemProducts/AddProduct.cs | 6 ++--- .../AddProductTagToProductToEdit.cs | 2 -- .../Commands/TabItemProducts/DeleteProduct.cs | 2 +- Alligator/Helpers/UserInputValidation.cs | 7 +----- Alligator/TabItems/TabItemCategories.xaml.cs | 3 +-- 32 files changed, 113 insertions(+), 247 deletions(-) diff --git a/Alligator.DataLayer/Repositories/ClientRepository.cs b/Alligator.DataLayer/Repositories/ClientRepository.cs index 2895597..6491ea8 100644 --- a/Alligator.DataLayer/Repositories/ClientRepository.cs +++ b/Alligator.DataLayer/Repositories/ClientRepository.cs @@ -2,7 +2,6 @@ using Dapper; using System.Collections.Generic; using System.Data; -using System.Data.SqlClient; using System.Linq; namespace Alligator.DataLayer.Repositories diff --git a/Alligator.DataLayer/Repositories/OrderRepository.cs b/Alligator.DataLayer/Repositories/OrderRepository.cs index 0d0fd16..63ff12c 100644 --- a/Alligator.DataLayer/Repositories/OrderRepository.cs +++ b/Alligator.DataLayer/Repositories/OrderRepository.cs @@ -3,10 +3,7 @@ using System; using System.Collections.Generic; using System.Data; -using System.Data.SqlClient; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.DataLayer.Repositories { @@ -52,7 +49,7 @@ public List GetOrdersByClientId(int id) order.Client = client; return order; }, - new { ClientId=id }, + new { ClientId = id }, commandType: CommandType.StoredProcedure, splitOn: "Id"). Distinct().ToList(); @@ -64,7 +61,7 @@ public int AddOrder(DateTime date, int clientId, string address) using var connection = ProvideConnection(); string procString = "dbo.Order_Insert"; return connection.QueryFirstOrDefault(procString, - new { date,clientId, address }, + new { date, clientId, address }, commandType: CommandType.StoredProcedure); } @@ -73,7 +70,7 @@ public void DeleteOrder(int id) using var connection = ProvideConnection(); string procString = "dbo.Order_Delete"; connection.Execute(procString, - new {id }, + new { id }, commandType: CommandType.StoredProcedure); } @@ -82,7 +79,7 @@ public void EditOrder(Order editedOrder) using var connection = ProvideConnection(); string procString = "dbo.Order_Update"; connection.Execute(procString, - new { Date=editedOrder.Date, Id= editedOrder.Id, ClientId=editedOrder.Client.Id, editedOrder.Address }, + new { Date = editedOrder.Date, Id = editedOrder.Id, ClientId = editedOrder.Client.Id, editedOrder.Address }, commandType: CommandType.StoredProcedure); } public void DeleteOrdersByClientId(int clientId) diff --git a/Alligator/Commands/TabItemClients/AddClientPageCommand.cs b/Alligator/Commands/TabItemClients/AddClientPageCommand.cs index 2be72bb..8c937d2 100644 --- a/Alligator/Commands/TabItemClients/AddClientPageCommand.cs +++ b/Alligator/Commands/TabItemClients/AddClientPageCommand.cs @@ -1,7 +1,5 @@ -using Alligator.BusinessLayer.Models; -using Alligator.BusinessLayer.Services; +using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; -using System.Collections.ObjectModel; using System.Windows; namespace Alligator.UI.Commands.TabItemClients diff --git a/Alligator/Commands/TabItemClients/AddCommentCommand.cs b/Alligator/Commands/TabItemClients/AddCommentCommand.cs index 31686c2..0bd3342 100644 --- a/Alligator/Commands/TabItemClients/AddCommentCommand.cs +++ b/Alligator/Commands/TabItemClients/AddCommentCommand.cs @@ -1,20 +1,16 @@ using Alligator.BusinessLayer.Models; using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Commands.TabItemClients { public class AddCommentCommand : CommandBase { - private TabItemClientsViewModel _viewModel; - private CommentService _commentService; + private readonly TabItemClientsViewModel _viewModel; + private readonly CommentService _commentService; public AddCommentCommand(TabItemClientsViewModel viewModel, CommentService commentService) { _viewModel = viewModel; @@ -26,21 +22,21 @@ public override void Execute(object parameter) { if (_viewModel.SelectedClient.Comments is null) { - - List coms = new List(); - - _viewModel.SelectedClient.Comments = coms; + + List coms = new List(); + + _viewModel.SelectedClient.Comments = coms; } - if(_viewModel.Comments is null) + if (_viewModel.Comments is null) { ObservableCollection comms = new ObservableCollection(); _viewModel.Comments = comms; } - - + + var newComment = new CommentModel { Client = _viewModel.EditableClient, Text = _viewModel.Comment }; _viewModel.Comments.Add(newComment); - + _commentService.InsertComment(newComment); _viewModel.Comment = null; diff --git a/Alligator/Commands/TabItemClients/AddNewClientCommand.cs b/Alligator/Commands/TabItemClients/AddNewClientCommand.cs index 8966498..aa9b3d8 100644 --- a/Alligator/Commands/TabItemClients/AddNewClientCommand.cs +++ b/Alligator/Commands/TabItemClients/AddNewClientCommand.cs @@ -1,28 +1,21 @@ -using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Services; +using Alligator.BusinessLayer.Services; using Alligator.UI.Helpers; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemClients { class AddNewClientCommand : CommandBase { - private TabItemClientsViewModel _viewModel; - private ClientService _clientservice; + private readonly TabItemClientsViewModel _viewModel; + private readonly ClientService _clientservice; public AddNewClientCommand(TabItemClientsViewModel viewModel, ClientService clientService) { _viewModel = viewModel; _clientservice = clientService; } - + public override void Execute(object parameter) { bool isValid = ClientValidation.TrimAndCheckIsValid(_viewModel.NewClient); diff --git a/Alligator/Commands/TabItemClients/DeleteClientCommand.cs b/Alligator/Commands/TabItemClients/DeleteClientCommand.cs index ff04182..f0e91fd 100644 --- a/Alligator/Commands/TabItemClients/DeleteClientCommand.cs +++ b/Alligator/Commands/TabItemClients/DeleteClientCommand.cs @@ -41,11 +41,11 @@ public override void Execute(object parameter) { if (_orderService.DeleteOrdersByClientId(_viewModel.SelectedClient.Id) is false) { - MessageBox.Show("VIP клиент", "Невозможно удалить", MessageBoxButton.OK); - return; + MessageBox.Show("VIP клиент", "Невозможно удалить", MessageBoxButton.OK); + return; } - if (_commentService.DeleteCommentsByClientId(_viewModel.SelectedClient.Id) ) - + if (_commentService.DeleteCommentsByClientId(_viewModel.SelectedClient.Id)) + { _clientService.DeleteClient(_viewModel.SelectedClient); _viewModel.Clients.Remove(_viewModel.SelectedClient); diff --git a/Alligator/Commands/TabItemClients/DeleteCommentCommand.cs b/Alligator/Commands/TabItemClients/DeleteCommentCommand.cs index b0f7107..0052a48 100644 --- a/Alligator/Commands/TabItemClients/DeleteCommentCommand.cs +++ b/Alligator/Commands/TabItemClients/DeleteCommentCommand.cs @@ -1,22 +1,13 @@ - -using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; -using Alligator.BusinessLayer.Services; +using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemClients { public class DeleteCommentCommand : CommandBase { - private TabItemClientsViewModel _viewModel; - private CommentService _commentService; + private readonly TabItemClientsViewModel _viewModel; + private readonly CommentService _commentService; public DeleteCommentCommand(TabItemClientsViewModel viewModel, CommentService commentService) { diff --git a/Alligator/Commands/TabItemClients/LoadClientsCommand.cs b/Alligator/Commands/TabItemClients/LoadClientsCommand.cs index 822c090..578223c 100644 --- a/Alligator/Commands/TabItemClients/LoadClientsCommand.cs +++ b/Alligator/Commands/TabItemClients/LoadClientsCommand.cs @@ -18,19 +18,19 @@ public LoadClientsCommand(TabItemClientsViewModel viewModel, ClientService clien public override void Execute(object parameter) { _viewModel.Clients.Clear(); - if(_clientService.GetAllClients().Success is true) + if (_clientService.GetAllClients().Success is true) { var clients = _clientService.GetAllClients().Data; foreach (var client in clients) - _viewModel.Clients.Add(client); + _viewModel.Clients.Add(client); } else { MessageBox.Show("Ошибка", "Error", MessageBoxButton.OK); } - - - + + + } } diff --git a/Alligator/Commands/TabItemClients/OpenClientCardCommand.cs b/Alligator/Commands/TabItemClients/OpenClientCardCommand.cs index 9f90feb..543157d 100644 --- a/Alligator/Commands/TabItemClients/OpenClientCardCommand.cs +++ b/Alligator/Commands/TabItemClients/OpenClientCardCommand.cs @@ -2,23 +2,18 @@ using Alligator.BusinessLayer.Models; using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemClients { public class OpenClientCardCommand : CommandBase { - private TabItemClientsViewModel _viewModel; - private ClientService _clientService; - private CommentService _commentService; - private OrderService _orderService; - public OpenClientCardCommand(TabItemClientsViewModel viewModel,ClientService clientService, CommentService commentService, OrderService orderService) + private readonly TabItemClientsViewModel _viewModel; + private readonly ClientService _clientService; + private readonly CommentService _commentService; + private readonly OrderService _orderService; + public OpenClientCardCommand(TabItemClientsViewModel viewModel, ClientService clientService, CommentService commentService, OrderService orderService) { _viewModel = viewModel; _clientService = clientService; @@ -28,7 +23,7 @@ public OpenClientCardCommand(TabItemClientsViewModel viewModel,ClientService cli public override bool CanExecute(object parameter) { - return _viewModel.SelectedClient is not null; + return _viewModel.SelectedClient is not null; } public override void Execute(object parameter) diff --git a/Alligator/Commands/TabItemClients/ReturnCommand.cs b/Alligator/Commands/TabItemClients/ReturnCommand.cs index d326b15..4a8a67c 100644 --- a/Alligator/Commands/TabItemClients/ReturnCommand.cs +++ b/Alligator/Commands/TabItemClients/ReturnCommand.cs @@ -1,9 +1,4 @@ using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemClients @@ -11,7 +6,7 @@ namespace Alligator.UI.Commands.TabItemClients public class ReturnCommand : CommandBase { - private TabItemClientsViewModel _viewModel; + private readonly TabItemClientsViewModel _viewModel; public ReturnCommand(TabItemClientsViewModel viewModel) { diff --git a/Alligator/Commands/TabItemClients/SaveChanges.cs b/Alligator/Commands/TabItemClients/SaveChanges.cs index 38734ec..1bea692 100644 --- a/Alligator/Commands/TabItemClients/SaveChanges.cs +++ b/Alligator/Commands/TabItemClients/SaveChanges.cs @@ -1,12 +1,6 @@ -using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Services; +using Alligator.BusinessLayer.Services; using Alligator.UI.Helpers; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemClients @@ -39,7 +33,7 @@ public override void Execute(object parameter) { _viewModel.Clients.Add(item); } - + _viewModel.AllClients = Visibility.Visible; _viewModel.ClientCardVisibility = Visibility.Collapsed; _viewModel.SelectedClient = _viewModel.EditableClient; diff --git a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs index 7396b41..012bdb2 100644 --- a/Alligator/Commands/TabItemOrders/AddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddOrderCommand.cs @@ -1,22 +1,15 @@ using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class AddOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - private OrderReviewService _orderReviewService; - private OrderDetailService _orderDetailService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; + private readonly OrderReviewService _orderReviewService; + private readonly OrderDetailService _orderDetailService; public AddOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderReviewService orderReviewService , OrderDetailService orderDetailService) @@ -53,7 +46,7 @@ public override void Execute(object parameter) _orderDetailService.AddOrderDetailModels(_viewModel.NewOrderDetails, orderId); _viewModel.AllOrders.Add(_orderService.GetOrderByIdWithDetailsAndReviews(orderId).Data); MessageBox.Show("Заказ создан"); - _viewModel.NewAmount = string.Empty; + _viewModel.NewAmount = string.Empty; _viewModel.ComeBackFirstWindow.Execute(null); } } diff --git a/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs index 0fecead..3260855 100644 --- a/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddProductWindowOfAddOrderCommand.cs @@ -3,16 +3,13 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class AddProductWindowOfAddOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; + private readonly TabItemOrdersViewModel _viewModel; public AddProductWindowOfAddOrderCommand(TabItemOrdersViewModel viewModel) { _viewModel = viewModel; @@ -21,13 +18,13 @@ public AddProductWindowOfAddOrderCommand(TabItemOrdersViewModel viewModel) public override void Execute(object parameter) { var newAmount = _viewModel.NewAmount; - if (!int.TryParse(newAmount, out _)|| string.IsNullOrEmpty(newAmount)) + if (!int.TryParse(newAmount, out _) || string.IsNullOrEmpty(newAmount)) { MessageBox.Show("Введите количество продуктов"); return; } int amount = Convert.ToInt32(newAmount); - + if (_viewModel.SelectedProduct is null) { MessageBox.Show("Выберите продукт"); @@ -44,10 +41,10 @@ public override void Execute(object parameter) _viewModel.NewOrderDetails = new ObservableCollection(); } - var newOrderDetail = new OrderDetailModel() { Product=_viewModel.SelectedProduct, Amount=amount, Order=_viewModel.NewOrder}; + var newOrderDetail = new OrderDetailModel() { Product = _viewModel.SelectedProduct, Amount = amount, Order = _viewModel.NewOrder }; _viewModel.NewOrder.OrderDetails.Add(newOrderDetail); - _viewModel.NewOrderDetails.Add(newOrderDetail); + _viewModel.NewOrderDetails.Add(newOrderDetail); } - } + } } diff --git a/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs index bc35b86..28b86eb 100644 --- a/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddProductWindowOfChangeOrderCommand.cs @@ -4,17 +4,14 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { class AddProductWindowOfChangeOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderDetailService _orderDetailService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderDetailService _orderDetailService; public AddProductWindowOfChangeOrderCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) { _viewModel = viewModel; @@ -52,7 +49,7 @@ public override void Execute(object parameter) _viewModel.OrderDetails.Add(orderDetail); _orderDetailService.AddOrderDetailModel(amount, _viewModel.SelectedOrder.Id, _viewModel.SelectedProduct.Id); } - } - } +} + diff --git a/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs index af11801..4fc863f 100644 --- a/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddReviewWindowOfAddOrderCommand.cs @@ -1,19 +1,14 @@ -using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; +using Alligator.BusinessLayer.Models; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class AddReviewWindowOfAddOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; + private readonly TabItemOrdersViewModel _viewModel; public AddReviewWindowOfAddOrderCommand(TabItemOrdersViewModel viewModel) { @@ -29,7 +24,7 @@ public override void Execute(object parameter) MessageBox.Show("Введите текст отзыва"); return; } - + if (_viewModel.NewOrder.OrderReviews is null) { List orderReviews = new List(); @@ -38,15 +33,15 @@ public override void Execute(object parameter) } if (_viewModel.NewOrderReviews is null) { - + _viewModel.NewOrderReviews = new ObservableCollection(); } - var newOrderReview = new OrderReviewModel() { Order=_viewModel.NewOrder, Text = newReview }; + var newOrderReview = new OrderReviewModel() { Order = _viewModel.NewOrder, Text = newReview }; _viewModel.NewOrder.OrderReviews.Add(newOrderReview); - _viewModel.NewOrderReviews.Add(newOrderReview); + _viewModel.NewOrderReviews.Add(newOrderReview); _viewModel.NewReviewText = string.Empty; } - } + } } diff --git a/Alligator/Commands/TabItemOrders/AddReviewWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/AddReviewWindowOfOrderInfoCommand.cs index efe0a44..7156215 100644 --- a/Alligator/Commands/TabItemOrders/AddReviewWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/AddReviewWindowOfOrderInfoCommand.cs @@ -1,21 +1,16 @@ using Alligator.BusinessLayer; using Alligator.BusinessLayer.Models; -using Alligator.DataLayer.Entities; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { - internal class AddReviewWindowOfOrderInfoCommand : CommandBase + internal class AddReviewWindowOfOrderInfoCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderReviewService _orderReviewService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderReviewService _orderReviewService; public AddReviewWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderReviewService orderReviewService) { @@ -32,14 +27,14 @@ public override void Execute(object parameter) MessageBox.Show("Введите текст отзыва"); return; } - + if (_viewModel.SelectedOrder.OrderReviews is null) { List orderReviews = new List(); - - _viewModel.SelectedOrder.OrderReviews=orderReviews; + + _viewModel.SelectedOrder.OrderReviews = orderReviews; } - + if (_viewModel.OrderReviews is null) { ObservableCollection orderReviews = new ObservableCollection(); @@ -47,9 +42,9 @@ public override void Execute(object parameter) _viewModel.OrderReviews = orderReviews; } - var newOrderReview = new OrderReviewModel() {Order=_viewModel.SelectedOrder, Text=newReview }; + var newOrderReview = new OrderReviewModel() { Order = _viewModel.SelectedOrder, Text = newReview }; _viewModel.OrderReviews.Add(newOrderReview); - _orderReviewService.AddOrderReviewModel(newReview, _viewModel.SelectedOrder.Id); + _orderReviewService.AddOrderReviewModel(newReview, _viewModel.SelectedOrder.Id); _viewModel.NewReviewText = string.Empty; } } diff --git a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs index 0145f1d..19ba8c4 100644 --- a/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/ComeBackFirstWindowCommand.cs @@ -1,18 +1,13 @@ using Alligator.BusinessLayer; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class ComeBackFirstWindowCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; public ComeBackFirstWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { @@ -22,7 +17,7 @@ public ComeBackFirstWindowCommand(TabItemOrdersViewModel viewModel, OrderService public override void Execute(object parameter) { - _viewModel.AddOrderWindowVisibility= Visibility.Collapsed; + _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersWindowVisibility = Visibility.Visible; @@ -30,8 +25,8 @@ public override void Execute(object parameter) if (_orderService.GetOrders().Success is true) { var orders = _orderService.GetOrders().Data; - foreach (var order in orders) - _viewModel.AllOrders.Add(order); + foreach (var order in orders) + _viewModel.AllOrders.Add(order); } else { diff --git a/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs b/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs index d4038e6..f9d0394 100644 --- a/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteDetailCommand.cs @@ -1,18 +1,13 @@ using Alligator.BusinessLayer; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Commands.TabItemOrders { class DeleteDetailCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderDetailService _orderDetailService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderDetailService _orderDetailService; public DeleteDetailCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService) diff --git a/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs b/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs index 5a86144..a6da8b4 100644 --- a/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteNewDetailCommand.cs @@ -1,15 +1,10 @@ using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Commands.TabItemOrders { public class DeleteNewDetailCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; + private readonly TabItemOrdersViewModel _viewModel; public DeleteNewDetailCommand(TabItemOrdersViewModel viewModel) { diff --git a/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs b/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs index aa00391..82abf2f 100644 --- a/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteOrderCommand.cs @@ -1,10 +1,5 @@ using Alligator.BusinessLayer; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders @@ -12,10 +7,10 @@ namespace Alligator.UI.Commands.TabItemOrders public class DeleteOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; - private OrderDetailService _orderDetailService; - private OrderReviewService _orderReviewService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; + private readonly OrderDetailService _orderDetailService; + private readonly OrderReviewService _orderReviewService; public DeleteOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderService, OrderDetailService orderDetailService, OrderReviewService orderReviewService) { diff --git a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs index 11033cb..5e76335 100644 --- a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfAddOrderCommand.cs @@ -1,17 +1,11 @@ -using Alligator.BusinessLayer; -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Alligator.UI.VIewModels.TabItemsViewModels; namespace Alligator.UI.Commands.TabItemOrders { public class DeleteReviewWindowOfAddOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - + private readonly TabItemOrdersViewModel _viewModel; + public DeleteReviewWindowOfAddOrderCommand(TabItemOrdersViewModel viewModel) { _viewModel = viewModel; @@ -25,5 +19,5 @@ public override void Execute(object parameter) { _viewModel.NewOrderReviews.Remove(_viewModel.SelectedNewOrderReview); } - } + } } diff --git a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs index 98c4a97..50775fd 100644 --- a/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/DeleteReviewWindowOfOrderInfoCommand.cs @@ -1,17 +1,12 @@ using Alligator.BusinessLayer; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Commands.TabItemOrders { public class DeleteReviewWindowOfOrderInfoCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderReviewService _orderReviewService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderReviewService _orderReviewService; public DeleteReviewWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderReviewService orderReviewService) { diff --git a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs index c46aaa6..407da2e 100644 --- a/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs +++ b/Alligator/Commands/TabItemOrders/GetOrdersCommand.cs @@ -1,19 +1,12 @@ using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Commands.TabItemOrders { public class GetOrdersCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; public GetOrdersCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { diff --git a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs index 309de7a..84a5b95 100644 --- a/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenAddOrderWindowCommand.cs @@ -3,19 +3,15 @@ using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class OpenAddOrderWindowCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private ClientService _clientService; - private ProductService _productService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly ClientService _clientService; + private readonly ProductService _productService; public OpenAddOrderWindowCommand(TabItemOrdersViewModel viewModel, ClientService clientService, ProductService productService) { @@ -55,7 +51,7 @@ public override void Execute(object parameter) _viewModel.OrdersWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility = Visibility.Collapsed; - _viewModel.AddOrderWindowVisibility = Visibility.Visible; + _viewModel.AddOrderWindowVisibility = Visibility.Visible; } } } diff --git a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs index e861416..247a81d 100644 --- a/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenChangeOrderWindowOfOrderInfoCommand.cs @@ -1,36 +1,29 @@ using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; using Alligator.BusinessLayer.Services; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class OpenChangeOrderWindowOfOrderInfoCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderDetailService _orderDetailService; - private ClientService _clientService; - private ProductService _productService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderDetailService _orderDetailService; + private readonly ClientService _clientService; + private readonly ProductService _productService; - public OpenChangeOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService, ClientService clientService, ProductService productService) + public OpenChangeOrderWindowOfOrderInfoCommand(TabItemOrdersViewModel viewModel, OrderDetailService orderDetailService, ClientService clientService, ProductService productService) { - _viewModel = viewModel; + _viewModel = viewModel; _orderDetailService = orderDetailService; _clientService = clientService; _productService = productService; - - } + + } public override void Execute(object parameter) - { + { _viewModel.AddOrderWindowVisibility = Visibility.Collapsed; _viewModel.OrdersInfoWindowVisibility = Visibility.Collapsed; _viewModel.ChangeOrderWindowVisibility = Visibility.Visible; diff --git a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs index ad1a6e3..865c44e 100644 --- a/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs +++ b/Alligator/Commands/TabItemOrders/OpenOrderInfoWindowCommand.cs @@ -1,20 +1,15 @@ using Alligator.BusinessLayer; using Alligator.BusinessLayer.Models; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { public class OpenOrderInfoWindowCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; public OpenOrderInfoWindowCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { diff --git a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs index 859766e..2594692 100644 --- a/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs +++ b/Alligator/Commands/TabItemOrders/SaveChangedOrderCommand.cs @@ -1,20 +1,15 @@ using Alligator.BusinessLayer; using Alligator.BusinessLayer.Models; using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Alligator.UI.Commands.TabItemOrders { class SaveChangedOrderCommand : CommandBase { - private TabItemOrdersViewModel _viewModel; - private OrderService _orderService; + private readonly TabItemOrdersViewModel _viewModel; + private readonly OrderService _orderService; public SaveChangedOrderCommand(TabItemOrdersViewModel viewModel, OrderService orderService) { diff --git a/Alligator/Commands/TabItemProducts/AddProduct.cs b/Alligator/Commands/TabItemProducts/AddProduct.cs index bae9293..216ec98 100644 --- a/Alligator/Commands/TabItemProducts/AddProduct.cs +++ b/Alligator/Commands/TabItemProducts/AddProduct.cs @@ -1,15 +1,13 @@ using Alligator.BusinessLayer; -using Alligator.BusinessLayer.Models; using Alligator.UI.Helpers; using Alligator.UI.ViewModels.TabItemsViewModels; -using System.Collections.Generic; using System.Windows; namespace Alligator.UI.Commands.TabItemProducts { class AddProduct : CommandBase { - private TabItemProductsViewModel _viewModel; + private readonly TabItemProductsViewModel _viewModel; private readonly ProductService _productService; public AddProduct(TabItemProductsViewModel viewModel, ProductService productService) { @@ -43,7 +41,7 @@ public override void Execute(object parameter) } _viewModel.Products.Add(productModelActionResult.Data); - + _viewModel.VisibilityAddProduct = Visibility.Collapsed; _viewModel.VisibilityAllProducts = Visibility.Visible; } diff --git a/Alligator/Commands/TabItemProducts/AddProductTagToProductToEdit.cs b/Alligator/Commands/TabItemProducts/AddProductTagToProductToEdit.cs index 2dd0289..68724d2 100644 --- a/Alligator/Commands/TabItemProducts/AddProductTagToProductToEdit.cs +++ b/Alligator/Commands/TabItemProducts/AddProductTagToProductToEdit.cs @@ -1,6 +1,4 @@ using Alligator.UI.ViewModels.TabItemsViewModels; -using System; -using System.Linq; using System.Windows; namespace Alligator.UI.Commands.TabItemProducts diff --git a/Alligator/Commands/TabItemProducts/DeleteProduct.cs b/Alligator/Commands/TabItemProducts/DeleteProduct.cs index 400f853..4360346 100644 --- a/Alligator/Commands/TabItemProducts/DeleteProduct.cs +++ b/Alligator/Commands/TabItemProducts/DeleteProduct.cs @@ -21,7 +21,7 @@ public override void Execute(object parameter) if (userAnswer == MessageBoxResult.Yes) { var deleted = _productService.DeleteProduct(_viewModel.SelectedProduct); - if(!deleted) + if (!deleted) { MessageBox.Show("Ошибка при записи в базу данных", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; diff --git a/Alligator/Helpers/UserInputValidation.cs b/Alligator/Helpers/UserInputValidation.cs index 1baa7e0..1b41f07 100644 --- a/Alligator/Helpers/UserInputValidation.cs +++ b/Alligator/Helpers/UserInputValidation.cs @@ -1,10 +1,5 @@ -using Alligator.UI.VIewModels.TabItemsViewModels; -using System; -using System.Collections.Generic; -using System.Linq; +using System; using System.Net.Mail; -using System.Text; -using System.Threading.Tasks; namespace Alligator.UI.Helpers { diff --git a/Alligator/TabItems/TabItemCategories.xaml.cs b/Alligator/TabItems/TabItemCategories.xaml.cs index c194283..1442431 100644 --- a/Alligator/TabItems/TabItemCategories.xaml.cs +++ b/Alligator/TabItems/TabItemCategories.xaml.cs @@ -1,5 +1,4 @@ -using Alligator.UI.ViewModels.TabItemsViewModels; -using System.Windows.Controls; +using System.Windows.Controls; namespace Alligator.UI.TabItems {