Use GetUrl methods in pages

This commit is contained in:
2017-02-15 07:18:39 +01:00
parent 69a04c04b1
commit c223951fda
3 changed files with 34 additions and 15 deletions

View File

@@ -54,28 +54,21 @@ namespace VAR.Focus.Web.Pages
Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, CurrentUser.Name); Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, CurrentUser.Name);
_idBoard = board.IDBoard; _idBoard = board.IDBoard;
Response.Redirect(string.Format("{0}?idBoard={1}", Response.Redirect(GetUrl(_idBoard));
typeof(FrmBoard).Name,
_idBoard));
} }
private void BtnView_Click(object sender, EventArgs e) private void BtnView_Click(object sender, EventArgs e)
{ {
CButton btnView = (CButton)sender; CButton btnView = (CButton)sender;
int idBoard = Convert.ToInt32(btnView.CommandArgument); int idBoard = Convert.ToInt32(btnView.CommandArgument);
Response.Redirect(string.Format("{0}?idBoard={1}", Response.Redirect(GetUrl(idBoard));
typeof(FrmBoard).Name,
idBoard));
} }
private void BtnEdit_Click(object sender, EventArgs e) private void BtnEdit_Click(object sender, EventArgs e)
{ {
CButton btnEdit = (CButton)sender; CButton btnEdit = (CButton)sender;
int idBoard = Convert.ToInt32(btnEdit.CommandArgument); int idBoard = Convert.ToInt32(btnEdit.CommandArgument);
Response.Redirect(string.Format("{0}?idBoard={1}&returnUrl={2}", Response.Redirect(FrmBoardEdit.GetUrl(idBoard, nameof(FrmBoard)));
typeof(FrmBoardEdit).Name,
idBoard,
typeof(FrmBoard).Name));
} }
private void BtnDelete_Click(object sender, EventArgs e) private void BtnDelete_Click(object sender, EventArgs e)
@@ -100,7 +93,7 @@ namespace VAR.Focus.Web.Pages
var lnkTitle = new HyperLink var lnkTitle = new HyperLink
{ {
NavigateUrl = string.Format("{0}?idBoard={1}", typeof(FrmBoard).Name, board.IDBoard), NavigateUrl = GetUrl(board.IDBoard),
}; };
var lblTitle = new CLabel var lblTitle = new CLabel
{ {
@@ -195,5 +188,18 @@ namespace VAR.Focus.Web.Pages
} }
#endregion Private methods #endregion Private methods
#region Public methods
public static string GetUrl(int idBoard, string returnUrl = null)
{
if (string.IsNullOrEmpty(returnUrl))
{
return string.Format("{0}?idBoard={1}", nameof(FrmBoard), idBoard);
}
return string.Format("{0}?idBoard={1}&returnUrl={2}", nameof(FrmBoard), idBoard, HttpUtility.UrlEncode(returnUrl));
}
#endregion Public methods
} }
} }

View File

@@ -45,7 +45,7 @@ namespace VAR.Focus.Web.Pages
} }
if (_idBoard == 0) if (_idBoard == 0)
{ {
Response.Redirect(typeof(FrmBoard).Name); Response.Redirect(nameof(FrmBoard));
} }
InitializeComponents(); InitializeComponents();
} }
@@ -68,7 +68,7 @@ namespace VAR.Focus.Web.Pages
string returnUrl = Context.GetRequestParm("returnUrl"); string returnUrl = Context.GetRequestParm("returnUrl");
if (string.IsNullOrEmpty(returnUrl)) if (string.IsNullOrEmpty(returnUrl))
{ {
Response.Redirect(string.Format("{0}?idBoard={1}", typeof(FrmBoard).Name, _idBoard)); Response.Redirect(FrmBoard.GetUrl(_idBoard));
} }
else else
{ {
@@ -114,5 +114,18 @@ namespace VAR.Focus.Web.Pages
} }
#endregion Private methods #endregion Private methods
#region Public methods
public static string GetUrl(int idBoard, string returnUrl = null)
{
if (string.IsNullOrEmpty(returnUrl))
{
return string.Format("{0}?idBoard={1}", nameof(FrmBoardEdit), idBoard);
}
return string.Format("{0}?idBoard={1}&returnUrl={2}", nameof(FrmBoardEdit), idBoard, HttpUtility.UrlEncode(returnUrl));
}
#endregion Public methods
} }
} }

View File

@@ -69,7 +69,7 @@ namespace VAR.Focus.Web.Pages
} }
if (_currentUser == null && _mustBeAutenticated) if (_currentUser == null && _mustBeAutenticated)
{ {
Response.Redirect("FrmLogin"); Response.Redirect(nameof(FrmLogin));
} }
} }
@@ -94,7 +94,7 @@ namespace VAR.Focus.Web.Pages
_currentUser = null; _currentUser = null;
if (_mustBeAutenticated) if (_mustBeAutenticated)
{ {
Response.Redirect("FrmLogin"); Response.Redirect(nameof(FrmLogin));
} }
} }