public ActionResult LeaveComment() { string[] names = null; CommentViewModel model = new CommentViewModel(); try { CommentViewModel commentModel = System.Web.HttpContext.Current.Session[Constants.CommentModel] as CommentViewModel; if (commentModel != null) { model = commentModel; System.Web.HttpContext.Current.Session[Constants.CommentModel] = null; } IBlog blog = _renderingRepository.GetPageContextItem <IBlog>(); if (blog != null) { model.parentId = blog.Id.ToString(); } if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { string fullName = Sitecore.Context.User.Profile != null ? Sitecore.Context.User.Profile.FullName : string.Empty; if (!string.IsNullOrEmpty(fullName) && !Sitecore.Context.User.IsAdministrator) { if (Sitecore.Context.User.Profile.Comment == Constants.GoogleLogin) { names = Regex.Split(fullName, @"(?<!^)(?=[A-Z])"); } else { names = fullName.Split(' '); } model.FirstName = names.Length >= 0 ? string.IsNullOrEmpty(names[0]) ? model.FirstName : names[0] : model.FirstName; model.LastName = names.Length >= 1 ? string.IsNullOrEmpty(names[1].Trim()) ? model.LastName : names[1].Trim() : model.LastName; } } if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity != null && !System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { var corePipelineManager = DependencyResolver.Current.GetService <Sitecore.Abstractions.BaseCorePipelineManager>(); var args = new GetSignInUrlInfoArgs(Sitecore.Context.Site.Name, blog.Url); GetSignInUrlInfoPipeline.Run(corePipelineManager, args); model.signinURLInfo = args?.Result; } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(ex.Message, ex, this); } return(View(Constants.LeaveCommentViewName, model)); }
public ActionResult BlogList() { BlogListViewModel model = new BlogListViewModel { Blogs = new List <BlogViewModel>() }; try { //get the featureArticleId from the current context which was set in the FeatureArticle Action call string featureArticleId = System.Web.HttpContext.Current.Items[Constants.featuredArticleID] as string; model.FeatureArticleId = featureArticleId; //Get the PageContext item to check whether it is home page,then only quotes need to show string contextItemName = _renderingRepository.GetPageContextItem <Item>()?.Name; model.IsQuotesRequired = string.IsNullOrEmpty(contextItemName) ? false : contextItemName.ToLower() == Constants.HomeItemName ? true : false; string category = HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request.QueryString[Constants.categoryQueryString]); category = string.IsNullOrEmpty(category) ? category : category.ToLower(); model.Category = category; //get the blogs from solr based on page no and page size var searchQuery = new SearchQuery { NoOfResults = model.IsQuotesRequired ? Constants.NoOfBlogsWithQuotes : Constants.NoOfBlogs, Page = Constants.IntialPageNo, Category = category, ExcludeArticles = new List <string> { featureArticleId } }; var blogList = _searchContextManager.GetBlogs(searchQuery); if (blogList != null && blogList.Any()) { model.Blogs.AddRange(blogList); } if (model.IsQuotesRequired) { GetQuote(Constants.IntialPageNo, model); } } catch (Exception ex) { Sitecore.Diagnostics.Log.Error(ex.Message, ex, this); } return(View(Constants.BlogList, model)); }