示例#1
0
        public async Task <IActionResult> AddBranch(BranchesListViewModel model)
        {
            try
            {
                await _siteService.AddBranchAsync(model.Branch);

                ShowAlertSuccess($"Added Branch '{model.Branch.Name}'");
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to add Branch: ", gex);
            }
            return(RedirectToAction("Branches", new { search = model.Search }));
        }
示例#2
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 }));
        }