Example #1
0
        private void RefreshPage(Core.Geo.Domain.Territory territory, long savedTerritoryId)
        {
            var redirectUrlStringBuilder = new StringBuilder();

            redirectUrlStringBuilder.AppendFormat("Edit.aspx?tid={0}", savedTerritoryId);
            if (territory.ParentTerritoryId != null)
            {
                redirectUrlStringBuilder.AppendFormat("&ftid={0}", territory.ParentTerritoryId);
            }
            Response.RedirectUser(ResolveUrl(redirectUrlStringBuilder.ToString()));
        }
Example #2
0
 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.");
         }
     }
 }
Example #3
0
 private Core.Geo.Domain.Territory GetFranchiseeTerritory(long franchiseeTerritoryId)
 {
     try
     {
         Core.Geo.Domain.Territory franchiseeTerritory = _territoryRepository.GetTerritory(franchiseeTerritoryId);
         var allowableTerritories = new List <TerritoryType> {
             TerritoryType.Franchisee, TerritoryType.SalesRep
         };
         if (!allowableTerritories.Contains(franchiseeTerritory.TerritoryType))
         {
             Response.RedirectUser(REDIRECT_URL);
         }
         return(franchiseeTerritory);
     }
     catch (ObjectNotFoundInPersistenceException <Core.Geo.Domain.Territory> )
     {
         Response.RedirectUser(REDIRECT_URL);
     }
     return(null);
 }
Example #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (!string.IsNullOrEmpty(Request.QueryString["ftid"]))
         {
             long franchiseeTerritoryId;
             long.TryParse(Request.QueryString["ftid"], out franchiseeTerritoryId);
             Core.Geo.Domain.Territory franchiseeTerritory = GetFranchiseeTerritory(franchiseeTerritoryId);
             ParentTerritoryNameLiteral.Text = franchiseeTerritory.Name;
             List <Core.Geo.Domain.Territory> childTerritories = _territoryRepository.GetChildTerritories(franchiseeTerritory.Id);
             long territoryId = 0;
             if (!string.IsNullOrEmpty(Request.QueryString["tid"]))
             {
                 long.TryParse(Request.QueryString["tid"], out territoryId);
                 if (territoryId != 0)
                 {
                     Page.Title = "Edit Subterritory";
                     TerritoryTypeDDL.Enabled          = false;
                     WhyTypeDDLIsDisabledLabel.Visible = true;
                     TerritoryTypeDDL.Enabled          = false;
                     WhyTypeDDLIsDisabledLabel.Visible = true;
                     LoadTerritoryFields(territoryId);
                 }
             }
             List <string> childTerritoryZipCodes = childTerritories.Where(ct => ct.Id != territoryId).
                                                    Select(ct => ct.ZipCodes.Select(zc => zc.Zip)).SelectMany(zc => zc).Distinct().ToList();
             SetFranchisorMasterPageOptions();
             LoadTerritoryTypeDDL();
             LoadAvailableZipCodesTextBox(franchiseeTerritory.ZipCodes.Where(z => !childTerritoryZipCodes.Contains(z.Zip)));
         }
         else
         {
             Response.RedirectUser(REDIRECT_URL);
         }
     }
 }