public OrderSaveAndContinueLater GetById(Guid id)
 {
     var order = new OrderSaveAndContinueLater();
     var item = _appTempTransactionRepository.GetById(id);
     if(item!=null)
     {
         order = JsonConvert.DeserializeObject<OrderSaveAndContinueLater>(item.Json);
     }
     return order;
 }
 public void Save(OrderSaveAndContinueLater order)
 {
     var temp = new AppTempTransaction
                    {
                        Id = order.Id,
                        Json = JsonConvert.SerializeObject(order),
                        TransactionStatus = false,
                        TransactionType = order.OrderType.ToString()
                    };
     _appTempTransactionRepository.Save(temp);
 }
       private OrderItemSummary Map(OrderSaveAndContinueLater orderSummary, int count)
       {
           var pricingService = Using<IDiscountProWorkflow>(NestedContainer);

           var orderSummaryMapped= new OrderItemSummary()
           {
               SequenceNo = count + 1,
               OrderId = orderSummary.Id,
               TotalVat = orderSummary.LineItem.Sum(s=>s.UnitVat*s.Quantity),
               GrossAmount = (orderSummary.LineItem.Sum(s =>(s.UnitVat +s.UnitPrice)* s.Quantity).GetTruncatedValue()).GetTotalGross(),

               NetAmount = (orderSummary.LineItem.Sum(s => ((s.UnitVat + s.UnitPrice) * s.Quantity).GetTruncatedValue())).GetTotalGross(),
               Required = orderSummary.Required,
               SaleDiscount = orderSummary.SaleDiscount,
               OutstandingAmount =0,
                   
               OrderReference = "Not Generated",
               PaidAmount = 0,
               Status =DocumentStatus.New,
               Salesman = orderSummary.Salesman,
               ExRefNo = "",
               Outlet = orderSummary.Outlet

           };
           return orderSummaryMapped;

       }
        protected override void SaveAndContinue()
        {
            if (!LineItem.Any())
            {
                MessageBox.Show("Make sure you have atleast one item");
                return;

            }
            using (var c = NestedContainer)
            {
                var saveAndContinue = new OrderSaveAndContinueLater();
                saveAndContinue.OrderType = OrderType.SalesmanToDistributor;
                saveAndContinue.Id = OrderId != Guid.Empty ? OrderId : Guid.NewGuid();
                saveAndContinue.SalesmanId = SelectedSalesman.Id;
                saveAndContinue.Required = DateRequired;
                foreach (var item in LineItem)
                {
                    var i = new OrderSaveAndContinueLaterItem();
                    i.DiscountType = item.DiscountType;
                    i.LineItemType = item.LineItemType;
                    i.ProductId = item.ProductId;
                    i.ProductType = item.ProductType;
                    i.Quantity = item.Quantity;
                    i.UnitDiscount = item.UnitDiscount;
                    i.UnitPrice = item.UnitPrice;
                    i.UnitVat = item.UnitVAT;
                    saveAndContinue.LineItem.Add(i);

                }

                Using<IOrderSaveAndContinueService>(c).Save(saveAndContinue);
                MessageBox.Show("Stockist Purchase Order saved successfully ");
                var uri = "/views/Orders_Stockist/StockistPurchaseOrderListing.xaml";
                NavigateCommand.Execute(uri);


            }
        }