//public int test(string videoId) //{ // //Connect to the Umbraco DB // var db = _context.GetDatabaseContext(); // var record = db.SingleOrDefault<VideoItem>("WHERE VideoId=@0", videoId); //} public int CreateNewVideoNode(string videoUrl, string videoTitle, string subCategoryIdsList, int monthNodeId) { try { var memberShipHelper = new MembershipHelper(UmbracoContext.Current); var member = (MyMember)_umbracoHelper.TypedMember(memberShipHelper.GetCurrentMemberId()); var newVideoNode = _content.CreateContent(VideoIdExtractor(videoUrl), monthNodeId, "VideoPage", 0); newVideoNode.SetValue("title", videoTitle); newVideoNode.SetValue("videoUrl", videoUrl); newVideoNode.SetValue("videoId", VideoIdExtractor(videoUrl)); newVideoNode.SetValue("date", DateTime.Now); newVideoNode.SetValue("memberName", member.Name); newVideoNode.SetValue("views", 0); newVideoNode.SetValue("likes", 0); newVideoNode.SetValue("dislikes", 0); newVideoNode.SetValue("shares", 0); _content.SaveAndPublishWithStatus(newVideoNode); return _content.SaveAndPublishWithStatus(newVideoNode).Result.StatusType.ToString() == "Success" ? newVideoNode.Id : 0; //new video node creation in Umbraco } catch (Exception e) { return 0; } }
public IMember GetCurrentMember() { var memberId = membershipHelper.GetCurrentMemberId(); var memberService = ApplicationContext.Current.Services.MemberService; var m = memberService.GetById(memberId); return(m); }
/// <summary> /// Attempts to either retrieve an anonymous customer or an existing customer /// </summary> /// <param name="key">The key of the customer to retrieve</param> private void TryGetCustomer(Guid key) { var customer = (ICustomerBase)_cache.RuntimeCache.GetCacheItem(CacheKeys.CustomerCacheKey(key)); // check the cache for a previously retrieved customer if (customer != null) { CurrentCustomer = customer; if (customer.IsAnonymous) { if (_membershipHelper.IsLoggedIn()) { var memberId = _membershipHelper.GetCurrentMemberId(); var member = _memberService.GetById(memberId); if (MerchelloConfiguration.Current.CustomerMemberTypes.Any(x => x == member.ContentTypeAlias)) { var anonymousBasket = Basket.GetBasket(_merchelloContext, customer); customer = _customerService.GetByLoginName(member.Username) ?? _customerService.CreateCustomerWithKey(member.Username); var customerBasket = Basket.GetBasket(_merchelloContext, customer); //// convert the customer basket ConvertBasket(anonymousBasket, customerBasket); CacheCustomer(customer); CurrentCustomer = customer; return; } } } ContextData.Key = customer.Key; return; } // try to get the customer customer = _customerService.GetAnyByKey(key); if (customer != null) { CurrentCustomer = customer; ContextData.Key = customer.Key; CacheCustomer(customer); } else { // create a new anonymous customer CreateAnonymousCustomer(); } }
/// <summary> /// Attempts to either retrieve an anonymous customer or an existing customer /// </summary> /// <param name="key">The key of the customer to retrieve</param> private void TryGetCustomer(Guid key) { var customer = (ICustomerBase)_cache.RuntimeCache.GetCacheItem(CacheKeys.CustomerCacheKey(key)); var isLoggedIn = (bool)_cache.RequestCache.GetCacheItem(CacheKeys.CustomerIsLoggedIn(key), () => _membershipHelper.IsLoggedIn()); // check the cache for a previously retrieved customer if (customer != null) { CurrentCustomer = customer; if (customer.IsAnonymous) { if (isLoggedIn) { var memberId = _membershipHelper.GetCurrentMemberId(); var member = _memberService.GetById(memberId); if (MerchelloConfiguration.Current.CustomerMemberTypes.Any(x => x == member.ContentTypeAlias)) { var anonymousBasket = Basket.GetBasket(_merchelloContext, customer); customer = _customerService.GetByLoginName(member.Username) ?? _customerService.CreateCustomerWithKey(member.Username); ContextData.Key = customer.Key; ContextData.Values.Add(new KeyValuePair <string, string>(UmbracoMemberIdDataKey, memberId.ToString(CultureInfo.InvariantCulture))); var customerBasket = Basket.GetBasket(_merchelloContext, customer); //// convert the customer basket ConvertBasket(anonymousBasket, customerBasket); CacheCustomer(customer); CurrentCustomer = customer; return; } } } else if (customer.IsAnonymous == false && isLoggedIn == false) { CreateAnonymousCustomer(); return; } else if (customer.IsAnonymous == false && isLoggedIn) { this.EnsureIsLoggedInCustomer(customer); } ContextData.Key = customer.Key; return; } // try to get the customer customer = _customerService.GetAnyByKey(key); if (customer != null) { CurrentCustomer = customer; ContextData.Key = customer.Key; if (isLoggedIn) { ContextData.Values.Add(new KeyValuePair <string, string>(UmbracoMemberIdDataKey, _membershipHelper.GetCurrentMemberId().ToString(CultureInfo.InvariantCulture))); } CacheCustomer(customer); } else { // create a new anonymous customer CreateAnonymousCustomer(); } }
//[ValidateGoogleCaptcha] public ActionResult HandleAjaxForm(FormCollection frm) { var typeName = frm["FullName"]; var form = new MCFlyApiController().GetByAlias(typeName); var type = UIOMatic.Helper.GetUIOMaticTypes().FirstOrDefault(x => x.FullName == typeName); var instance = Activator.CreateInstance(type); var dict = new Dictionary <string, object>(); foreach (PropertyInfo prop in type.GetProperties()) { if (prop.Name != "Id" && prop.Name != "Created" && prop.Name != "UmbracoPage" && prop.Name != "UmbracoMember") { var fld = form.Fields.FirstOrDefault(x => x.Alias == prop.Name); var val = fld.FieldType.Process(form, fld, !frm.AllKeys.Contains(prop.Name) ? null : frm[prop.Name], ControllerContext); if (fld.FieldType.FrontEndRenderView == "CheckBox" && (bool)val == false) { ModelState.AddModelError(string.Empty, $"The field {0} is required"); } if (val != null && val.ToString() != string.Empty) { prop.SetValue(instance, val); dict.Add(prop.Name, val); } } if (prop.Name == "Member") { var memberShipHelper = new MembershipHelper(Umbraco.UmbracoContext); var member = Services.MemberService.GetById(memberShipHelper.GetCurrentMemberId()); if (memberShipHelper.IsLoggedIn()) { prop.SetValue(instance, member.Name); dict.Add("UmbracoMember", member.Name); } else { prop.SetValue(instance, ""); dict.Add("UmbracoMember", ""); } } if (prop.Name == "Created") { prop.SetValue(instance, DateTime.Now); dict.Add("Created", DateTime.Now); } if (prop.Name == "UmbracoPage") { prop.SetValue(instance, frm["Umbraco.AssignedContentItem.Id"]); dict.Add("UmbracoPage", frm["Umbraco.AssignedContentItem.Id"]); } } // Server Side Validation var context = new ValidationContext(instance, null, null); var results = new List <ValidationResult>(); Validator.TryValidateObject(instance, context, results, true); if (results.Any()) { foreach (var error in results) { ModelState.AddModelError(error.MemberNames.FirstOrDefault(), error.ErrorMessage); } } if (!ModelState.IsValid) { return(Json(new { message = "Failure" })); } ////workaround for nullable string props foreach (PropertyInfo prop in type.GetProperties()) { if (prop.Name != "Id" && prop.Name != "Created" && prop.Name != "UmbracoPage" && prop.Name != "UmbracoMember") { if (string.IsNullOrEmpty(frm[prop.Name]) && prop.PropertyType == typeof(string)) { var val = string.Empty; if (prop.GetValue(instance) == null) { prop.SetValue(instance, val); dict.Remove(prop.Name); dict.Add(prop.Name, val); } } } } //Store Record to DB if (form.StoresData) { UIOMaticObjectService.Instance.Create(type, dict); } //Send Emails foreach (var email in form.Emails) { var mm = new MailMessage { Body = EmailRenderer.Render(email.Template, instance, form, email, Umbraco.TypedContent(frm["Umbraco.AssignedContentItem.Id"])), IsBodyHtml = true, Subject = email.Subject ?? "New " + form.Name + " entry", From = new MailAddress(email.From) }; mm.Headers.Add("X-Application", "Website"); mm.Headers.Add("MIME-Version", "1.0"); mm.Headers.Add("Content-Type", "text/html;charset=utf-8"); mm.Headers.Add("Content-Transfer-Encoding", "base64"); mm.SubjectEncoding = Encoding.UTF8; mm.HeadersEncoding = Encoding.UTF8; mm.BodyEncoding = Encoding.UTF8; mm.To.Add(email.ToProperty != string.Empty ? new MailAddress(type.GetProperty(email.ToProperty).GetValue(instance).ToString(), type.GetProperty(email.ToProperty).GetValue(instance).ToString(), Encoding.UTF8) : new MailAddress(email.To, email.To, Encoding.UTF8)); using (SmtpClient client = new SmtpClient()) { client.Send(mm); } } //Do more stuff if (!string.IsNullOrEmpty(form.WebHookUrl)) { var client = new WebClient { Encoding = Encoding.UTF8 }; client.Headers[HttpRequestHeader.ContentType] = "application/json"; try { var response = client.UploadString(form.WebHookUrl, "POST", JsonConvert.SerializeObject(dict)); } catch (Exception ex) { //log } } return(Json(new { Success = true })); }
public ActionResult HandleForm(FormCollection frm) { var typeName = frm["FullName"]; var form = new MCFlyApiController().GetByAlias(typeName); var type = UIOMatic.Helper.GetUIOMaticTypes().FirstOrDefault(x => x.FullName == typeName); var instance = Activator.CreateInstance(type); var dict = new Dictionary <string, object>(); foreach (PropertyInfo prop in type.GetProperties()) { if (prop.Name != "Id" && prop.Name != "Created" && prop.Name != "UmbracoPage" && prop.Name != "UmbracoMember") { var fld = form.Fields.FirstOrDefault(x => x.Alias == prop.Name); var val = fld.FieldType.Process(form, fld, !frm.AllKeys.Contains(prop.Name) ? null : frm[prop.Name], ControllerContext); if (val != null && val.ToString() != string.Empty) { prop.SetValue(instance, val); dict.Add(prop.Name, val); } } if (prop.Name == "Member") { var memberShipHelper = new MembershipHelper(Umbraco.UmbracoContext); var member = Services.MemberService.GetById(memberShipHelper.GetCurrentMemberId()); if (memberShipHelper.IsLoggedIn()) { prop.SetValue(instance, member.Name); dict.Add("UmbracoMember", member.Name); } else { prop.SetValue(instance, ""); dict.Add("UmbracoMember", ""); } } if (prop.Name == "Created") { prop.SetValue(instance, DateTime.Now); dict.Add("Created", DateTime.Now); } if (prop.Name == "UmbracoPage") { prop.SetValue(instance, CurrentPage.Id.ToString()); dict.Add("UmbracoPage", CurrentPage.Id.ToString()); } } //Server Side Validation var context = new ValidationContext(instance, null, null); var results = new List <ValidationResult>(); Validator.TryValidateObject(instance, context, results, true); if (results.Any()) { foreach (var error in results) { ModelState.AddModelError(error.MemberNames.FirstOrDefault(), error.ErrorMessage); } } if (!ModelState.IsValid) { return(CurrentUmbracoPage()); } ////workaround for nullable string props foreach (PropertyInfo prop in type.GetProperties()) { if (prop.Name != "Id" && prop.Name != "Created" && prop.Name != "UmbracoPage") { if (string.IsNullOrEmpty(frm[prop.Name]) && prop.PropertyType == typeof(string)) { var val = string.Empty; if (prop.GetValue(instance) == null) { prop.SetValue(instance, val); dict.Remove(prop.Name); dict.Add(prop.Name, val); } } } } //Store Record to DB if (form.StoresData) { UIOMaticObjectService.Instance.Create(type, dict); } //Send Emails foreach (var email in form.Emails) { var mm = new MailMessage { Body = EmailRenderer.Render(email.Template, instance, form, email, CurrentPage), IsBodyHtml = true, Subject = email.Subject ?? "New " + form.Name + " entry", From = new MailAddress(email.From) }; mm.To.Add(email.ToProperty != string.Empty ? new MailAddress(type.GetProperty(email.ToProperty).GetValue(instance).ToString()) : new MailAddress(email.To)); new SmtpClient().Send(mm); } //Do more stuff if (!string.IsNullOrEmpty(form.WebHookUrl)) { var client = new WebClient { Encoding = Encoding.UTF8 }; client.Headers[HttpRequestHeader.ContentType] = "application/json"; try { var response = client.UploadString(form.WebHookUrl, "POST", JsonConvert.SerializeObject(dict)); } catch (Exception ex) { //log } } //redir TempData["success"] = true; return(RedirectToCurrentUmbracoPage()); }
/// <summary> /// Attempts to either retrieve an anonymous customer or an existing customer /// </summary> /// <param name="key">The key of the customer to retrieve</param> private void TryGetCustomer(Guid key) { var customer = (ICustomerBase)_cache.RuntimeCache.GetCacheItem(CacheKeys.CustomerCacheKey(key)); var isLoggedIn = (bool)_cache.RequestCache.GetCacheItem(CacheKeys.CustomerIsLoggedIn(key), () => _membershipHelper.IsLoggedIn()); // check the cache for a previously retrieved customer if (customer != null) { CurrentCustomer = customer; if (customer.IsAnonymous) { if (isLoggedIn) { var memberId = _membershipHelper.GetCurrentMemberId(); var member = _memberService.GetById(memberId); if (MerchelloConfiguration.Current.CustomerMemberTypes.Any(x => x == member.ContentTypeAlias)) { var anonymousBasket = Basket.GetBasket(_merchelloContext, customer); customer = _customerService.GetByLoginName(member.Username) ?? _customerService.CreateCustomerWithKey(member.Username); ContextData.Key = customer.Key; var customerBasket = Basket.GetBasket(_merchelloContext, customer); //// convert the customer basket ConvertBasket(anonymousBasket, customerBasket); CacheCustomer(customer); CurrentCustomer = customer; return; } } } else if (customer.IsAnonymous == false && isLoggedIn == false) { // customer has logged out, so we need to go back to an anonymous customer var cookie = _umbracoContext.HttpContext.Request.Cookies[CustomerCookieName]; cookie.Expires = DateTime.Now.AddDays(-1); _cache.RequestCache.ClearCacheItem(CustomerCookieName); _cache.RuntimeCache.ClearCacheItem(CacheKeys.CustomerCacheKey(customer.Key)); Initialize(); return; } ContextData.Key = customer.Key; return; } // try to get the customer customer = _customerService.GetAnyByKey(key); if (customer != null) { CurrentCustomer = customer; ContextData.Key = customer.Key; CacheCustomer(customer); } else { // create a new anonymous customer CreateAnonymousCustomer(); } }
//Current member public ActionResult RenderViewOwnProfile() { //Get profileURLtoCheck //string profileURLtoCheck = Request.RequestContext.RouteData.Values["profileURLtoCheck"].ToString(); //Create a view model ViewProfileViewModel profile = new ViewProfileViewModel(); var membershipService = ApplicationContext.Services.MemberService; ////Check we have a value in the URL //if (string.IsNullOrEmpty(profileURL)) //{ // return new HttpNotFoundResult("No profile URL parameter was provided"); //} //var currentMember = memmembershipService..GetById(this.base.Umbraco.UmbracoHelper.Members.GetCurrentMemberId())); //Try and find member with the QueryString value ?profileURLtoCheck=warrenbuckley //Member findMember = Member.GetAllAsList().FirstOrDefault(x => x.getProperty("profileURL").Value.ToString() == profileURLtoCheckMember); //var findMember = membershipService.GetMembersByPropertyValue("profileURL", profileURL, StringPropertyMatchType.Exact).SingleOrDefault(); var memberShipHelper = new MembershipHelper(UmbracoContext); var findMember = membershipService.GetById(memberShipHelper.GetCurrentMemberId()); //Check if we found member if (findMember == null) { return(new HttpNotFoundResult("The member profile does not exist")); } ////Increment profile view counter by one //int noOfProfileViews = 0; //int.TryParse(findMember.Properties["numberOfProfileViews"].Value?.ToString(), out noOfProfileViews); ////Increment counter by one //findMember.Properties["numberOfProfileViews"].Value = noOfProfileViews + 1; ////Save it down to the member //membershipService.Save(findMember); int noOfProfileViews = 0; int.TryParse(findMember.Properties["numberOfProfileViews"].Value?.ToString(), out noOfProfileViews); int noOfLogins = 0; int.TryParse(findMember.Properties["numberOfLogins"].Value.ToString(), out noOfLogins); //Got the member lets bind the data to the view model profile.Name = findMember.Name; profile.MemberID = findMember.Id; profile.EmailAddress = findMember.Email; //profile.Description = findMember.Properties["description"].Value.ToString(); //profile.LinkedIn = findMember.Properties["linkedIn"].Value?.ToString(); //profile.Skype = findMember.Properties["skype"].Value?.ToString(); //profile.Twitter = findMember.Properties["twitter"].Value?.ToString(); profile.NumberOfLogins = noOfLogins; profile.LastLoginDate = findMember.LastLoginDate; profile.NumberOfProfileViews = noOfProfileViews; //////////////////////////////// return(PartialView("_ViewProfile", profile)); }
public int GetCurrentMemberId() { return(membershipHelper.GetCurrentMemberId()); }