using OOO_WriteAndClear.DBModels;
using OOO_WriteAndClear.EventBus.Signals;
using OOO_WriteAndClear.MVP.Models.OrderFormerer;
using OOO_WriteAndClear.MVP.MVPInterfaces;
using OOO_WriteAndClear.MVP.Presenters;
using OOO_WriteAndClear.MVP.Views;
using OOO_WriteAndClear.MVP.Views.DisplayingUserControlManager;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace OOO_WriteAndClear.Views
{
///
/// Логика взаимодействия для MainApplicationWindow.xaml
///
public partial class MainApplicationWindow : Window, IMainApplicationWindowContract.IView
{
public MainApplicationWindow()
{
InitializeComponent();
_presenter = new MainApplicationWindowPresenter(this);
_displayingUserControlManager = new DisplayingUserControlManager(this, new AuthorizationUserControl());
EventBus.EventBus.GetService().Subscribe(TransferUserToNextUC);
EventBus.EventBus.GetService().Subscribe(OpenOrderCart);
EventBus.EventBus.GetService().Subscribe(BackAuthorizationUserControl);
EventBus.EventBus.GetService().Subscribe(GoToProductsUserControl);
EventBus.EventBus.GetService().Subscribe(GoToOrdersUserControl);
EventBus.EventBus.GetService().Subscribe(BackToMenuFeatures);
EventBus.EventBus.GetService().Subscribe(ShowOrderTalon);
}
private readonly IMainApplicationWindowContract.IPresenter _presenter;
///
/// Менеджер для инкапсуляции логики смены UC
///
private readonly DisplayingUserControlManager _displayingUserControlManager;
private void TransferUserToNextUC(UserWasLoggedSignal signal)
{
AddUserInAppResources(signal.User);
if(signal.User.UserId == -1 || signal.User.UserRole == 1)
{
_displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
return;
}
_displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
return;
}
private void OpenOrderCart(GoToOrderCartSignal goToOrderCartSignal)
{
OrderCartWindow window = new OrderCartWindow(goToOrderCartSignal.OrderFormerer);
window.ShowDialog();
EventBus.EventBus.GetService().Invoke(new OrderCartWasClosedSignal());
}
private void BackAuthorizationUserControl(BackToAuthorizationUserControlSignal signal)
{
_displayingUserControlManager.DisplayingUserControl = new AuthorizationUserControl();
}
private void GoToProductsUserControl(GoToProductsUserControlSignal signal)
{
_displayingUserControlManager.DisplayingUserControl = new ProductsUserControl();
}
private void GoToOrdersUserControl(GoToOrdersUserControlSignal signal)
{
_displayingUserControlManager.DisplayingUserControl = new OrdersUserControl();
}
private void BackToMenuFeatures(BackToFeaturesMenuUserControlSignal signal)
{
_displayingUserControlManager.DisplayingUserControl = new FeaturesMenuUserControl();
}
private void ShowOrderTalon(ShowOrderTalonSignal signal)
{
new OrderReceipt(signal.Order).ShowDialog();
}
private void AddUserInAppResources(User user)
{
if (Application.Current.Resources.Contains("CurrentUser"))
Application.Current.Resources["CurrentUser"] = user;
else
Application.Current.Resources.Add("CurrentUser", user);
}
}
}