Some fixing based on code review
This commit is contained in:
@@ -185,7 +185,7 @@ JOIN umbracoNode ON umbracoRedirectUrl.contentKey=umbracoNode.uniqueID");
|
||||
public IEnumerable<IRedirectUrl> GetAllUrls(int rootContentId, long pageIndex, int pageSize, out long total)
|
||||
{
|
||||
var sql = GetBaseQuery(false)
|
||||
.Where("[umbracoNode].[path] LIKE @path", new { path = "%," + rootContentId + ",%" })
|
||||
.Where(string.Format("{0}.{1} LIKE @path", SqlSyntax.GetQuotedTableName("umbracoNode"), SqlSyntax.GetQuotedColumnName("path")), new { path = "%," + rootContentId + ",%" })
|
||||
.OrderByDescending<RedirectUrlDto>(x => x.CreateDateUtc, SqlSyntax);
|
||||
var result = Database.Page<RedirectUrlDto>(pageIndex + 1, pageSize, sql);
|
||||
total = Convert.ToInt32(result.TotalItems);
|
||||
@@ -197,7 +197,7 @@ JOIN umbracoNode ON umbracoRedirectUrl.contentKey=umbracoNode.uniqueID");
|
||||
public IEnumerable<IRedirectUrl> SearchUrls(string searchTerm, long pageIndex, int pageSize, out long total)
|
||||
{
|
||||
var sql = GetBaseQuery(false)
|
||||
.Where("[umbracoRedirectUrl].[Url] LIKE @url", new { url = "%" + searchTerm.Trim().ToLowerInvariant() + "%" })
|
||||
.Where(string.Format("{0}.{1} LIKE @url", SqlSyntax.GetQuotedTableName("umbracoRedirectUrl"), SqlSyntax.GetQuotedColumnName("Url")), new { url = "%" + searchTerm.Trim().ToLowerInvariant() + "%" })
|
||||
.OrderByDescending<RedirectUrlDto>(x => x.CreateDateUtc, SqlSyntax);
|
||||
var result = Database.Page<RedirectUrlDto>(pageIndex + 1, pageSize, sql);
|
||||
total = Convert.ToInt32(result.TotalItems);
|
||||
|
||||
@@ -75,7 +75,6 @@ namespace Umbraco.Core.Services
|
||||
using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow))
|
||||
{
|
||||
var rule = repo.GetMostRecentUrl(url);
|
||||
uow.Commit();
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +85,6 @@ namespace Umbraco.Core.Services
|
||||
using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow))
|
||||
{
|
||||
var rules = repo.GetContentUrls(contentKey);
|
||||
uow.Commit();
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +95,6 @@ namespace Umbraco.Core.Services
|
||||
using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow))
|
||||
{
|
||||
var rules = repo.GetAllUrls(pageIndex, pageSize, out total);
|
||||
uow.Commit();
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +105,6 @@ namespace Umbraco.Core.Services
|
||||
using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow))
|
||||
{
|
||||
var rules = repo.GetAllUrls(rootContentId, pageIndex, pageSize, out total);
|
||||
uow.Commit();
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
@@ -118,7 +114,6 @@ namespace Umbraco.Core.Services
|
||||
using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow))
|
||||
{
|
||||
var rules = repo.SearchUrls(searchTerm, pageIndex, pageSize, out total);
|
||||
uow.Commit();
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace Umbraco.Web.Redirects
|
||||
searchResult.SearchResults = redirects;
|
||||
searchResult.TotalCount = resultCount;
|
||||
searchResult.CurrentPage = page;
|
||||
//hmm how many results 'could there be ?
|
||||
searchResult.PageCount = ((int)resultCount + pageSize - 1) / pageSize;
|
||||
|
||||
searchResult.HasSearchResults = resultCount > 0;
|
||||
@@ -40,52 +39,42 @@ namespace Umbraco.Web.Redirects
|
||||
{
|
||||
var publishedUrl = "#";
|
||||
if (id > 0)
|
||||
{
|
||||
publishedUrl = Umbraco.Url(id);
|
||||
}
|
||||
|
||||
return new HttpResponseMessage { Content = new StringContent(publishedUrl, Encoding.UTF8, "text/html") };
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage DeleteRedirectUrl(int id)
|
||||
public IHttpActionResult DeleteRedirectUrl(int id)
|
||||
{
|
||||
|
||||
var redirectUrlService = Services.RedirectUrlService;
|
||||
// has the redirect already been deleted ?
|
||||
//var redirectUrl = redirectUrlService.GetById(redirectUrl.Id);
|
||||
//if (redirectUrl== null)
|
||||
//{
|
||||
// return new HttpResponseMessage(System.Net.HttpStatusCode.NotFound);
|
||||
//}
|
||||
redirectUrlService.Delete(id);
|
||||
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public HttpResponseMessage ToggleUrlTracker(bool disable)
|
||||
public IHttpActionResult ToggleUrlTracker(bool disable)
|
||||
{
|
||||
var configFilePath = HttpContext.Current.Server.MapPath("~/config/umbracoSettings.config");
|
||||
|
||||
if (File.Exists(configFilePath))
|
||||
{
|
||||
var umbracoConfig = new XmlDocument { PreserveWhitespace = true };
|
||||
umbracoConfig.Load(configFilePath);
|
||||
var action = disable ? "disable" : "enable";
|
||||
|
||||
var webRoutingElement = umbracoConfig.SelectSingleNode("//web.routing") as XmlElement;
|
||||
if (webRoutingElement != null)
|
||||
{
|
||||
// note: this adds the attribute if it does not exist
|
||||
webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant());
|
||||
umbracoConfig.Save(configFilePath);
|
||||
}
|
||||
if (File.Exists(configFilePath) == false)
|
||||
return BadRequest(string.Format("Couldn't {0} URL Tracker, the umbracoSettings.config file does not exist.", action));
|
||||
|
||||
var umbracoConfig = new XmlDocument { PreserveWhitespace = true };
|
||||
umbracoConfig.Load(configFilePath);
|
||||
|
||||
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
|
||||
}
|
||||
var webRoutingElement = umbracoConfig.SelectSingleNode("//web.routing") as XmlElement;
|
||||
if (webRoutingElement == null)
|
||||
return BadRequest(string.Format("Couldn't {0} URL Tracker, the web.routing element was not found in umbracoSettings.config.", action));
|
||||
|
||||
return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
|
||||
// note: this adds the attribute if it does not exist
|
||||
webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant());
|
||||
umbracoConfig.Save(configFilePath);
|
||||
|
||||
return Ok(string.Format("URL tracker is now {0}d", action));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user