/// <summary> /// Gets the redirect mathing the specified <paramref name="url"/> and <paramref name="queryString"/>. /// </summary> /// <param name="rootNodeId">THe ID of the root/side node. Use <c>0</c> for a global redirect.</param> /// <param name="url">The URL of the redirect.</param> /// <param name="queryString">The query string of the redirect.</param> /// <returns>An instance of <see cref="RedirectItem"/>, or <c>null</c> if not found.</returns> public RedirectItem GetRedirectByUrl(int rootNodeId, string url, string queryString) { // Some input validation if (String.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException(nameof(url)); } url = url.TrimEnd('/').Trim(); queryString = (queryString ?? "").Trim(); // Just return "null" if the table doesn't exist (since there aren't any redirects anyway) if (!SchemaHelper.TableExist(RedirectItemRow.TableName)) { return(null); } // Generate the SQL for the query Sql sql = new Sql().Select("*").From(RedirectItemRow.TableName).Where <RedirectItemRow>(x => x.RootNodeId == rootNodeId && !x.IsRegex && x.Url == url && x.QueryString == queryString); // Make the call to the database RedirectItemRow row = Database.FirstOrDefault <RedirectItemRow>(sql); if (row == null) { // no redirect found, try with forwardQueryString = true, and no querystring sql = new Sql().Select("*").From(RedirectItemRow.TableName).Where <RedirectItemRow>(x => x.RootNodeId == rootNodeId && x.Url == url && x.ForwardQueryString); // Make the call to the database row = Database.FirstOrDefault <RedirectItemRow>(sql); } // Wrap the database row return(row == null ? null : new RedirectItem(row)); }
public RedirectItem() { Row = new RedirectItemRow(); _created = EssentialsDateTime.Now; _updated = EssentialsDateTime.Now; Row.UniqueId = Guid.NewGuid().ToString(); }
internal RedirectItem(RedirectItemRow row) { _created = EssentialsDateTime.FromUnixTimestamp(row.Created); _updated = EssentialsDateTime.FromUnixTimestamp(row.Updated); _linkMode = EnumUtils.ParseEnum(row.LinkMode, RedirectLinkMode.Content); Row = row; }
/// <summary> /// Gets the redirect mathing the specified unique <paramref name="redirectId"/>. /// </summary> /// <param name="redirectId">The unique ID of the redirect.</param> /// <returns>An instance of <see cref="RedirectItem"/>, or <c>null</c> if not found.</returns> public RedirectItem GetRedirectById(string redirectId) { // Validate the input if (String.IsNullOrWhiteSpace(redirectId)) { throw new ArgumentNullException(nameof(redirectId)); } // Just return "null" if the table doesn't exist (since there aren't any redirects anyway) if (!SchemaHelper.TableExist(RedirectItemRow.TableName)) { return(null); } // Generate the SQL for the query Sql sql = new Sql().Select("*").From(RedirectItemRow.TableName).Where <RedirectItemRow>(x => x.UniqueId == redirectId); // Make the call to the database RedirectItemRow row = Database.FirstOrDefault <RedirectItemRow>(sql); // Wrap the database row return(row == null ? null : new RedirectItem(row)); }
internal static RedirectItem GetFromRow(RedirectItemRow row) { return(row == null ? null : new RedirectItem(row)); }