void Map(IEnumerable<MasterImportEntity> items)
 {
     if (!items.Any()) return;
     if(!Positions.Any())
     using (var c = NestedContainer)
     {
         Positions = Using<IMapEntityColumnPosition>(c).GetEntityMapping(new ImportEntity() { EntityName = "commoditysupplier" });
     }
     if (!Positions.Any())
     {
         GotoHomePage();
         return;
     }
     
     var paged = items.Select((row, index) => new CommoditySupplierImportVM()
                                                        {
                                                            Code =GetColumn(row,GetIndex("code")),
                                                            Name =GetColumn(row,GetIndex("name")),
                                                            Description =GetColumn(row,GetIndex("description")),
                                                            AccountNo =GetColumn(row,GetIndex("AccountNo")),
                                                            PinNo =GetColumn(row,GetIndex("PinNo")),
                                                            JoinDate =DateTime.Parse(GetColumn(row, GetIndex("JoinDate"),handleDateTime:true)),
                                                            BankBranchName =GetColumn(row,GetIndex("BankBranchName")),
                                                            BankName =GetColumn(row,GetIndex("BankName")),
                                                            CommoditySupplierType =Int32.Parse(GetColumn(row, GetIndex("CommoditySupplierType"),handleEnum:true)),
                                                            IsChecked = false,
                                                            SequenceNo = index + 1
                                                        }).AsQueryable();
     PagedList = new PagenatedList<ImportItemVM>(paged, CurrentPage, ItemsPerPage, paged.Count());
     CommoditySupplierImportVMList.Clear();
     PagedList.ToList().ForEach(n => CommoditySupplierImportVMList.Add((CommoditySupplierImportVM)n));
 }
        protected override void Load(bool isFirstLoad = false)
        {
            LoadMemberFarmers();
            AddFarmerEnabler();

            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                        if (isFirstLoad)
                            Setup();
                        using (var c = NestedContainer)
                        {
                            var query = new QueryCommodityOwner();
                            query.SupplierId = SupplierId;
                            query.Take = ItemsPerPage;
                            query.Skip = ItemsPerPage * (CurrentPage - 1);
                            query.ShowInactive = ShowInactive;
                            if (!string.IsNullOrWhiteSpace(SearchText))
                                query.Name = SearchText;

                            var rawList = Using<ICommodityOwnerRepository>(c).Query(query);
                            _pagedCommodityOwners = new PagenatedList<CommodityOwner>(rawList.Data.OfType<CommodityOwner>().AsQueryable(),
                                                                                      CurrentPage,
                                                                                      ItemsPerPage,
                                                                                      rawList.Count, true);

                            ListOfCommodityOwners.Clear();
                            int rownumber = 0;
                            _pagedCommodityOwners.ToList().ForEach(n =>
                                                                   ListOfCommodityOwners.Add(new VmCommodityOwner
                                                                   {
                                                                       Id = n.Id,
                                                                       Code = n.Code,
                                                                       Surname = n.Surname,
                                                                       FirstName = n.FirstName,
                                                                       LastName = n.LastName,
                                                                       IdNo = n.IdNo,
                                                                       Email = n.Email,
                                                                       PhoneNumber = n.PhoneNumber,
                                                                       BusinessNumber = n.BusinessNumber,
                                                                       CommodityOwnerType = n.CommodityOwnerType,
                                                                       Status = n._Status,
                                                                       Action=n._Status==EntityStatus.Active?"Deactivate":"Activate",
                                                                       RowNumber = ++rownumber
                                                                   }));
                            UpdatePagenationControl();
                        }
                    }));
        }
        private async void LoadImportsFromFile()
        {
            if (FileUtility.ValidateFile(SelectedPath))
            {
                using (var c = NestedContainer)
                {

                    try
                    {
                        ImportVmList.Clear();
                        ImportItems = await Using<IOutletImportService>(c).Import(SelectedPath);

                        var productImports = ImportItems as List<OutletImport> ?? ImportItems.ToList();
                        if (productImports.Any())
                        {
                            var items = productImports.Select((n, i) => new OutletImportVm()
                            {
                                SequenceNo = i + 1,
                                Code = n.OutletCode,
                                Name = n.Name,
                                PinNo = n.PinNo,
                                PostalAddress = n.PostalAddress,
                                PhysicalAddress = n.PhysicalAddress,
                                Status = n.Status,
                                Tax = n.Tax,
                                Currency =n.Currency,
                                SalesmanCode = n.SalesmanCode,
                                RouteName = n.RouteName,
                                IsChecked = false
                            }).AsQueryable();

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


                            PagedList.ToList().ForEach(n => ImportVmList.Add((OutletImportVm)n));
                            UpdatePagenationControl();

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

                    }
                }
            }

        }
        protected override void Load(bool isFirstLoad = false)
        {
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                       
                        using (var c = NestedContainer)
                        {
                            var query = new QuerySupplierContact
                                {
                                    SupplierId = SupplierId,
                                    Take = ItemsPerPage,
                                    Skip = ItemsPerPage*(CurrentPage - 1),
                                    ShowInactive = ShowInactive
                                };
                            if (!string.IsNullOrWhiteSpace(SearchText))
                                query.Name = SearchText;

                            var rawList = Using<IContactRepository>(c).Query(query);
                            _pagedContacts = new PagenatedList<Contact>(rawList.Data.OfType<Contact>().AsQueryable(),
                                                                                      CurrentPage,
                                                                                      ItemsPerPage,
                                                                                      rawList.Count, true);

                            ContactList.Clear();
                            int rownumber = 0;
                            _pagedContacts.ToList().ForEach(n =>
                                                                   ContactList.Add(new VmContact
                                                                   {
                                                                       Id = n.Id,
                                                                       FirstName = n.Firstname,
                                                                       LastName = n.Lastname,
                                                                       Email = n.Email,
                                                                       MobilePhone=n.MobilePhone,
                                                                       PhysicalAddress=n.PhysicalAddress,
                                                                       PostalAddress=n.PostalAddress,
                                                                       Status=n._Status,
                                                                       Action=n._Status==EntityStatus.Active?"Deactivate":"Activate",
                                                                       RowNumber = ++rownumber
                                                                   }));

                            UpdatePagenationControl();
                        }
                    }));
        }
        protected override void Load(bool isFirstLoad = false)
        {
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                        //if (isFirstLoad)

                            using (var c = NestedContainer)
                            {
                                var query = new QueryServiceProvider();
                                query.Take = ItemsPerPage;
                                query.Skip = ItemsPerPage * (CurrentPage - 1);
                                query.ShowInactive = ShowInactive;
                                if (!string.IsNullOrWhiteSpace(SearchText))
                                    query.Name = SearchText;

                                var rawList = Using<IServiceProviderRepository>(c).Query(query);
                                _pagedServiceProvider = new PagenatedList<ServiceProvider>(rawList.Data.OfType<ServiceProvider>().AsQueryable(),
                                                                                          CurrentPage,
                                                                                          ItemsPerPage,
                                                                                          rawList.Count, true);

                                ListOfServiceProviders.Clear();
                                int rownumber = 0;
                                _pagedServiceProvider.ToList().ForEach(n =>
                                                                       ListOfServiceProviders.Add(new VmServiceProvider
                                                                       {
                                                                           Id = n.Id,
                                                                           Code = n.Code,
                                                                           Name = n.Name,
                                                                           IdNo=n.IdNo,
                                                                           PinNo=n.PinNo,
                                                                           MobileNumber=n.MobileNumber,
                                                                           AccountName=n.AccountName,
                                                                           AccountNumber=n.AccountNumber,
                                                                           BankName=n.Bank!=null?n.Bank.Name:"",
                                                                           BankBranchName=n.BankBranch!=null?n.BankBranch.Name:"",
                                                                           Status = n._Status,
                                                                           Action = n._Status == EntityStatus.Active ? "Deactivate" : "Activate",
                                                                           RowNumber = ++rownumber
                                                                       }));
                                UpdatePagenationControl();
                            }
                    }));
        }
        private async void LoadProductImportFromImportFile()
        {
            if (FileUtility.ValidateFile(SelectedPath))
            {
                using (var c = NestedContainer)
                {

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

                        var productImports = ImportItems as List<ProductImport> ?? ImportItems.ToList();
                        if (productImports.Any())
                        {
                            var items = productImports.Select((n, i) => new ProductImportVM()
                                                                            {
                                                                                SequenceNo = i + 1,
                                                                                BrandCode = n.BrandCode,
                                                                                Code = n.ProductCode,
                                                                                Description = n.Description,
                                                                                Status = n.Status,
                                                                                SellingPrice = n.SellingPrice,
                                                                                ExFactoryPrice = n.ExFactoryPrice,
                                                                                IsChecked = false
                                                                            }).AsQueryable();

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


                            PagedList.ToList().ForEach(n => ImportVmList.Add((ProductImportVM) n));
                            UpdatePagenationControl();

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

                    }
                }
            }

        }
        protected override void Load(bool isFirstLoad = false)
        {
            

            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                        if (isFirstLoad)
                            Setup();
                        using (var c = NestedContainer)
                        {
                            var query = new QuerySeason();
                            query.Take = ItemsPerPage;
                            query.Skip = ItemsPerPage * (CurrentPage - 1);
                            query.ShowInactive = ShowInactive;
                            if (!string.IsNullOrWhiteSpace(SearchText))
                                query.Name = SearchText;

                            var rawList = Using<ISeasonRepository>(c).Query(query);
                            _pagedSeasons = new PagenatedList<Season>(rawList.Data.OfType<Season>().AsQueryable(),
                                                                                      CurrentPage,
                                                                                      ItemsPerPage,
                                                                                      rawList.Count, true);

                            ListOfSeasons.Clear();
                            int rownumber = 0;
                            _pagedSeasons.ToList().ForEach(n =>
                                                                   ListOfSeasons.Add(new VmSeason
                                                                   {
                                                                       Id = n.Id,
                                                                       Code = n.Code,
                                                                       Name=n.Name,
                                                                       StartDate=n.StartDate.Date,
                                                                       EndDate=n.EndDate.Date,
                                                                       Status = n._Status,
                                                                       Action=n._Status == EntityStatus.Active? "Deactivate":"Activate",
                                                                       RowNumber = ++rownumber
                                                                   }));
                            UpdatePagenationControl();
                        }
                    }));
        }
        private async void LoadImportFromFile()
        {
            if (FileUtility.ValidateFile(SelectedPath))
            {
                using (var c = NestedContainer)
                {

                    try
                    {
                        ImportVmList.Clear();
                        ImportItems = await Using<IShipToAddressImportService>(c).Import(SelectedPath);

                        var productImports = ImportItems as List<ShipToAddressImport> ?? ImportItems.ToList();
                        if (productImports.Any())
                        {
                            var items = productImports.Select((n, i) => new ShipToAddressImportVM()
                            {
                                SequenceNo = i + 1,
                                OutletCode=n.OutletCode,
                                OutletName=n.OutletName,
                                PostalAddress=n.PostalAddress,
                                ShipToCode=n.ShipToCode,
                                ShipToName=n.ShipToName,
                                IsChecked = false
                            }).AsQueryable();

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


                            PagedList.ToList().ForEach(n => ImportVmList.Add((ShipToAddressImportVM)n));
                            UpdatePagenationControl();

                        }
                    }catch(Exception ex)
                    {
                        MessageBox.Show("Error getting data from file\nDetails=>" + ex.Message);
                        FileUtility.LogError(ex.Message);
                    }
                }
            }
        }
 private void Map(IEnumerable<MasterImportEntity> importItems)
 {
     if (!importItems.Any()) return;
     if (!Positions.Any())
     using (var c = NestedContainer)
     {
         Positions = Using<IMapEntityColumnPosition>(c).GetEntityMapping(new ImportEntity(){EntityName = "Commodity"});
     }
    var paged= importItems.Select((row, index) => new CommodityImportVM()
                                            {
                                                Code = GetColumn(row, GetIndex("code")),
                                                Name = GetColumn(row, GetIndex("name")),
                                                Description = GetColumn(row, GetIndex("description")),
                                                CommodityTypeCode =GetColumn(row, GetIndex("commoditytypecode")),
                                                IsChecked = false,
                                                SequenceNo = index + 1
                                            }).AsQueryable();
    PagedList = new PagenatedList<ImportItemVM>(paged, CurrentPage, ItemsPerPage, paged.Count());
     CommodityImportVmList.Clear();
     PagedList.ToList().ForEach(n => CommodityImportVmList.Add((CommodityImportVM)n));
 }
        private void Map(IEnumerable<MasterImportEntity> importItems)
        {
            if (!importItems.Any()) return;
            if(!Positions.Any())
            using (var c = NestedContainer)
            {
                Positions = Using<IMapEntityColumnPosition>(c).GetEntityMapping(new ImportEntity() { EntityName = "commodityowner" });
            }
            if (!Positions.Any())
            {
                GotoHomePage();
                return;
            }
            PagedListAll.Clear();
            
           var paged= importItems.Select((row, index) => new CommodityOwnerImportVM()
                                                         {
                                                             Code = GetColumn(row, GetIndex("code")),
                                                             Name = GetColumn(row, GetIndex("name")),
                                                             Description = GetColumn(row, GetIndex("description")),
                                                             FirstName = GetColumn(row,GetIndex("FirstName")),
                                                             LastName = GetColumn(row,GetIndex("lastname")),
                                                             BusinessNumber =GetColumn(row,GetIndex("businessnumber")),
                                                             OfficeNumber =GetColumn(row,GetIndex("OfficeNumber")),
                                                             Email =GetColumn(row,GetIndex("Email")),
                                                             FaxNumber =GetColumn(row,GetIndex("FaxNumber")),
                                                             IdNo =GetColumn(row,GetIndex("IdNo")),
                                                             PinNo = GetColumn(row, GetIndex("PinNo")),
                                                             PhoneNumber =GetColumn(row,GetIndex("PhoneNumber")),
                                                             CommodityOwnerTypeName =GetColumn(row,GetIndex("CommodityOwnerTypeName")),
                                                             PostalAddress =GetColumn(row,GetIndex("PostalAddress")),
                                                             Surname =GetColumn(row,GetIndex("Surname")),
                                                             CommoditySupplierName =GetColumn(row,GetIndex("CommoditySupplierName")),
                                                             GenderEnum =GetColumn(row,GetIndex("GenderEnum"),handleEnum:true),
                                                             DateOfBirth =GetColumn(row,GetIndex("DateOfBirth"),handleDateTime:true),
                                                             IsChecked = false,
                                                             SequenceNo = index + 1
                                                         }).AsQueryable();

           PagedListAll.AddRange(paged.ToList());

            PagedList = new PagenatedList<ImportItemVM>(paged, CurrentPage, ItemsPerPage, paged.Count());
            CommodityOwnerImportVmList.Clear();
            PagedList.ToList().ForEach(n => CommodityOwnerImportVmList.Add((CommodityOwnerImportVM)n));
            UpdatePagenationControl();
        }
        private void FilterFarmersInfo(string s)
        {
            FarmersList.Clear();
             using (StructureMap.IContainer c = NestedContainer)
             {
                 s = s.ToLower();
                 var farmers =
                     Using<ICommodityOwnerRepository>(c).GetAll().Where(
                         p =>p.FullName.ToLower().Contains(s) ||p.IdNo.ToLower().Contains(s)||p.PinNo.Contains(s)||p.Code.ToLower().Contains(s)).ToList();

                 _pagedCommodityOwners = new PagenatedList<CommodityOwner>(farmers.AsQueryable(),
                                                                         CurrentPage,
                                                                         ItemsPerPage,
                                                                         farmers.Count());

                 FarmersList.Clear();
                 _pagedCommodityOwners.ToList().ForEach(n => FarmersList.Add(n));
                 UpdatePagenationControl();
             }

        }
        protected override void Load(bool isFirstLoad = false)
        {
            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    delegate
                    {
                        if (isFirstLoad)
                            LoadMemberFarms();
                        using (var c = NestedContainer)
                        {
                            var query = new QueryCommodityProducer();
                            query.Take = ItemsPerPage;
                            query.Skip = ItemsPerPage*(CurrentPage - 1);
                            query.SupplierId = SupplierId;
                            query.ShowInactive = ShowInactive;

                            if (!string.IsNullOrWhiteSpace(SearchText))
                                query.Name = SearchText;
                            var rawList = Using<ICommodityProducerRepository>(c).Query(query);

                            _pagedCommodityProducers = new PagenatedList<CommodityProducer>(rawList.Data.OfType<CommodityProducer>().AsQueryable(),
                                                                                      CurrentPage,
                                                                                      ItemsPerPage,
                                                                                      rawList.Count,true);
                            ListOfCommodityProducers.Clear();
                            int rownumber = 0;
                            _pagedCommodityProducers.ToList().ForEach(n =>
                                                                   ListOfCommodityProducers.Add(new VmCommodityProducer
                                                                   {
                                                                       Id = n.Id,
                                                                       Code = n.Code,
                                                                       Acrage = n.Acrage,
                                                                       Name = n.Name,
                                                                       RegNo = n.RegNo,
                                                                       PhysicalAddress = n.PhysicalAddress,
                                                                       Description = n.Description,
                                                                       Status=n._Status,
                                                                       Action=n._Status==EntityStatus.Active?"Deactivate":"Activate",
                                                                       RowNumber = ++rownumber
                                                                   }));
                            UpdatePagenationControl();
                        }
                    }));
        }