public static string SetAvatar(int memberId, string service) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var member = memberShipHelper.GetById(memberId); switch (service) { case "twitter": if (string.IsNullOrWhiteSpace(member.GetPropertyValue <string>("twitter")) == false) { var twitData = Twitter.Profile(member.GetPropertyValue <string>("twitter")); if (twitData.MoveNext()) { var imgUrl = twitData.Current.SelectSingleNode("//profile_image_url").Value; return(SaveUrlAsBuddyIcon(imgUrl, member.Id)); } } break; case "gravatar": var gravatarUrl = string.Format("https://www.gravatar.com/avatar/{0}?s=48&d=monsterid", umbraco.library.md5(member.GetPropertyValue <string>("email"))); return(SaveUrlAsBuddyIcon(gravatarUrl, member.Id)); } return(string.Empty); }
private static MemberData GetMemberData() { var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); if (membershipHelper.GetCurrentLoginStatus().IsLoggedIn == false) { return(null); } var userName = membershipHelper.CurrentUserName; var memberData = ApplicationContext.Current.ApplicationCache.RuntimeCache .GetCacheItem <MemberData>("MemberData" + userName, () => { var member = membershipHelper.GetCurrentMember(); var avatarService = new AvatarService(); var memberAvatarPath = avatarService.GetMemberAvatar(member); memberAvatarPath = HostingEnvironment.MapPath($"~{memberAvatarPath}"); var avatarImage = avatarService.GetMemberAvatarImage(memberAvatarPath); var roles = member.GetRoles(); var topicService = new TopicService(ApplicationContext.Current.DatabaseContext); var latestTopics = topicService.GetLatestTopicsForMember(member.Id, maxCount: 100); var newTosAccepted = true; var tosAccepted = member.GetPropertyValue <DateTime>("tos"); var newTosDate = new DateTime(2018, 03, 26); if ((newTosDate - tosAccepted).TotalDays > 1) { newTosAccepted = false; } var avatarPath = avatarService.GetMemberAvatar(member); var avatarHtml = avatarService.GetImgWithSrcSet(avatarPath, member.Name, 100); var data = new MemberData { Member = member, AvatarImage = avatarImage, AvatarImageTooSmall = avatarImage != null && (avatarImage.Width < 400 || avatarImage.Height < 400), Roles = roles, LatestTopics = latestTopics, AvatarHtml = avatarHtml, AvatarPath = avatarPath, NumberOfForumPosts = member.ForumPosts(), Karma = member.Karma(), TwitterHandle = member.GetPropertyValue <string>("twitter").Replace("@", string.Empty), IsAdmin = member.IsAdmin(), Email = member.GetPropertyValue <string>("Email"), IsBlocked = member.GetPropertyValue <bool>("blocked"), NewTosAccepted = newTosAccepted }; return(data); }, TimeSpan.FromMinutes(5)); return(memberData); }
public static bool IsInGroup(string groupName) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var currentMember = memberShipHelper.GetCurrentMember(); return(currentMember != null && IsMemberInGroup(groupName, currentMember)); }
public JsonResult CheckProfileURLAvailable(string profileURL) { var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); //Get Current Member var member = membershipHelper.GetCurrentMember(); if (member != null) { //If the Url is the same as the one currently stored for this user, return Ok if (member.GetPropertyValue <string>("profileURL") == profileURL) { return(Json(true, JsonRequestBehavior.AllowGet)); } //Check if an exisiting member is already using this Url: //TODO-1: Maybe just exclude the current user in below search and delete the line above? var checkProfileURL = Services.MemberService.GetMembersByPropertyValue("profileUrl", profileURL).FirstOrDefault(); //If an exisiting member was found, then return negative if (checkProfileURL != null) { return(Json(String.Format("The profile URL '{0}' is already in use.", profileURL), JsonRequestBehavior.AllowGet)); } //Otherwise everything is good return(Json(true, JsonRequestBehavior.AllowGet)); } // No member found return(Json(true, JsonRequestBehavior.AllowGet)); }
public static IPublishedContent GetMember(int id) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var member = memberShipHelper.GetById(id); return(member); }
public JsonResult CheckEmailIsUsed(string emailAddress) { var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); //Get Current Member var member = membershipHelper.GetCurrentMember(); if (member != null) { //if the email is the same as the one stored then it's OK if (member.GetPropertyValue <string>("Email") == emailAddress) { return(Json(true, JsonRequestBehavior.AllowGet)); } //Try and get member by email typed in var checkEmail = Services.MemberService.GetByEmail(emailAddress); if (checkEmail != null) { return(Json(String.Format("The email address '{0}' is already in use.", emailAddress), JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); } // No member found return(Json(true, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Deletes a member and all their associated data /// @Html.ActionLink("Delete Profile", "HandleDeleteProfile", "MemberEdit") /// </summary> /// <returns></returns> public ActionResult HandleDeleteProfile() { try { // Get the current member var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var member = Services.MemberService.GetById(membershipHelper.GetCurrentMemberId()); //TODO-OPTIONAL: Notify the member that their profile is being deleted in x days, giving them a couple of days to cancel this. // -> Then delete the member with a scheduled task automatically after that period of time. // Delete the member Services.MemberService.Delete(member); } catch (Exception ex) { //TODO-1: Log the exception throw; } // Log the member out FormsAuthentication.SignOut(); // Redirect home or to a custom page return(Redirect("/")); }
public string SetServiceAsBuddyIcon(string service) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var id = memberShipHelper.GetCurrentMemberId(); return(SetAvatar(id, service)); }
public int GetCurrentUserId() { var memberService = ApplicationContext.Services.MemberService; var memberHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext); IPublishedContent member = memberHelper.GetCurrentMember(); var id = member.Id; return(id); }
public void UpdateDownloadCount(int fileId, bool ignoreCookies, bool isPackage) { var cookie = HttpContext.Current.Request.Cookies["ProjectFileDownload" + fileId]; if (cookie != null && ignoreCookies == false) { return; } var downloads = 0; var projectId = 0; var reader = Application.SqlHelper.ExecuteReader("Select downloads, nodeId from wikiFiles where id = @id;", Application.SqlHelper.CreateParameter("@id", fileId)); if (reader.Read()) { downloads = reader.GetInt("downloads"); projectId = reader.GetInt("nodeId"); } downloads = downloads + 1; Application.SqlHelper.ExecuteNonQuery( "update wikiFiles set downloads = @downloads where id = @id;", Application.SqlHelper.CreateParameter("@id", fileId), Application.SqlHelper.CreateParameter("@downloads", downloads)); var totalDownloads = Application.SqlHelper.ExecuteScalar <int>("Select SUM(downloads) from wikiFiles where nodeId = @projectId;", Application.SqlHelper.CreateParameter("@projectId", projectId)); if (isPackage) { var memberHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var memberId = memberHelper.GetCurrentMemberId(); var currentMemberId = memberId == -1 ? 0 : memberId; //update download count update Application.SqlHelper.ExecuteNonQuery( @"insert into projectDownload(projectId,memberId,timestamp) values((select nodeId from wikiFiles where id = @id) ,@memberId, getdate())", Application.SqlHelper.CreateParameter("@id", fileId), Application.SqlHelper.CreateParameter("@memberId", currentMemberId)); } var e = new FileDownloadUpdateEventArgs { ProjectId = projectId, Downloads = totalDownloads }; FireAfterDownloadUpdate(e); cookie = new HttpCookie("ProjectFileDownload" + fileId) { Expires = DateTime.Now.AddHours(1) }; HttpContext.Current.Response.Cookies.Add(cookie); }
public static bool IsModerator() { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var currentMember = memberShipHelper.GetCurrentMember(); if (currentMember.Id == 0) { return(false); } var moderatorRoles = new[] { "admin", "HQ", "Core", "MVP" }; return(moderatorRoles.Any(moderatorRole => IsMemberInGroup(moderatorRole, currentMember))); }
public Reputation(int memberId) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var member = memberShipHelper.GetById(memberId); if (member == null) { return; } Current = member.GetPropertyValue <int>(config.GetKey("/configuration/reputation/currentPointsAlias")); Total = member.GetPropertyValue <int>(config.GetKey("/configuration/reputation/totalPointsAlias")); MemberId = memberId; }
public string SaveWebCamImage(string memberGuid) { var url = HttpContext.Current.Request["AvatarUrl"]; if (string.IsNullOrEmpty(url) == false) { return("true"); } var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var member = memberShipHelper.GetCurrentMember(); if (member == null) { return("error"); } var imageBytes = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength); var file = member.Id.ToString(CultureInfo.InvariantCulture); var avatar = string.Format("/media/avatar/{0}.jpg", file); var path = HttpContext.Current.Server.MapPath(avatar); using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { ms.Write(imageBytes, 0, imageBytes.Length); var newImage = Image.FromStream(ms, true).GetThumbnailImage(64, 48, ThumbnailCallback, new IntPtr()); if (File.Exists(path)) { File.Delete(path); } newImage.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg); } var memberService = ApplicationContext.Current.Services.MemberService; var m = memberService.GetById(member.Id); m.SetValue("avatar", avatar); return(avatar); }
public ActionResult RenderEditProfile() { // Get the current member var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var currentMember = membershipHelper.GetCurrentMember(); ProfileViewModel profileModel = new ProfileViewModel(); profileModel.Name = currentMember.Name; profileModel.EmailAddress = currentMember.GetPropertyValue <string>("Email"); profileModel.MemberID = currentMember.Id; profileModel.Description = currentMember.GetPropertyValue <string>("description"); profileModel.ProfileURL = currentMember.GetPropertyValue <string>("profileURL"); profileModel.Twitter = currentMember.GetPropertyValue <string>("twitter"); profileModel.LinkedIn = currentMember.GetPropertyValue <string>("linkedIn"); profileModel.Skype = currentMember.GetPropertyValue <string>("skype"); //Pass the model to the view return(PartialView("EditProfile", profileModel)); }
//api/topic public void Delete(int id) { var c = TopicService.GetById(id); if (c == null) { throw new Exception("Topic not found"); } var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext); var currentMemberId = memberShipHelper.GetCurrentMemberId(); if (Library.Utils.IsModerator() == false && c.MemberId != currentMemberId) { throw new Exception("You cannot delete this topic"); } TopicService.Delete(c); }
public MyPageViewModel() { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var memberId = memberShipHelper.GetCurrentMemberId(); var memberService = ApplicationContext.Current.Services.MemberService; var m = memberService.GetById(memberId); Id = m.Id; Name = m.Name; Email = m.Email; Login = m.Name; var memberRoles = System.Web.Security.Roles.GetRolesForUser(m.Username); MemberGroup = string.Join(",", memberRoles.Select(item => item)); MemberType = m.ContentType.Name; //FirstName = m.GetValue<string>("firstname"); //LastName = m.GetValue<string>("lastname"); //Address = m.GetValue<string>("Address"); //ContactPerson = m.GetValue<string>("ContactPerson"); }
/// <summary> /// Update the logged in members password /// </summary> /// <param name="model"></param> /// <returns></returns> //[HttpPost] //[ValidateAntiForgeryToken] public ActionResult HandleChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(PartialView("ChangePassword", model)); } var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); // Get the current member var member = Services.MemberService.GetById(membershipHelper.GetCurrentMemberId()); //TODO-1: Validate their current password //Save the password for the member Services.MemberService.SavePassword(member, model.Password); //TODO-2: Notify the member that their password was just changed //Return the view return(PartialView("ChangePassword", model)); }
public string ChangeCollabStatus(int projectId, bool status) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var currentMember = memberShipHelper.GetCurrentMemberId(); if (currentMember <= 0) { return("false"); } var contentService = ApplicationContext.Services.ContentService; var content = contentService.GetById(projectId); if (content.GetValue <int>("owner") != currentMember) { return("false"); } content.SetValue("openForCollab", status); var result = contentService.PublishWithStatus(content); return(result.Success.ToString()); }
public string RemoveContributor(int projectId, int memberId) { var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var currentMember = memberShipHelper.GetCurrentMemberId(); if (currentMember <= 0) { return("false"); } var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); var content = umbracoHelper.Content(projectId); if (content.GetPropertyValue <int>("owner") != currentMember) { return("false"); } var projectContributor = new ProjectContributor(projectId, memberId); projectContributor.Delete(); return("true"); }
//Render Form public ActionResult RenderForm_NewPrayer(string userName) { try { //Instantiate variables var prayerRequest = new PrayerRequestModel(); var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); //Get member's ID from prayerRequest.UserId = memberShipHelper.GetByUsername(userName).Id; return(PartialView("~/Views/Partials/PrayerCorner/_newPrayer.cshtml", prayerRequest)); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine(@"PrayerController.cs : RenderForm_NewPrayer()"); sb.AppendLine("userName:"******"", "*An error occured while creating a new prayer form."); return(PartialView("~/Views/Partials/PrayerCorner/_newPrayer.cshtml")); } }
public void UpdateDownloadCount(int fileId, bool ignoreCookies, bool isPackage) { var cookie = HttpContext.Current.Request.Cookies["ProjectFileDownload" + fileId]; if (cookie != null && ignoreCookies == false) return; var downloads = 0; var projectId = 0; var reader = Application.SqlHelper.ExecuteReader("Select downloads, nodeId from wikiFiles where id = @id;", Application.SqlHelper.CreateParameter("@id", fileId)); if (reader.Read()) { downloads = reader.GetInt("downloads"); projectId = reader.GetInt("nodeId"); } downloads = downloads + 1; Application.SqlHelper.ExecuteNonQuery( "update wikiFiles set downloads = @downloads where id = @id;", Application.SqlHelper.CreateParameter("@id", fileId), Application.SqlHelper.CreateParameter("@downloads", downloads)); var totalDownloads = Application.SqlHelper.ExecuteScalar<int>("Select SUM(downloads) from wikiFiles where nodeId = @projectId;", Application.SqlHelper.CreateParameter("@projectId", projectId)); if (isPackage) { var memberHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var memberId = memberHelper.GetCurrentMemberId(); var currentMemberId = memberId == -1 ? 0 : memberId; //update download count update Application.SqlHelper.ExecuteNonQuery( @"insert into projectDownload(projectId,memberId,timestamp) values((select nodeId from wikiFiles where id = @id) ,@memberId, getdate())", Application.SqlHelper.CreateParameter("@id", fileId), Application.SqlHelper.CreateParameter("@memberId", currentMemberId)); } var e = new FileDownloadUpdateEventArgs { ProjectId = projectId, Downloads = totalDownloads }; FireAfterDownloadUpdate(e); cookie = new HttpCookie("ProjectFileDownload" + fileId) { Expires = DateTime.Now.AddHours(1) }; HttpContext.Current.Response.Cookies.Add(cookie); }
private void ObtainByPrayerCorner(Models.SearchList searchList, int pageNo) { //Instantiate variables var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); searchList.ShowPrayers = true; searchList.SearchInTitle = "The Prayer Corner"; if (!string.IsNullOrWhiteSpace(searchList.SearchFor)) { // var CmPrayerList = new ContentModels.PrayerList(Umbraco.TypedContent((int)Common.siteNode.ThePrayerCorner)); //Get all prayers BaseSearchProvider mySearcher = ExamineManager.Instance.SearchProviderCollection[Common.searchProviders.PrayersSearcher]; ISearchCriteria criteria = mySearcher.CreateSearchCriteria(BooleanOperation.Or); //Setup up search fields by importance IBooleanOperation query = criteria.Field(Common.NodeProperties.prayerTitle, searchList.SearchFor.MultipleCharacterWildcard()); query.Or().Field(Common.NodeProperties.prayer, searchList.SearchFor.MultipleCharacterWildcard()); query.Or().Field(Common.NodeProperties.prayerRequestMember, searchList.SearchFor.MultipleCharacterWildcard()); //IBooleanOperation query = criteria.Field(Common.NodeProperties.prayerTitle, searchList.SearchFor.Boost(2)); //query.Or().Field(Common.NodeProperties.prayer, searchList.SearchFor.Boost(1)); //query.Or().Field(Common.NodeProperties.prayerRequestMember, searchList.SearchFor); //Obtain result with query ISearchResults searchResults = mySearcher.Search(query.Compile()); //Get total experiences. searchList.Pagination.itemsPerPage = 10; searchList.Pagination.totalItems = searchResults.Count(); //Determine how many pages/items to skip and take, as well as the total page count for the search result. if (searchList.Pagination.totalItems > searchList.Pagination.itemsPerPage) { searchList.Pagination.totalPages = (int)Math.Ceiling((double)searchList.Pagination.totalItems / (double)searchList.Pagination.itemsPerPage); } else { searchList.Pagination.itemsPerPage = searchList.Pagination.totalItems; searchList.Pagination.totalPages = 1; } //Determine current page number if (pageNo <= 0 || pageNo > searchList.Pagination.totalPages) { pageNo = 1; } searchList.Pagination.pageNo = pageNo; //Determine how many pages/items to skip if (searchList.Pagination.totalItems > searchList.Pagination.itemsPerPage) { searchList.Pagination.itemsToSkip = searchList.Pagination.itemsPerPage * (pageNo - 1); } //Convert list of SearchResults to list of classes foreach (SearchResult sRecord in searchResults.Skip(searchList.Pagination.itemsToSkip).Take(searchList.Pagination.itemsPerPage)) { //Create new prayerLink class var prayerLink = new Models.PrayerLink(); prayerLink.Id = sRecord.Id; prayerLink.Title = sRecord.Fields[Common.NodeProperties.prayerTitle]; prayerLink.Url = Umbraco.NiceUrl(sRecord.Id); prayerLink.Date = Convert.ToDateTime(sRecord.Fields[Common.NodeProperties.requestDate]); //Determine current percentage prayerLink.currentPercentage = int.Parse(sRecord.Fields[Common.NodeProperties.currentPercentage]); prayerLink.baseCalculationDate = DateTime.Parse(sRecord.Fields[Common.NodeProperties.baseCalculationDate]); int daysSinceBaseDate = (DateTime.Now - prayerLink.baseCalculationDate).Days; if (daysSinceBaseDate > prayerLink.currentPercentage) { prayerLink.currentPercentage = 0; } else { prayerLink.currentPercentage = prayerLink.currentPercentage - daysSinceBaseDate; } //Determine proper candle based upon current percentage prayerLink.CandleUrl = CmPrayerList.CandleOut.Url; if (prayerLink.currentPercentage == 0) { prayerLink.CandleUrl = CmPrayerList.CandleOut.Url; } else if (prayerLink.currentPercentage >= 1 && prayerLink.currentPercentage <= 10) { prayerLink.CandleUrl = CmPrayerList.Candle10.Url; } else if (prayerLink.currentPercentage >= 11 && prayerLink.currentPercentage <= 20) { prayerLink.CandleUrl = CmPrayerList.Candle20.Url; } else if (prayerLink.currentPercentage >= 21 && prayerLink.currentPercentage <= 30) { prayerLink.CandleUrl = CmPrayerList.Candle30.Url; } else if (prayerLink.currentPercentage >= 31 && prayerLink.currentPercentage <= 40) { prayerLink.CandleUrl = CmPrayerList.Candle40.Url; } else if (prayerLink.currentPercentage >= 41 && prayerLink.currentPercentage <= 50) { prayerLink.CandleUrl = CmPrayerList.Candle50.Url; } else if (prayerLink.currentPercentage >= 51 && prayerLink.currentPercentage <= 60) { prayerLink.CandleUrl = CmPrayerList.Candle60.Url; } else if (prayerLink.currentPercentage >= 61 && prayerLink.currentPercentage <= 70) { prayerLink.CandleUrl = CmPrayerList.Candle70.Url; } else if (prayerLink.currentPercentage >= 71 && prayerLink.currentPercentage <= 80) { prayerLink.CandleUrl = CmPrayerList.Candle80.Url; } else if (prayerLink.currentPercentage >= 81 && prayerLink.currentPercentage <= 90) { prayerLink.CandleUrl = CmPrayerList.Candle90.Url; } else if (prayerLink.currentPercentage >= 91 && prayerLink.currentPercentage <= 100) { prayerLink.CandleUrl = CmPrayerList.Candle100.Url; } // IEnumerable <string> prayerSummary = sRecord.Fields[Common.NodeProperties.prayer].Split().Take(32); prayerLink.PrayerSummary = string.Join(" ", prayerSummary) + "..."; //Obtain member ContentModels.Member CmMember; int memberId; if (int.TryParse(sRecord.Fields[Common.NodeProperties.prayerRequestMember], out memberId)) { IPublishedContent ipMember = memberShipHelper.GetById(memberId); CmMember = new ContentModels.Member(ipMember); } else { CmMember = new ContentModels.Member(Udi.Parse(sRecord.Fields[Common.NodeProperties.prayerRequestMember]).ToPublishedContent()); } StringBuilder sbAuthor = new StringBuilder(); sbAuthor.Append(CmMember.FirstName); sbAuthor.Append(" "); sbAuthor.Append(CmMember.LastName); sbAuthor.Append("."); prayerLink.MemberName = sbAuthor.ToString(); // searchList.lstPrayerLinks.Add(prayerLink); //prayerLink.currentPercentage = int.Parse(sRecord.Fields[Common.NodeProperties.currentPercentage]); //IEnumerable<string> prayerSummary = sRecord.Fields[Common.NodeProperties.prayer].Split().Take(32); //prayerLink.PrayerSummary = string.Join(" ", prayerSummary) + "..."; ////Obtain member //ContentModels.Member CmMember; //int memberId; //if (int.TryParse(sRecord.Fields[Common.NodeProperties.prayerRequestMember], out memberId)) //{ // IPublishedContent ipMember = memberShipHelper.GetById(memberId); // CmMember = new ContentModels.Member(ipMember); //} //else //{ // CmMember = new ContentModels.Member(Udi.Parse(sRecord.Fields[Common.NodeProperties.prayerRequestMember]).ToPublishedContent()); //} //StringBuilder sbAuthor = new StringBuilder(); //sbAuthor.Append(CmMember.FirstName); //sbAuthor.Append(" "); //sbAuthor.Append(CmMember.LastName); //sbAuthor.Append("."); //prayerLink.MemberName = sbAuthor.ToString(); //searchList.lstPrayerLinks.Add(prayerLink); } } }
//Search by private void ObtainByIlluminationStories(Models.SearchList searchList, int pageNo) { //Instantiate variables var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); searchList.ShowIlluminationStories = true; searchList.SearchInTitle = "Illumination Stories"; if (!string.IsNullOrWhiteSpace(searchList.SearchFor)) { //Set up search criteria BaseSearchProvider mySearcher = ExamineManager.Instance.SearchProviderCollection[Common.searchProviders.IlluminationStoriesSearcher]; ISearchCriteria criteria = mySearcher.CreateSearchCriteria(BooleanOperation.Or); //Setup up search fields by importance IBooleanOperation query = criteria.Field(Common.NodeProperties.title, searchList.SearchFor.MultipleCharacterWildcard()); query.Or().Field(Common.NodeProperties.story, searchList.SearchFor.MultipleCharacterWildcard()); query.Or().Field(Common.NodeProperties.experienceType, searchList.SearchFor.MultipleCharacterWildcard()); query.Or().Field(Common.NodeProperties.member, searchList.SearchFor.MultipleCharacterWildcard()); //IBooleanOperation query = criteria.Field(Common.NodeProperties.title, searchList.SearchFor.Boost(2)); //query.Or().Field(Common.NodeProperties.story, searchList.SearchFor.Boost(1)); //query.Or().Field(Common.NodeProperties.experienceType, searchList.SearchFor); //query.Or().Field(Common.NodeProperties.member, searchList.SearchFor); //Obtain result with query ISearchResults searchResults = mySearcher.Search(query.Compile()); //Get item counts and total experiences. searchList.Pagination.totalItems = searchResults.Count(); //Determine how many pages/items to skip and take, as well as the total page count for the search result. if (searchList.Pagination.totalItems > searchList.Pagination.itemsPerPage) { searchList.Pagination.totalPages = (int)Math.Ceiling((double)searchList.Pagination.totalItems / (double)searchList.Pagination.itemsPerPage); } else { searchList.Pagination.itemsPerPage = searchList.Pagination.totalItems; searchList.Pagination.totalPages = 1; } //Determine current page number if (pageNo <= 0 || pageNo > searchList.Pagination.totalPages) { pageNo = 1; } searchList.Pagination.pageNo = pageNo; //Determine how many pages/items to skip if (searchList.Pagination.totalItems > searchList.Pagination.itemsPerPage) { searchList.Pagination.itemsToSkip = searchList.Pagination.itemsPerPage * (pageNo - 1); } //Convert list of SearchResults to list of classes foreach (SearchResult sRecord in searchResults.Skip(searchList.Pagination.itemsToSkip).Take(searchList.Pagination.itemsPerPage)) { var storyLink = new Models.illuminationStoryLink(); storyLink.experienceType = sRecord.Fields[Common.NodeProperties.experienceType]; storyLink.id = sRecord.Id; storyLink.title = sRecord.Fields[Common.NodeProperties.title]; storyLink.url = Umbraco.NiceUrl(sRecord.Id); //Obtain member ContentModels.Member CmMember; int memberId; if (int.TryParse(sRecord.Fields[Common.NodeProperties.member], out memberId)) { IPublishedContent ipMember = memberShipHelper.GetById(memberId); CmMember = new ContentModels.Member(ipMember); } else { CmMember = new ContentModels.Member(Udi.Parse(sRecord.Fields[Common.NodeProperties.member]).ToPublishedContent()); } //var CmMember = new ContentModels.Member(Udi.Parse(sRecord.Fields[Common.NodeProperties.member]).ToPublishedContent()); StringBuilder sbAuthor = new StringBuilder(); sbAuthor.Append(CmMember.FirstName); sbAuthor.Append(" "); sbAuthor.Append(CmMember.LastName); sbAuthor.Append("."); storyLink.memberName = sbAuthor.ToString(); storyLink.memberId = CmMember.Id; searchList.lstStoryLink.Add(storyLink); } } }
public ActionResult RenderList() { //Instantiate variables var prayerList = new Models.PrayerList(); try { // var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); var CmPrayerList = new ContentModels.PrayerList(Umbraco.TypedContent((int)Common.siteNode.ThePrayerCorner)); //Get all prayers BaseSearchProvider mySearcher = ExamineManager.Instance.SearchProviderCollection[Common.searchProviders.PrayersSearcher]; ISearchCriteria criteria = mySearcher.CreateSearchCriteria(IndexTypes.Content); IBooleanOperation query = criteria.Field(Common.NodeProperties.indexType, Common.NodeProperties.content); //gets all items query.And().OrderByDescending(Common.NodeProperties.requestDate); query.And().OrderBy(Common.NodeProperties.prayerTitle); ISearchResults isResults = mySearcher.Search(query.Compile()); //Get item counts and total experiences. prayerList.Pagination.itemsPerPage = 10; prayerList.Pagination.totalItems = isResults.Count(); //Determine how many pages/items to skip and take, as well as the total page count for the search result. if (prayerList.Pagination.totalItems > prayerList.Pagination.itemsPerPage) { prayerList.Pagination.totalPages = (int)Math.Ceiling((double)prayerList.Pagination.totalItems / (double)prayerList.Pagination.itemsPerPage); } else { prayerList.Pagination.itemsPerPage = prayerList.Pagination.totalItems; prayerList.Pagination.totalPages = 1; } //Determine current page number var pageNo = 1; if (!string.IsNullOrEmpty(Request.QueryString[Common.miscellaneous.PageNo])) { int.TryParse(Request.QueryString[Common.miscellaneous.PageNo], out pageNo); if (pageNo <= 0 || pageNo > prayerList.Pagination.totalPages) { pageNo = 1; } } prayerList.Pagination.pageNo = pageNo; //Determine how many pages/items to skip if (prayerList.Pagination.totalItems > prayerList.Pagination.itemsPerPage) { prayerList.Pagination.itemsToSkip = prayerList.Pagination.itemsPerPage * (pageNo - 1); } //Convert list of SearchResults to list of classes foreach (SearchResult sRecord in isResults.Skip(prayerList.Pagination.itemsToSkip).Take(prayerList.Pagination.itemsPerPage)) { //Create new prayerLink class var prayerLink = new Models.PrayerLink(); prayerLink.Id = sRecord.Id; prayerLink.Title = sRecord.Fields[Common.NodeProperties.prayerTitle]; prayerLink.Url = Umbraco.NiceUrl(sRecord.Id); prayerLink.Date = Convert.ToDateTime(sRecord.Fields[Common.NodeProperties.requestDate]); //Determine current percentage prayerLink.currentPercentage = int.Parse(sRecord.Fields[Common.NodeProperties.currentPercentage]); prayerLink.baseCalculationDate = DateTime.Parse(sRecord.Fields[Common.NodeProperties.baseCalculationDate]); int daysSinceBaseDate = (DateTime.Now - prayerLink.baseCalculationDate).Days; if (daysSinceBaseDate > prayerLink.currentPercentage) { prayerLink.currentPercentage = 0; } else { prayerLink.currentPercentage = prayerLink.currentPercentage - daysSinceBaseDate; } //Determine proper candle based upon current percentage prayerLink.CandleUrl = CmPrayerList.CandleOut.Url; if (prayerLink.currentPercentage == 0) { prayerLink.CandleUrl = CmPrayerList.CandleOut.Url; } else if (prayerLink.currentPercentage >= 1 && prayerLink.currentPercentage <= 10) { prayerLink.CandleUrl = CmPrayerList.Candle10.Url; } else if (prayerLink.currentPercentage >= 11 && prayerLink.currentPercentage <= 20) { prayerLink.CandleUrl = CmPrayerList.Candle20.Url; } else if (prayerLink.currentPercentage >= 21 && prayerLink.currentPercentage <= 30) { prayerLink.CandleUrl = CmPrayerList.Candle30.Url; } else if (prayerLink.currentPercentage >= 31 && prayerLink.currentPercentage <= 40) { prayerLink.CandleUrl = CmPrayerList.Candle40.Url; } else if (prayerLink.currentPercentage >= 41 && prayerLink.currentPercentage <= 50) { prayerLink.CandleUrl = CmPrayerList.Candle50.Url; } else if (prayerLink.currentPercentage >= 51 && prayerLink.currentPercentage <= 60) { prayerLink.CandleUrl = CmPrayerList.Candle60.Url; } else if (prayerLink.currentPercentage >= 61 && prayerLink.currentPercentage <= 70) { prayerLink.CandleUrl = CmPrayerList.Candle70.Url; } else if (prayerLink.currentPercentage >= 71 && prayerLink.currentPercentage <= 80) { prayerLink.CandleUrl = CmPrayerList.Candle80.Url; } else if (prayerLink.currentPercentage >= 81 && prayerLink.currentPercentage <= 90) { prayerLink.CandleUrl = CmPrayerList.Candle90.Url; } else if (prayerLink.currentPercentage >= 91 && prayerLink.currentPercentage <= 100) { prayerLink.CandleUrl = CmPrayerList.Candle100.Url; } // IEnumerable <string> prayerSummary = sRecord.Fields[Common.NodeProperties.prayer].Split().Take(32); prayerLink.PrayerSummary = string.Join(" ", prayerSummary) + "..."; //Obtain member ContentModels.Member CmMember; int memberId; if (int.TryParse(sRecord.Fields[Common.NodeProperties.prayerRequestMember], out memberId)) { IPublishedContent ipMember = memberShipHelper.GetById(memberId); CmMember = new ContentModels.Member(ipMember); } else { CmMember = new ContentModels.Member(Udi.Parse(sRecord.Fields[Common.NodeProperties.prayerRequestMember]).ToPublishedContent()); } StringBuilder sbAuthor = new StringBuilder(); sbAuthor.Append(CmMember.FirstName); sbAuthor.Append(" "); sbAuthor.Append(CmMember.LastName); sbAuthor.Append("."); prayerLink.MemberName = sbAuthor.ToString(); // prayerList.lstPrayerLinks.Add(prayerLink); } } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine(@"PrayerController.cs : RenderList()"); sb.AppendLine("model:" + Newtonsoft.Json.JsonConvert.SerializeObject(prayerList)); Common.SaveErrorMessage(ex, sb, typeof(PrayerController)); ModelState.AddModelError("", "*An error occured while creating the prayer list."); return(CurrentUmbracoPage()); } //Return data to partialview return(PartialView("~/Views/Partials/PrayerCorner/_prayerList.cshtml", prayerList)); }
public ExistingComplaintReportViewModel(ComplaintReport c) { ComplaintReportId = c.ComplaintReportId; MachineNo1 = c.MachineNo1; MachineNo2 = c.MachineNo2; DealerId = c.MemberId; SaleDate = c.SaleDate; DamageDate = c.DamageDate; RepairDate = c.RepairDate; TimeAmount = c.TimeAmount; EngineNo = c.EngineNo; Customer = new CustomerViewModel() { CustomerId = c.Customer.CustomerId, Name = c.Customer.Name, Address = c.Customer.Address, CustomerType = c.Customer.CustomerType }; var memberShipHelper = new Umbraco.Web.Security.MembershipHelper(Umbraco.Web.UmbracoContext.Current); var memberId = memberShipHelper.GetCurrentMemberId(); var memberService = ApplicationContext.Current.Services.MemberService; var m = memberService.GetById(c.MemberId); Dealer = new DealerViewModel(m); Product = new ProductViewModel(c.ProductModel.Product); ProductModel = new ProductModelViewModel(c.ProductModel); Status = c.Status; SelectedProduct = c.ProductModel.ProductId; SelectedProductModel = c.ProductModelId; Closed = c.Closed; Error = c.Error; ReasonForError = c.ReasonForError; PartsMarked = c.PartsMarked; PartsReturned = c.PartsReturned; CreateEmail = c.CreateEmail; //Parts = new List<PartViewModel>(); //Parts.AddRange(c.ComplaintReportParts.Select(p => // new PartViewModel(){ // PartId = p.PartId, // Description = p.Description, // PartNo = p.PartNo, // Price = p.Price, // Shipping = p.Shipping, // })); var parts = c.ComplaintReportParts.Select(p => new PartViewModel() { PartId = p.PartId, Description = p.Part.Description, PartNo = p.Part.PartNo, Price = p.Part.Price, Shipping = p.Part.Shipping, Amount = p.Amount }); Parts = new List <PartViewModel>(); Parts.AddRange(parts); SentToApproval = c.SentToApproval; }