private void SaveTerritory(Core.Geo.Domain.Territory territory, IEnumerable <ZipCode> zipCodes, bool shouldStayOnPageAfterPersistence) { if (TerritoryNameTextBox.Text.Length == 0) { MessageControl1.ShowErrorMessage("A territory name is required."); return; } if (zipCodes.IsEmpty()) { MessageControl1.ShowErrorMessage("At least one valid zip code is required."); return; } if (territory != null) { territory.Description = TerritoryDescriptionTextBox.Text; territory.Name = TerritoryNameTextBox.Text; territory.ZipCodes = zipCodes.ToList(); territory.DataRecorderMetadata = new DataRecorderMetaData() { DateCreated = DateTime.Now, DateModified = DateTime.Now, DataRecorderCreator = new OrganizationRoleUser(IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole.OrganizationRoleUserId) }; try { long savedTerritoryId = _territoryRepository.SaveTerritory(territory); if (shouldStayOnPageAfterPersistence) { MessageControl1.EnqueueSuccessMessage(string.Format ("The territory '{0}' has been saved successfully. You may continue editing it below.", territory.Name)); RefreshPage(territory, savedTerritoryId); } else { Response.RedirectUser("Manage.aspx"); } } catch (PersistenceFailureException) { MessageControl1.ShowErrorMessage("The territory could not saved due to a system error. Please try again."); } } }
protected void SubmitButtonClick(object sender, EventArgs e) { IZipCodeParser zipCodeParser = new ZipCodeParser(); IEnumerable <string> selectedZipCodes = zipCodeParser.ParseStringIntoZipCodes(TerritoryZipCodesTextBox.Text).Distinct(); IEnumerable <string> availableZipCodes = zipCodeParser.ParseStringIntoZipCodes(AvailableZipCodesTextBox.Text).Distinct(); IEnumerable <string> invalidZipCodes = selectedZipCodes.Where(zc => !availableZipCodes.Contains(zc)); if (invalidZipCodes.IsEmpty()) { IEnumerable <ZipCode> zipCodesToSave = _zipCodeRepository.GetAllExistingZipCodes(selectedZipCodes.ToList()); bool shouldStayOnPageAfterPersistence = ((Button)sender).CommandArgument == "RefreshPage"; SaveTerritory(GetTerritory(), zipCodesToSave, shouldStayOnPageAfterPersistence); } else { string invalidZipCodesString = String.Join(", ", invalidZipCodes.ToArray()); string errorMessage = "The following zip code(s) need to be removed from the selection as they are out of this territory or are already in use:<br />" + invalidZipCodesString; MessageControl1.ShowErrorMessage(errorMessage); } }
private Core.Geo.Domain.Territory GetTerritory() { long territoryId; long parentTerritoryId; long.TryParse(Request.QueryString["tid"], out territoryId); long.TryParse(Request.QueryString["pid"], out parentTerritoryId); switch ((TerritoryType)(byte.Parse(TerritoryTypeDDL.SelectedValue))) { case TerritoryType.Franchisee: var franchiseeTerritory = new FranchiseeTerritory(territoryId) { FranchiseeOwnerId = long.Parse(TerritoryFranchiseeOwnerDDL.SelectedValue) }; if (parentTerritoryId != 0) { franchiseeTerritory.ParentTerritoryId = parentTerritoryId; } return(franchiseeTerritory); case TerritoryType.HospitalPartner: var hospitalPartnerOwnerIds = new List <long>(); foreach (ListItem item in TerritoryHospitalPartnerOwnersCBL.Items) { if (item.Selected) { hospitalPartnerOwnerIds.Add(long.Parse(item.Value)); } } if (!hospitalPartnerOwnerIds.IsEmpty()) { var hospitalPartnerTerritory = new HospitalPartnerTerritory(territoryId) { HospitalPartnerOwnerIds = hospitalPartnerOwnerIds }; if (parentTerritoryId != 0) { hospitalPartnerTerritory.ParentTerritoryId = parentTerritoryId; } return(hospitalPartnerTerritory); } MessageControl1.ShowErrorMessage("At least one hospital partner must be selected."); break; case TerritoryType.ReadingPhysician: var readingPhysicianTerritory = new ReadingPhysicianTerritory(territoryId); if (parentTerritoryId != 0) { readingPhysicianTerritory.ParentTerritoryId = parentTerritoryId; } return(readingPhysicianTerritory); case TerritoryType.Advertiser: var advertiserTerritory = new AdvertiserTerritory(territoryId); if (parentTerritoryId != 0) { advertiserTerritory.ParentTerritoryId = parentTerritoryId; } return(advertiserTerritory); case TerritoryType.Pod: var podTerritory = new PodTerritory(territoryId); if (parentTerritoryId != 0) { podTerritory.ParentTerritoryId = parentTerritoryId; } var packageIds = (from ListItem item in TerritoryPackageCBL.Items where item.Selected select Convert.ToInt64(item.Value)).ToList(); podTerritory.PackageIds = packageIds; return(podTerritory); } return(null); }