private void LoadProductsToImport()
        {
           if(!FileUtility.ValidateFile(SelectedPath))return;
            using (var c=NestedContainer)
            {

                try
                {
                    ImportItems = Using<IProductImportService>(c).Import(SelectedPath);

                    var productImports = ImportItems as List<ProductImport> ?? ImportItems.ToList();
                    if (productImports.Any())
                    {
                        var items = productImports.Select((n, i) => new ProductImportItem()
                                                                        {
                                                                            SequenceNo = i + 1,
                                                                            BrandCode = n.BrandCode,
                                                                            Description = n.Description,
                                                                            DiscountGroup = n.DiscountGroup,
                                                                            ExFactoryPrice = n.ExFactoryPrice,
                                                                            PackagingCode = n.PackagingCode,
                                                                            PackagingTypeCode = n.PackagingTypeCode,
                                                                            ProductCode = n.ProductCode,
                                                                            ProductFlavourCode = n.ProductFlavourCode,
                                                                            ProductTypeCode = n.ProductTypeCode,
                                                                            VATClass = n.VATClass,
                                                                            CustomerDiscount = n.CustomerDiscount,
                                                                            IsChecked = false
                                                                        }).AsQueryable();
                        
                        PagedList = new PagenatedList<ProductImportItem>(items, CurrentPage, ItemsPerPage,items.Count());
                        
                            ProductImportList.Clear();
                        PagedList.ToList().ForEach(ProductImportList.Add);

                        UpdatePagenationControl();

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);

                }
            }
        }
 protected void LoadEntityContacts(MasterEntity entity)
 {
     _entity = entity;
     using (var c = NestedContainer)
     {
         ContactsList.Clear();
         var contacts = Using<IContactRepository>(c).GetByContactsOwnerId(entity.Id, ShowInactive)
             .Where(n => (n.Firstname.ToLower().Contains(SearchText.ToLower()) ||
                          n.Lastname.ToLower().Contains(SearchText.ToLower()) ||
                          n.MobilePhone.ToLower().Contains(SearchText.ToLower()))
             );
         _pagedList = new PagenatedList<Contact>(contacts.AsQueryable(), CurrentPage, ItemsPerPage, contacts.Count());
         _pagedList.ToList().ForEach(
             n => ContactsList.Add(new VMContactItem { Contact = n, IsDirty = false, IsNew = false }));
         UpdatePagenationControl();
     }
 }
        protected override void Reload()
        {
            if (!FileUtility.ValidateFile(SelectedPath)) return;
             using (var c = NestedContainer)
             {

                 MainWindowViewModel.GlobalStatus = string.Format("Loading: {0}", LoadedImportItem);
                 try
                 {

                     ImportItems = Using<IDistributorSalesmanImportService>(c).Import(SelectedPath);
                     var imports = ImportItems as List<DistributorSalesmanImport> ?? ImportItems.ToList();
                     if (imports.Any())
                     {
                         var importready = imports.Select((n, i) => new DistributorSalesmanImportItem()
                                                                        {
                                                                            SequenceNo = i + 1,
                                                                            DistributorCode = n.DistributorCode,
                                                                            Name = n.Name,
                                                                            PayRollNumber = n.PayRollNumber,
                                                                            IsChecked = false,
                                                                            SalesmanCode = n.SalesmanCode,
                                                                          //  SalesmanPhoneNumber = n.SalesmanPhoneNumber
                                                                        }).ToList();
                         SalesmanImportList.Clear();
                        PagedList = new PagenatedList<DistributorSalesmanImportItem>(importready.AsQueryable(),
                                                                                            CurrentPage,
                                                                                            ItemsPerPage,
                                                                                            importready.Count());
                         PagedList.ToList().ForEach(SalesmanImportList.Add);

                         UpdatePagenationControl();
                         MainWindowViewModel.GlobalStatus = string.Format("Loaded:{0}", LoadedImportItem);
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);
                     MainWindowViewModel.GlobalStatus = string.Format("Error loading {0}", LoadedImportItem);
                 }
             }

        }
        protected override void Reload()
        {
            if (!FileUtility.ValidateFile(SelectedPath)) return;
            using (var c = NestedContainer)
            {
                try
                {
                    ImportItems = Using<IPricingImportService>(c).Import(SelectedPath);
                    var imports = ImportItems as List<PricingImport> ?? ImportItems.ToList();
                    if (imports.Any())
                    {
                        var importready = imports.Select((n, i) => new PricingImportItem()
                                                                       {
                                                                           SequenceNo = i + 1,
                                                                           IsChecked = false,
                                                                           ProductCode = n.ProductCode,
                                                                           SellingPrice = n.SellingPrice,
                                                                           ExFactoryRate = n.ExFactoryRate,
                                                                           PricingTireCode = n.PricingTireCode

                                                                       }).AsQueryable();

                        PagedList = new PagenatedList<PricingImportItem>(importready.AsQueryable(),
                                                                                               CurrentPage,
                                                                                               ItemsPerPage,
                                                                                               importready.Count());
                        PricingImportList.Clear();
                        PagedList.ToList().ForEach(PricingImportList.Add);
                       
                        UpdatePagenationControl();
                        
                        
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);

                }
            }
        }
        protected override void Reload()
        {
            if (!FileUtility.ValidateFile(SelectedPath)) return;
            using (var c = NestedContainer)
            {
                try
                {
                    ImportItems = Using<IShipToAddressImportService>(c).Import(SelectedPath);
                    var imports = ImportItems as List<ShipToAddressImport> ?? ImportItems.ToList();
                    if (imports.Any())
                    {
                        var importready = imports.Select((n, i) => new ShipToAddressImportItem()
                                                                       {
                                                                           SequenceNo = i + 1,
                                                                           IsChecked = false,
                                                                           Name = n.Code,
                                                                           Description = n.Description,
                                                                           OutletCode = n.OutletCode,
                                                                           PhysicalAddress = n.PhysicalAddress,
                                                                           PostalAddress = n.PostalAddress,
                                                                           Latitude = n.Latitude,
                                                                           Longitude = n.Longitude
                                                                       }).ToList();
                        ShipToAddressesImportList.Clear();
                        PagedList = new PagenatedList<ShipToAddressImportItem>(importready.AsQueryable(),
                                                                                             CurrentPage,
                                                                                             ItemsPerPage,
                                                                                             importready.Count());
                        PagedList.ToList().ForEach(ShipToAddressesImportList.Add);

                        UpdatePagenationControl();
                       
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);

                }
            }
        }
       private void LoadDiscountGroupsToImport()
       {
           if (!FileUtility.ValidateFile(SelectedPath)) return;
           using (var c = NestedContainer)
           {
               try
               {
                   ImportItems = Using<IProductDiscountGroupImportService>(c).Import(SelectedPath);
                   var imports = ImportItems as List<ProductDiscountGroupImport> ?? ImportItems.ToList();
                   if (imports.Any())
                   {
                       var importready = imports.Select((n, i) => new DiscountGroupImportItem()
                       {
                           SequenceNo = i + 1,
                           IsChecked = false,
                           ProductCode = n.ProductCode,
                           DiscontGroupCode = n.DiscontGroupCode,
                           DiscountValue = n.DiscountValue

                       }).AsQueryable();

                       PagedList = new PagenatedList<DiscountGroupImportItem>(importready.AsQueryable(),
                                                                                              CurrentPage,
                                                                                              ItemsPerPage,
                                                                                              importready.Count());
                       DiscountGroupImportList.Clear();
                       PagedList.ToList().ForEach(DiscountGroupImportList.Add);

                       UpdatePagenationControl();


                   }
               }
               catch (Exception ex)
               {
                   MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);

               }
           }
       }
        internal void LoadConfirmedOrders()
       {
           Application.Current.Dispatcher.BeginInvoke(
               new Action(
                   () =>
                       {
                           using (var c = NestedContainer)
                           {
                               var orders = Using<IMainOrderRepository>(c)
                                   .PagedDocumentList(CurrentPage, ItemsPerPage, StartDate, EndDate,
                                                      OrderType.OutletToDistributor, DocumentStatus.Confirmed,
                                                      SearchText);
                                 
                               
                               var items = orders
                                   .Select((n, i) => new OrderItemSummary()
                                                         {
                                                             SequenceNo = i + 1,
                                                             OrderId = n.OrderId,
                                                             TotalVat = n.TotalVat,
                                                             GrossAmount = n.GrossAmount,
                                                             NetAmount = n.NetAmount,
                                                             Required = n.Required,
                                                             OutstandingAmount =
                                                                 FormatOutstandingAmount(n.OutstandingAmount),
                                                             OrderReference = n.OrderReference,
                                                             PaidAmount = n.PaidAmount,
                                                             Status = n.Status,
                                                             Salesman = n.Salesman,
                                                             ShippingAddress = GetShippingAddress(n.OrderId),
                                                             IsChecked = false
                                                             
                                                         }).AsQueryable();

                               _pagedItemSummaries = new PagenatedList<OrderItemSummary>(items, CurrentPage, ItemsPerPage,
                                                                                                  items.Count());
                               OrdersSummaryList.Clear();
                              
                               _pagedItemSummaries.ToList().ForEach(OrdersSummaryList.Add);

                               UpdatePagenationControl();
                           }
                       }));
       }
        private void Load(IEnumerable<ApprovedOrderImport> imports)
        {
            using (var c = NestedContainer)
            {
                var importsAuditRepository = Using<IExportImportAuditRepository>(c);
                var validImportsItems =
                    imports.Where(
                        approvedOrderImport => !importsAuditRepository.IsImported(approvedOrderImport.OrderReference)).
                        ToList();
               
                var items = validImportsItems.Select((n, i) => new ImportOrderItemSummary()
                                                         {
                                                             SequenceNo = i + 1,
                                                             DistributrCode =string.IsNullOrEmpty(n.DistributrCode)?GetDistributorCode(n.OrderReference):"",
                                                             OrderReference = n.OrderReference,
                                                             OutletCode = n.OutletCode,
                                                             ProductCode = n.ProductCode,
                                                             OrderDate=n.OrderDate,
                                                            SalesmanCode = n.SalesmanCode,
                                                             ApprovedQuantity = n.ApprovedQuantity
                                                         }).AsQueryable();

                PagedList = new PagenatedList<ImportOrderItemSummary>(items, CurrentPage, ItemsPerPage,
                                                                      items.Count());

                PagedList.ToList().ForEach(ImportOrderItemsSummaryList.Add);

                UpdatePagenationControl();
                
                if (!validImportsItems.Any())
                    UploadStatusMessage = "All orders in file already imported";
            }

        }
 private void LoadShipToAddress()
 {
    ShippingAddresses.Clear();
     DeletedAddresses.Clear();
      if(outlet !=null)
      {
          var addresses = outlet.ShipToAddresses.Where(n => n._Status != EntityStatus.Deleted).ToList();
          if(!string.IsNullOrEmpty(SearchText))
          {
              SearchText = SearchText.ToLower();
              addresses =
                  addresses.Where(
                      p =>
                      p.Code != null && p.Code.ToLower().Contains(SearchText) ||
                      p.Name != null && p.Name.ToLower().Contains(SearchText)).ToList();
          }
          
          if(addresses.Count>10)
          {
              PagedList=new PagenatedList<Core.Domain.Master.CostCentreEntities.ShipToAddress>(addresses.AsQueryable(),20,20,addresses.Count);
              PagedList.ToList().ForEach(n=>ShippingAddresses.Add(MapShippingAddress(n)));
          }
          else
          {
              addresses.ForEach(n=>ShippingAddresses.Add(MapShippingAddress(n)));
              
          }
      }
 }