/// <summary> /// Initilizes a new configution of a quotation /// </summary> /// <param name="window">A class that implements IWindowFactory</param> /// <param name="quotation">The quoation that need to be configured</param> public ConfigureQuotationViewModel(Action onClose, QuotationViewModel quotation, ObservableCollection <CustomerViewModel> activeCustomers, IWindowFactory windowFactory, UnitOfWork unitOfWork) : base(onClose) { Quotation = quotation; _windowFactory = windowFactory; _unitOfWork = unitOfWork; QuotationStatuses = new ObservableCollection <string>() { "Created", "Sent", "Lost", "Confirmed", "Canceled" }; CurrentStatusType = Quotation.CurrentStatus.Type; NeedToBeAdded = false; ActiveCustomers = activeCustomers; CurrentDeadline = Quotation.Deadline.ToShortDateString(); if (Quotation.Customer != null) { SelectedCustomerIndex = ActiveCustomers.IndexOf(ActiveCustomers.Where(x => x.ID == Quotation.Customer.ID).FirstOrDefault()); } // Commands SaveCommand = new RelayCommand(o => SaveChanges(), o => true); CancelCommand = new RelayCommand(CancelDialog, o => true); }
// Methods private void CreateNewQuotation() { QuotationViewModel quotation = new QuotationViewModel(new Quotation(new QuotationStatus(DateTime.Now, QuotationStatusType.Created))); Quotations.Add(quotation); _unitOfWork.QuotationRepository.Add(quotation.QuotationModel); _unitOfWork.Save(); IWindowService configureQuotationView = _windowFactory.GetWindowService(WindowType.ConfigureQuotationView); ConfigureQuotationViewModel configureQuotationViewModel = new ConfigureQuotationViewModel(configureQuotationView.Close, quotation, ActiveCustomers, _windowFactory); configureQuotationView.OpenAsDialog(configureQuotationViewModel); if (!configureQuotationViewModel.NeedToBeAdded) { _unitOfWork.QuotationRepository.Delete(quotation.QuotationModel); Quotations.Remove(quotation); _unitOfWork.Save(); } }
public void AddQuotation(Quotation quotation) { int index = CustomerModel.GetQuotationIndexByID(quotation); // If the quotation does not exist, add it to the quotation collection. Otherwise throw exception. if (index == -1) { quotation.Customer = CustomerModel; QuotationViewModel quotationViewModel = new QuotationViewModel(quotation); quotationViewModel.Customer = this; Quotations.Add(quotationViewModel); CustomerModel.Quotations.Add(quotation); } else { throw new InvalidOperationException("Cannot add already existing quotation"); } }
public PrintQuotationViewModel(Action onClose, QuotationViewModel quotation, IPrintableWindowService printer) : base(onClose) { Quotation = quotation; _printer = printer; PrintPDFCommand = new RelayCommand(o => _printer.PrintPDFDocument(), o => true); }