public ActionResult Redirect(string url) { var viewdata = new FacebookViewData { pageUrl = url }; return(View(viewdata)); }
/// <summary> /// profile tab /// </summary> /// <returns></returns> public ActionResult Profile(string fb_sig_in_profile_tab, string fb_sig_page_id, string fb_sig_type, string fb_sig_profile_id, int?fb_sig_is_fan) { if (string.IsNullOrEmpty(fb_sig_in_profile_tab)) { Syslog.Write(new Exception("Not from Page" + fb_sig_type + "," + fb_sig_page_id + "," + fb_sig_profile_id)); } string pageType; if (!string.IsNullOrEmpty(fb_sig_type)) { pageType = fb_sig_type == "APPLICATION" ? "APPLICATION" : "FANPAGE"; } else { pageType = "PROFILE"; } var viewdata = new FacebookViewData { isTab = true, pageID = fb_sig_page_id, pageType = pageType, profileID = fb_sig_profile_id }; // look for an entry in db, if none found for this page then it has not been configured yet. string identifier = ""; if (!string.IsNullOrEmpty(fb_sig_page_id)) { identifier = fb_sig_page_id; } else if (!string.IsNullOrEmpty(fb_sig_profile_id)) { identifier = fb_sig_profile_id; } var fbpage = repository.GetFacebookPage(identifier).SingleOrDefault(); if (fbpage != null) { var subdomain = fbpage.MASTERsubdomain.name; var org = fbpage.MASTERsubdomain.organisation; // render store viewdata.isConfigured = true; viewdata.storeName = org.name; viewdata.gallery = new Gallery { viewAllUrl = string.Concat("http://", subdomain, ".tradelr.com"), categories = repository.GetProductCategories(null, fbpage.subdomainid) .Select(x => new SelectListItem() { Text = x.MASTERproductCategory.name, Value = x.id.ToString() }), products = repository.GetProducts(fbpage.subdomainid) .OrderByDescending(x => x.id) .Take(21) .ToModel(subdomain) }; // show logo if there is one if (fbpage.MASTERsubdomain.organisation.logo.HasValue) { viewdata.logoUrl = string.Concat(viewdata.gallery.viewAllUrl, org.image.ToModel(Imgsize.BANNER).url); viewdata.storeName = ""; } // handle coupon message if (fbpage.MASTERsubdomain.facebookCoupon.HasValue) { if (fb_sig_is_fan == 1) { var coupon = fbpage.MASTERsubdomain.coupon; var currency = fbpage.MASTERsubdomain.currency.ToCurrency(); string description; string minimumPurchase = " on all purchases."; if (coupon.minimumPurchase.HasValue) { minimumPurchase = string.Format(" with a minimum purchase of {0}{1}.", currency.code, coupon.minimumPurchase.Value.ToString("n" + currency.decimalCount)); } if (coupon.couponPercentage.HasValue) { description = string.Format("{0}% discount", coupon.couponPercentage.Value.ToString("n2")); } else { description = string.Format("{0}{1} off", currency.code, coupon.couponValue.Value.ToString("n" + currency.decimalCount)); } viewdata.couponMessage = string.Format( "<p><strong>Discount code:</strong> {0}</p><p>{1}{2}</p>", coupon.code, description, minimumPurchase); } else { viewdata.couponMessage = string.Format("<p class='strong'><img src='{0}/Content/img/arrow_up.png' /> Click on the like button above to view the latest discount code.</p>", GeneralConstants.FACEBOOK_HOST); } } return(View("Gallery", viewdata)); } return(View(viewdata)); }
public ActionResult Configure(string pageid, string address, PageType?pagetype, string profileid, string fb_sig_user) { bool isError = false; string identifier = ""; if ((string.IsNullOrEmpty(pageid) && string.IsNullOrEmpty(profileid)) || string.IsNullOrEmpty(address)) { isError = true; } if (!string.IsNullOrEmpty(pageid)) { identifier = pageid; } else if (!string.IsNullOrEmpty(profileid)) { identifier = profileid; } else { isError = true; Syslog.Write(new Exception("NULL FB identifier")); } Uri storeAddress = null; try { if (address.IndexOf('.') == -1) { // user only enter store name address = string.Format("{0}.tradelr.com", address); } if (!address.StartsWith("http")) { // user did not enter http address = string.Format("http://{0}", address); } storeAddress = new Uri(address); } catch (Exception ex) { Syslog.Write(new Exception("FB: Unable to parse " + address)); isError = true; } // pagetype can be empty if from a profile if (!pagetype.HasValue) { pagetype = PageType.PROFILE; } if (!isError) { string subdomain = ""; if (storeAddress.Host.Split('.').Length > 2) { int lastIndex = storeAddress.Host.LastIndexOf("."); int index = storeAddress.Host.LastIndexOf(".", lastIndex - 1); subdomain = storeAddress.Host.Substring(0, index); } else { isError = true; } var mastersd = repository.GetSubDomains().Where(x => x.name == subdomain).SingleOrDefault(); if (mastersd == null) { Syslog.Write(ErrorLevel.INFORMATION, "New FB subdomain:" + subdomain); // create new account return(RedirectToAction("Redirect", new { url = string.Format( "{0}/newaccount?id={1}&identifier={2}&pagetype={3}", GeneralConstants.FACEBOOK_APP_URL, subdomain, identifier, pagetype.Value) })); } // check if there's already an entry, we ignore if there's already an entry var existing = repository.GetFacebookPage(identifier).Where(x => x.subdomainid == mastersd.id).SingleOrDefault(); if (existing == null) { var newEntry = new facebookPage { subdomainid = mastersd.id, pageid = identifier }; repository.AddFacebookPage(newEntry); } } string returnUrl = pagetype.Value.ToReturnUrl(identifier); var viewdata = new FacebookViewData { pageUrl = returnUrl, errorMessage = "This is not a valid store address" }; if (isError) { return(View("Error", viewdata)); } return(RedirectToAction("Redirect", new { url = returnUrl })); }
/// <summary> /// handler for canvas page for tradelr facebook app /// </summary> public ActionResult Index(string auth_token, string fb_sig_user) { var viewdata = new FacebookViewData(); return(View(viewdata)); }