コード例 #1
0
        public async Task <IActionResult> Branches(string search, int page = 1)
        {
            var filter = new BaseFilter(page)
            {
                Search = search
            };

            var branchList = await _siteService.GetPaginatedBranchListAsync(filter);

            PaginateViewModel paginateModel = new PaginateViewModel()
            {
                ItemCount    = branchList.Count,
                CurrentPage  = page,
                ItemsPerPage = filter.Take.Value
            };

            if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            BranchesListViewModel viewModel = new BranchesListViewModel()
            {
                Branches      = branchList.Data.ToList(),
                PaginateModel = paginateModel,
                SystemList    = new SelectList(await _siteService.GetSystemList(), "Id", "Name")
            };

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <BranchesListViewModel> GetBankBranches(GetBankBranchesQuery request, CancellationToken cancellationToken)
        {
            var filteredBranches = _context.Branches
                                   .Where(x => x.BankId == request.BankId);

            var branchCounters = _context.Counters
                                 .Where(x => x.Branch.BankId == request.BankId);

            var counterServices = _context.CounterServices;

            var services = _context.Services;

            var queryResult = (from branch in filteredBranches
                               join branchCounter in branchCounters on branch.BranchId equals branchCounter.BranchId
                               join counterService in counterServices on branchCounter.CounterId equals counterService.CounterId
                               join service in services on counterService.ServiceId equals service.ServiceId
                               select new BankBranchesDto
            {
                BankId = branch.BankId,
                BranchId = branch.BranchId,
                Address = branch.Address,
                Phone = branch.Phone,
                ServiceId = service.ServiceId,
                ServiceName = service.ServiceName
            }).Distinct()
                              .AsNoTracking();

            var result = await BranchesListViewModel.Create(queryResult, cancellationToken);

            return(result);
        }
コード例 #3
0
 public BranchesPage(Users user)
 {
     InitializeComponent();
     this.curr_user = user;
     branchesList   = new BranchesListViewModel(curr_user)
     {
         Navigation = this.Navigation
     };
     this.BindingContext = branchesList;
 }
コード例 #4
0
        public async Task <IActionResult> EditBranch(BranchesListViewModel model)
        {
            try
            {
                await _siteService.UpdateBranchAsync(model.Branch);

                ShowAlertSuccess($"Branch  '{model.Branch.Name}' updated");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to edit Branch: ", gex);
            }
            return(RedirectToAction("Branches", new { search = model.Search }));
        }
コード例 #5
0
        public async Task <IActionResult> EditBranch(BranchesListViewModel model)
        {
            if (model != null)
            {
                try
                {
                    if (await _siteLookupService.IsSiteSettingSetAsync(GetCurrentSiteId(),
                                                                       SiteSettingKey.Events.GoogleMapsAPIKey))
                    {
                        model.Branch.Geolocation = null;
                        var newAddress    = model.Branch.Address?.Trim();
                        var currentBranch = await _siteService.GetBranchByIdAsync(model.Branch.Id);

                        if (string.IsNullOrWhiteSpace(currentBranch.Geolocation) ||
                            !string.Equals(currentBranch.Address, newAddress,
                                           StringComparison.OrdinalIgnoreCase))
                        {
                            var result = await _spatialService
                                         .GetGeocodedAddressAsync(newAddress);

                            if (result.Status == ServiceResultStatus.Success)
                            {
                                model.Branch.Geolocation = result.Data;
                            }
                            else if (result.Status == ServiceResultStatus.Warning)
                            {
                                ShowAlertWarning("Unable to set branch geolocation: ",
                                                 result.Message);
                            }
                            else
                            {
                                ShowAlertDanger("Unable to set branch geolocation: ",
                                                result.Message);
                            }
                        }
                    }

                    await _siteService.UpdateBranchAsync(model.Branch);

                    ShowAlertSuccess($"Branch  '{model.Branch.Name}' updated");
                }
                catch (GraException gex)
                {
                    ShowAlertDanger("Unable to edit Branch: ", gex);
                }
            }
            return(RedirectToAction("Branches", new { search = model?.Search }));
        }
コード例 #6
0
        public async Task <IActionResult> Branches(string search, int page = 1)
        {
            var filter = new BaseFilter(page)
            {
                Search = search
            };

            var branchList = await _siteService.GetPaginatedBranchListAsync(filter);

            var paginateModel = new PaginateViewModel
            {
                ItemCount    = branchList.Count,
                CurrentPage  = page,
                ItemsPerPage = filter.Take.Value
            };

            if (paginateModel.PastMaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            var viewModel = new BranchesListViewModel
            {
                Branches        = branchList.Data.ToList(),
                PaginateModel   = paginateModel,
                ShowGeolocation = await _siteLookupService.IsSiteSettingSetAsync(GetCurrentSiteId(),
                                                                                 SiteSettingKey.Events.GoogleMapsAPIKey),
                SystemList = new SelectList(await _siteService.GetSystemList(), "Id", "Name")
            };

            var(IsSet, SetValue) = await _siteLookupService.GetSiteSettingStringAsync(
                GetCurrentSiteId(), SiteSettingKey.Events.GoogleMapsAPIKey);

            viewModel.ShowGeolocation  = IsSet;
            viewModel.GoogleMapsAPIKey = SetValue;

            return(View(viewModel));
        }
コード例 #7
0
        public async Task <IActionResult> AddBranch(BranchesListViewModel model)
        {
            if (model != null)
            {
                try
                {
                    model.Branch.Geolocation = null;
                    var branch = await _siteService.AddBranchAsync(model.Branch);

                    ShowAlertSuccess($"Added Branch '{branch.Name}'");

                    if (await _siteLookupService.IsSiteSettingSetAsync(GetCurrentSiteId(),
                                                                       SiteSettingKey.Events.GoogleMapsAPIKey))
                    {
                        var result = await _spatialService
                                     .GetGeocodedAddressAsync(branch.Address);

                        if (result.Status == ServiceResultStatus.Success)
                        {
                            branch.Geolocation = result.Data;
                            await _siteService.UpdateBranchAsync(branch);
                        }
                        else if (result.Status == ServiceResultStatus.Warning)
                        {
                            ShowAlertWarning("Unable to set branch geolocation: ", result.Message);
                        }
                        else
                        {
                            ShowAlertDanger("Unable to set branch geolocation: ", result.Message);
                        }
                    }
                }
                catch (GraException gex)
                {
                    ShowAlertDanger("Unable to add Branch: ", gex);
                }
            }
            return(RedirectToAction("Branches", new { search = model?.Search }));
        }