public IHttpActionResult CreateRedirect(RedirectInstruction instruction) { var redirectUrlService = Services.RedirectUrlService; var domainService = Services.DomainService; var contentService = Services.ContentService; if (!String.IsNullOrEmpty(instruction.ContentUdi)) { instruction.ContentKey = GuidUdi.TryParse(instruction.ContentUdi, out var guidIdi) ? guidIdi.Guid : default(Guid); } try { var rootNodeId = GetRootNodeId(instruction, domainService, contentService); instruction.RedirectFromUrl = string.IsNullOrWhiteSpace(rootNodeId) ? instruction.RedirectFromUrl : rootNodeId + instruction.RedirectFromUrl; redirectUrlService.Register(instruction.RedirectFromUrl, instruction.ContentKey); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionInformation GetActionInformation(RedirectInstruction instruction) { if (!_mappingEnumToActionInformations.ContainsKey(instruction.Action)) { return(null); } var actionInformation = _mappingEnumToActionInformations[instruction.Action]; var dic = GetRouteValueDictionary(instruction); actionInformation.RouteValueDictionary = dic; return(actionInformation); }
public RouteValueDictionary GetRouteValueDictionary(RedirectInstruction instruction) { var result = new RouteValueDictionary(); if (instruction.Parameters != null && instruction.Parameters.Any()) { foreach (var parameter in instruction.Parameters) { result.Add(parameter.Name, parameter.Value); } } return(result); }
public ActionInformation GetActionInformation(RedirectInstruction instruction, ICollection <string> amrLst = null) { ActionInformation actionInformation = null; if (instruction.Action == IdentityServerEndPoints.AuthenticateIndex) { actionInformation = new ActionInformation("Authenticate", "OpenId", amrLst.Last()); } else { actionInformation = _mappingEnumToActionInformations[instruction.Action]; } var dic = GetRouteValueDictionary(instruction); actionInformation.RouteValueDictionary = dic; return(actionInformation); }
private string GetRootNodeId(RedirectInstruction instruction, IDomainService domainService, IContentService contentService) { var rootNodeId = string.Empty; var domains = domainService.GetAll(true).Where(x => x.RootContentId.HasValue).ToList(); if (domains.Any()) { var content = contentService.GetById(instruction.ContentKey); if (content == null) { throw new Exception("Content item does not exist"); } var pathNodeIds = content.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (pathNodeIds.Any()) { var assignedDomain = domains.FirstOrDefault(x => pathNodeIds.Contains(x.RootContentId?.ToString())); rootNodeId = assignedDomain?.RootContentId?.ToString() ?? string.Empty; } } return(rootNodeId); }