public void SetPurchaseOrder(WpfPurchaseOrder wpfPurchaseOrder)
        {
            PurchaseOrder = wpfPurchaseOrder;

            if (EditMode)
            {
                var purchaseOrderWithLines = _unitOfWork
                                             .PurchaseOrders
                                             .GetPurchaseOrderByPurchaseOrderNumber(wpfPurchaseOrder.PurchaseOrderNumber, true);

                if (purchaseOrderWithLines == null)
                {
                    throw new ApplicationException("Invalid Purchase Order");
                }

                PurchaseOrder.Lines = new BindingList <WpfPurchaseOrderLine>(
                    RestproMapper.MapPurchaseOrderLineListToWpfPurchaseOrderLineList(purchaseOrderWithLines
                                                                                     .PurchaseOrderLines.ToList()));
            }
            else
            {
                PurchaseOrder.Lines               = new BindingList <WpfPurchaseOrderLine>();
                PurchaseOrder.CreatedBy           = _unitOfWork.Users.SingleOrDefault(x => x.Id == CurrentUser.Id).Id;
                PurchaseOrder.PurchaseOrderNumber = GenerateNewPurchaseOrderNumber().ToString();
                PurchaseOrder.StatusId            = Statuses.New.ToString();
                PurchaseOrder.Active              = true;
                PurchaseOrder.DateCreated         = DateTime.Today;

                _unitOfWork.PurchaseOrders
                .AddPurchaseOrder(
                    RestproMapper.MapWpfPurchaseOrderToPurchaseOrderWithLines(PurchaseOrder));

                PurchaseOrder.Id = _unitOfWork.PurchaseOrders
                                   .SingleOrDefault(p => p.PurchaseOrderNumber == PurchaseOrder.PurchaseOrderNumber).Id;
            }


            if (PurchaseOrder != null)
            {
                PurchaseOrder.ErrorsChanged -= RaiseCanExecuteChanged;
            }

            PurchaseOrder.ErrorsChanged          += RaiseCanExecuteChanged;
            this.PurchaseOrder.Lines.ListChanged += this.OnListChanged;
        }
        private async void OnSave()
        {
            var purchaseOrderEntity = RestproMapper.MapWpfPurchaseOrderToPurchaseOrderWithLines(PurchaseOrder);

            if (_editMode)
            {
                _unitOfWork.PurchaseOrders.UpdatePurchaseOrder(purchaseOrderEntity);
            }
            else
            {
                _unitOfWork.PurchaseOrders.UpdatePurchaseOrder(purchaseOrderEntity);
                _unitOfWork.Complete();
            }

            var controller = await dialogCoordinator.ShowMessageAsync(this, "Success", "Items Saved Successfully. You Rock!");

            if (controller == MessageDialogResult.Affirmative)
            {
                Done(CurrentUser);
            }
        }