private async Task <bool> GetTransactionDetails()
        {
            var details = new ObservableCollection <PaymentDetails>((await APICall.GetPaymentDetails(App.UserName)).GroupBy(d => d.ContainerId).Select(c => c.First()).ToList());


            //vm.PaymentDetails.ToList().AddRange((_paymentdetail).Where(x => !vm.PaymentDetails.Select(y => y.ContainerId).Contains(x.ContainerId)).Select(x => x).ToList());
            var supplierShipment = (await APICall.GetShipmentDetail(App.UserName)).Where(x => !details.Select(y => y.ContainerId).Contains(x.ContainerId)).Select(x => x).ToList();

            vm.Balance = 0;

            details.ToList().ForEach(x => { vm.Balance += x.Quantity; vm.Bank = x.Bank; if (x.Quantity > 0)
                                            {
                                                x.Status = Status.GatedIn;
                                            }
                                     });
            supplierShipment.ForEach(x => details.Add(new PaymentDetails()
            {
                ContainerId = x.ContainerId, ContainerName = x.ContainerName, Quantity = 0, Unit = x.Quantity
            }));
            await UpdateStatus(details.ToList());

            vm.PaymentDetails = details;
            await TrackShipmentStatus();

            return(true);
        }
        private async void Approve_Click(object sender, RoutedEventArgs e)
        {
            prg1.Visibility            = Visibility.Visible;
            ((Button)sender).IsEnabled = false;
            var data = ((Button)sender).DataContext as ShipmentDetails;
            ShipmentDetailForPayment shipmentDetailrequest = new ShipmentDetailForPayment()
            {
                ContainerId   = data.Id,
                ContainerName = data.ContainerName,
                Quantity      = Convert.ToInt32(data.Unit),
                SupplierName  = App.UserName
            };
            await APICall.AddShipmentDetail(shipmentDetailrequest.ContainerId, shipmentDetailrequest);

            ShipmentDetails shipmentRequest = new ShipmentDetails()
            {
                Id            = data.Id,
                ContainerName = data.ContainerName,
                Weight        = Convert.ToInt32(data.Weight),
                _status       = 0,
                Desc          = string.Format("Container {0} is Approved by {1}", data.ContainerName, App.UserName),
                Source        = data.Source,
                Destination   = data.Destination
            };
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            prg.Visibility  = Visibility.Collapsed;
            prg1.Visibility = Visibility.Collapsed;
        }
 private async Task UpdateStatus(List <PaymentDetails> contaiinerList)
 {
     foreach (var container in contaiinerList)
     {
         container.Status          = (Status)(await APICall.GetContainerStatus(container.ContainerId));
         container.TransactionTime = (await APICall.GetContainerTimespan(container.ContainerId));
     }
 }
        private async void SetSupplierAndBank()
        {
            //var Supplierfunc = App.mainWindow.shipmentContract.GetFunction("Supplier");
            var Supplier = await APICall.GetContainerSupplier(Container.Id);

            txtsupplier.Text += " : " + Supplier;
            //var Bankfunc = App.mainWindow.paymentContract.GetFunction("Bank");
            //var Bank = await Bankfunc.CallAsync<string>(Supplier);
            //txtbank.Text += " : " + Bank;
        }
        private async void UpdateShipmentStatus(string desc, int status)
        {
            ShipmentDetails shipmentRequest = new ShipmentDetails()
            {
                Id            = Container.Id,
                ContainerName = Container.ContainerName,
                Weight        = Convert.ToInt32(Container.Weight),
                _status       = status,
                Desc          = desc,
                Source        = Container.Source,
                Destination   = Container.Destination
            };
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            prg.Visibility = Visibility.Collapsed;
        }
        private async Task <bool> TrackShipmentStatus()
        {
            try
            {
                var trackingshipmentdetails = await APICall.TrackShipmentsStatus();


                if (trackingshipmentdetails != null && trackingshipmentdetails.Count > 0)
                {
                    foreach (var detail in trackingshipmentdetails)
                    {
                        var Supplier = await APICall.GetContainerSupplier(detail.Id);

                        if (vm.ContainerList.Where(l => l.Id == detail.Id).Count() == 0)
                        {
                            var unit = await APICall.GetContainerUnit(detail.Id);

                            vm.ContainerList.Insert(0, new ShipmentDetails()
                            {
                                Id              = detail.Id,
                                ContainerName   = detail.ContainerName,
                                _status         = (int)detail.Status,
                                IsVisible       = Visibility.Collapsed,
                                Weight          = Convert.ToInt32(detail.Weight),
                                Source          = detail.Source,
                                Destination     = detail.Destination,
                                TransactionTime = detail.TransactionTime,
                                Unit            = unit,
                                Supplier        = Supplier
                            });
                        }
                        else
                        {
                            vm.ContainerList.Where(l => l.Id == detail.Id).First()._status  = detail._status;
                            vm.ContainerList.Where(l => l.Id == detail.Id).First().Supplier = Supplier;
                        }
                    }
                }


                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private async void CalculatePayment()
        {
            var detail = await APICall.GetContainerShipmentDetail(Container.Id);

            if (detail != null)
            {
                PaymentDetails details = new PaymentDetails()
                {
                    ContainerId   = Container.Id,
                    ContainerName = Container.ContainerName,
                    Quantity      = detail.Quantity,
                    SupplierName  = detail.SupplierName,
                    Unit          = detail.Quantity
                };
                await APICall.CalculatePayment(details.ContainerId, details);
            }
        }
        private async Task <bool> TrackShipment()
        {
            try
            {
                var trackingdetails = await APICall.TrackShipmentStatus(Container.Id);

                TrackingDetails.Clear();
                foreach (var detail in trackingdetails)
                {
                    TrackingDetails.Insert(0, detail);
                }
                Container._status = (int)trackingdetails.Last().Status;
            }
            catch
            {
            }
            SetStatus();
            return(true);
        }
        private async Task <bool> SendForApprovals(int docstatus, int containerstatus)
        {
            string desc = string.Empty;

            if (docstatus == 1)
            {
                desc = String.Format("Document {0} is Approved by {1}", selectedItem.Document, txtUserName.Text);
            }
            else
            {
                desc = String.Format("Document {0} is Rejected by {1}", selectedItem.Document, txtUserName.Text);
            }
            ApprovalsDetails approvalRequest = new ApprovalsDetails()
            {
                DocId           = selectedItem.DocId,
                Document        = selectedItem.Document,
                Id              = selectedItem.Id,
                Url             = selectedItem.Url,
                _status         = docstatus,
                TransactionTime = DateTime.Now.ToString()
            };
            await APICall.UpdateApprovalStatus(approvalRequest.Id, approvalRequest);

            ShipmentDetails shipmentRequest = new ShipmentDetails()
            {
                Id            = Container.Id,
                ContainerName = Container.ContainerName,
                Weight        = Convert.ToInt32(Container.Weight),
                _status       = containerstatus,
                Desc          = desc,
                Source        = Container.Source,
                Destination   = Container.Destination
            };
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            prg.Visibility     = Visibility.Collapsed;
            btnSave.IsEnabled  = true;
            btnClose.IsEnabled = true;

            return(true);
        }
        private async void VerifyWeight()
        {
            try
            {
                prg.Visibility = Visibility.Visible;
                ShipmentDetails shipmentRequest = new ShipmentDetails()
                {
                    Id            = Container.Id,
                    ContainerName = Container.ContainerName,
                    Weight        = Convert.ToInt32(txtWeight.Text),
                    Source        = Container.Source,
                    Destination   = Container.Destination
                };
                await APICall.VerifyWeight(shipmentRequest.Id, shipmentRequest);

                prg.Visibility = Visibility.Collapsed;
            }
            catch
            {
            }
        }
        private async Task <bool> TrackApprovals()
        {
            try
            {
                listDoc.DataContext = vm;
                listDoc.ItemsSource = vm.Approvalsdetail;
                var detail = await APICall.TrackApproval(Container.Id);

                switch (App.UserType)
                {
                case UserType.Excise:
                    btnExport.Visibility = Visibility.Collapsed;
                    if (vm.Approvalsdetail.Count() < 2)
                    {
                        vm.Approvalsdetail = new ObservableCollection <ApprovalsDetails>(detail.Where(x => x.DocId == 1 || x.DocId == 2).ToList());
                    }
                    break;

                case UserType.VGM:
                    btnExport.Visibility = Visibility.Collapsed;
                    if (vm.Approvalsdetail.Count() == 0)
                    {
                        vm.Approvalsdetail = new ObservableCollection <ApprovalsDetails>(detail.Where(x => x.DocId == 3).ToList());
                    }
                    break;

                case UserType.Custom:
                    btnExport.Visibility = Visibility.Visible;
                    if (vm.Approvalsdetail.Count() == 0)
                    {
                        vm.Approvalsdetail = new ObservableCollection <ApprovalsDetails>(detail.Where(x => x.DocId == 4).ToList());
                    }
                    break;

                default:
                    btnExport.Visibility = Visibility.Collapsed;
                    if (vm.Approvalsdetail.Count() < 4)
                    {
                        vm.Approvalsdetail = new ObservableCollection <ApprovalsDetails>(detail.ToList());
                    }
                    break;
                }
                //Approvalsdetail.Clear();
                foreach (var s in detail)
                {
                    if (vm.Approvalsdetail.Where(x => x.Document == s.Document).Count() > 0)
                    {
                        vm.Approvalsdetail.Where(x => x.Document == s.Document).First()._status = s._status;
                    }
                    //Approvalsdetail.Add(s.Event);
                }

                if (detail.Where(c => c.Status == ApprovalStatus.Approved).Count() == 2 && TrackingDetails.Count == 8 && Container.Status == Status.Initiated && App.UserType == UserType.Excise && !Approved)
                {
                    Approved          = true;
                    Container._status = (int)Status.ExciseApproved;

                    ShipmentDetails shipmentRequest = new ShipmentDetails()
                    {
                        Id            = Container.Id,
                        ContainerName = Container.ContainerName,
                        Weight        = Convert.ToInt32(Container.Weight),
                        _status       = 1,
                        Desc          = String.Format("Documents for container {0} are approved successfully by {1}", Container.ContainerName, App.UserName),
                        Source        = Container.Source,
                        Destination   = Container.Destination
                    };
                    await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);
                }
                if (detail.Where(c => c.Status == ApprovalStatus.Approved).Count() == 3 && Container.Status == Status.ExciseApproved && App.UserType == UserType.VGM && !weighingApproved)
                {
                    prg.Visibility   = Visibility.Visible;
                    weighingApproved = true;
                    VerifyWeight();
                }


                var doc = (ApprovalsDetails)listDoc.SelectedItem;
                //if (doc._status == 0 && App.UserType == UserType.Custom)
                //{
                //    stkAppprover.Visibility = Visibility.Visible;
                //}
                //else
                //{
                //    stkAppprover.Visibility = Visibility.Collapsed;
                //}
            }
            catch
            {
            }
            return(true);
        }
        private async Task <bool> InitateShipment()
        {
            string url1 = "http://idtp376/Pdf/GST_B2B_INVOICE_CASES-CF.pdf";
            string url2 = "http://idtp376/Pdf/Ethereum%20Multi-Member%20Consortium%20Network.pdf";
            string url3 = "http://idtp376/Pdf/ASF-VGM-Declaration-Form.pdf";
            string url4 = "http://idtp376/Pdf/Ethereum%20Consortium%20Blockchain%20in%20Azure%20Marketplace.pdf";

            ShipmentDetailForPayment shipmentDetailrequest = new ShipmentDetailForPayment()
            {
                ContainerId   = detail.txtContainerId.Text,
                ContainerName = detail.txtContainerName.Text,
                Quantity      = Convert.ToInt32(detail.txtQuantity.Text),
                SupplierName  = string.Empty
            };
            await APICall.AddShipmentDetail(shipmentDetailrequest.ContainerId, shipmentDetailrequest);

            ShipmentDetails shipmentRequest = new ShipmentDetails()
            {
                Id            = detail.txtContainerId.Text,
                ContainerName = detail.txtContainerName.Text,
                Weight        = Convert.ToInt32(detail.txtContainerWeight.Text),
                _status       = 9,
                Desc          = string.Format("Container {0} is initiated successfully at {1} from {2} to {3}", detail.txtContainerName.Text, DateTime.Now.ToString(), detail.txtSource.Text, detail.txtDestination.Text),
                Source        = detail.txtSource.Text,
                Destination   = detail.txtDestination.Text
            };
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            ApprovalsDetails approvalRequest = new ApprovalsDetails()
            {
                DocId           = 1,
                Document        = "Excise Form",
                Id              = detail.txtContainerId.Text,
                Url             = url1,
                _status         = 0,
                TransactionTime = DateTime.Now.ToString()
            };
            await APICall.UpdateApprovalStatus(approvalRequest.Id, approvalRequest);

            shipmentRequest.Desc = string.Format("Excise Form for Container {0} is uploaded successfully at {1}", detail.txtContainerName.Text, DateTime.Now.ToString());
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            approvalRequest = new ApprovalsDetails()
            {
                DocId           = 2,
                Document        = "Packaging List",
                Id              = detail.txtContainerId.Text,
                Url             = url2,
                _status         = 0,
                TransactionTime = DateTime.Now.ToString()
            };
            await APICall.UpdateApprovalStatus(approvalRequest.Id, approvalRequest);

            shipmentRequest.Desc = string.Format("Packaging List for Container {0} is uploaded successfully at {1}", detail.txtContainerName.Text, DateTime.Now.ToString());
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            approvalRequest = new ApprovalsDetails()
            {
                DocId           = 3,
                Document        = "VGM",
                Id              = detail.txtContainerId.Text,
                Url             = url3,
                _status         = 0,
                TransactionTime = DateTime.Now.ToString()
            };
            await APICall.UpdateApprovalStatus(approvalRequest.Id, approvalRequest);

            shipmentRequest.Desc = string.Format("VGM for Container {0} is uploaded successfully at {1}", detail.txtContainerName.Text, DateTime.Now.ToString());
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            approvalRequest = new ApprovalsDetails()
            {
                DocId           = 4,
                Document        = "Custom Form",
                Id              = detail.txtContainerId.Text,
                Url             = url4,
                _status         = 0,
                TransactionTime = DateTime.Now.ToString()
            };
            await APICall.UpdateApprovalStatus(approvalRequest.Id, approvalRequest);

            shipmentRequest.Desc    = string.Format("Custom Form for Container {0} is uploaded successfully at {1}", detail.txtContainerName.Text, DateTime.Now.ToString());
            shipmentRequest._status = 11;
            await APICall.AddShipmentStatus(shipmentRequest.Id, shipmentRequest);

            return(true);
        }