public override string Render(string[] path, string body = "", object metadata = null) { if (!HasPermissions(Query.Models.LogApi.Names.CampaignDetails)) { return(""); } if (path.Length <= 1) { context.Response.StatusCode = 500; return("URL is missing parameters"); } try { var campaignId = int.Parse(path[1]); var html = ""; //load campaign details var scaffold = new Scaffold("/Views/Campaign/details.html"); var campaign = Query.Campaigns.GetInfoByUserId(User.userId, campaignId); var message = Query.CampaignMessages.GetInfo(campaignId); scaffold.Bind(new { campaign, message, recepients = new { total = Query.CampaignQueue.TotalEmails(campaignId) } }); html = scaffold.Render(); if (parameters.ContainsKey("nolayout")) { return(RenderCORS(html)); } return(base.Render(path, html, metadata)); } catch (Exception) { return(Error("Error retrieving campaign details (10102). Please report error to " + Settings.ContactInfo.CustomerService.email)); } }
public string Create(int subscriptionId, string entryemail, string firstname, string lastname) { if (!HasPermissions()) { return(Error()); } //get accessable subscriptions for user var subscriptions = Query.Subscriptions.GetSubscriptions(User.userId); var subscription = subscriptions.Where(a => a.subscriptionId == subscriptionId).FirstOrDefault(); if (subscription != null) { //check if user has permission to create new addressbook entries if (subscription.roleType <= Query.Models.RoleType.contributer) { //check if address already exists in team's address book if (Query.AddressBookEntries.Exists(subscription.teamId, entryemail) == true) { return(Error("Email address already exists in address book")); } var addressId = Query.AddressBookEntries.Create(new Query.Models.AddressBookEntry() { teamId = subscription.teamId, email = entryemail, firstname = firstname, lastname = lastname }); //render addressbook entry HTML var entryItem = new Scaffold("/Views/Subscription/addressbook/entry-item.html"); entryItem.Bind(new { entry = new { addressid = addressId, email = entryemail, firstname, lastname } }); entryItem.Show("is-new"); return(JsonResponse(new { addressId = addressId.ToString(), html = entryItem.Render() })); } } return(Error("You do not have permission to create new address book entries")); }
private string GetTeams(int subscriptionId) { var subscription = Query.Subscriptions.GetInfo(subscriptionId); if (subscription != null) { var scaffold = new Scaffold("/Views/Subscription/team.html"); scaffold["team-name"] = subscription.teamName; if (subscription.roleType <= Query.Models.RoleType.moderator) { var members = Query.TeamMembers.GetList(subscription.teamId).OrderBy(a => a.roleType).ThenBy(a => a.email).ToList(); if (members != null) { var memberItem = new Scaffold("/Views/Subscription/team/member-item.html"); var html = new StringBuilder(); if (members.Count > 0) { scaffold["total-members"] = members.Count.ToString(); foreach (var member in members) { memberItem.Bind(new { member = new { member.email, roletype = member.roleType.ToString(), member.name } }); html.Append(memberItem.Render()); } scaffold["members"] = html.ToString(); } } } if (scaffold["members"] == null) { scaffold["members"] = Server.LoadFileFromCache("/Views/Subscription/team/no-members.html"); } return(scaffold.Render()); } else { return(Error("Subscription does not exist")); } }
private string GetCampaigns(int subscriptionId, int start = 1, int length = 20, string search = "") { var subscription = Query.Subscriptions.GetInfo(subscriptionId); if (subscription != null) { var campaigns = Query.Campaigns.GetList(subscription.teamId, start, length, search); var scaffold = new Scaffold("/Views/Subscription/campaigns.html"); var item = new Scaffold("/Views/Subscription/campaigns/campaign-item.html"); scaffold["team-name"] = subscription.teamName; if (campaigns.Count > 0) { var html = new StringBuilder(); foreach (var campaign in campaigns) { item.Bind(new { campaign = new { campaign.campaignId, campaign.label, status = campaign.status == 0 ? "New" : campaign.status == 1 ? "Running" : campaign.status == 2 ? "Ended" : "Unknown", draftonly = campaign.draftsOnly == true ? "Drafts Only" : "Customer Emails", datecreated = campaign.datecreated.ToString("MM-dd-yyyy") } }); html.Append(item.Render()); } scaffold["campaigns"] = html.ToString(); } else { scaffold["campaigns"] = Server.LoadFileFromCache("/Views/Subscription/campaigns/no-campaigns.html"); } return(scaffold.Render()); } else { return(Error("Subscription does not exist")); } }
public string View() { //load partial view var scaffold = new Scaffold("/Views/Profile/profile.html"); //bind model scaffold.Bind(new Header() { User = new Models.Profile() { Name = User.name, Username = User.displayName, Image = User.photo ? "/content/users/" + User.userId + ".jpg" : "/images/nophoto.jpg" } }); //render partial view return(RenderContent(User.name, "icon-user", scaffold.Render())); }
private string GetAddressBook(int subscriptionId, int start = 1, int length = 50, Query.AddressBookEntries.SortList sort = Query.AddressBookEntries.SortList.email, string search = "") { var subscription = Query.Subscriptions.GetInfo(subscriptionId); if (subscription != null) { var addresses = Query.AddressBookEntries.GetList(subscription.teamId, start, length, sort, search); var scaffold = new Scaffold("/Views/Subscription/addressbook.html"); scaffold["team-name"] = subscription.teamName; //load svg icons scaffold["svg"] = Server.LoadFileFromCache("/Content/Icons/iconEdit.svg"); if (addresses != null) { var entryItem = new Scaffold("/Views/Subscription/addressbook/entry-item.html"); var html = new StringBuilder(); if (addresses.Count > 0) { foreach (var entry in addresses) { entryItem.Bind(new { entry }); html.Append(entryItem.Render()); } scaffold["entries"] = html.ToString(); } else { scaffold["entries"] = Server.LoadFileFromCache("/Views/Subscription/addressbook/no-entries.html"); } } else { scaffold["entries"] = Server.LoadFileFromCache("/Views/Subscription/addressbook/no-entries.html"); } return(scaffold.Render()); } else { return(Error("Subscription does not exist")); } }
public string Index(int page = 1, int length = 50, int sort = 0, string search = "") { if (!HasPermissions()) { return(Error()); } //get accessable subscriptions for user var subscriptions = Query.Subscriptions.GetSubscriptions(User.userId); var subscription = subscriptions.Where(a => a.userId == User.userId).FirstOrDefault(); if (subscription != null) { var entries = Query.AddressBookEntries.GetList(User.userId, page, length, (Query.AddressBookEntries.SortList)sort, search); var entryItem = new Scaffold("/Views/Subscription/addressbook/entry-item.html"); var html = new StringBuilder(); foreach (var entry in entries) { entryItem.Bind(new { entry = new { entry.addressId, entry.email, entry.firstname, entry.lastname } }); html.Append(entryItem.Render()); } return(JsonResponse(new { total = entries.Count.ToString(), html = html.ToString() })); } return(Error("You do not have permission to view address book entries")); }
public override string Render(string[] path, string body = "", object metadata = null) { //check security if (!CheckSecurity()) { return(AccessDenied(true, new Login(context))); } //set up client-side dependencies AddCSS("/css/views/dashboard/dashboard.css"); AddScript("js/views/dashboard/dashboard.js"); //load the dashboard layout var scaffold = new Scaffold("/Views/Dashboard/dashboard.html", Server.Scaffold); var menuitem = new Scaffold("/Views/Dashboard/menu-item.html", Server.Scaffold); //load UI scaffold.Bind(new Header() { User = new Models.Profile() { Name = User.name, Username = User.displayName, Image = User.photo ? "/content/users/" + User.userId + ".jpg" : "/images/nophoto.jpg" } }); //load Options Menu UI var menuItems = new List <OptionsMenuItem>() { new OptionsMenuItem() { Id = "find-friends", Href = "Find-Friends", Icon = "icon-user", Label = "Find Friends" }, new OptionsMenuItem() { Id = "browse-communities", Href = "Browse-Communities", Icon = "icon-communities", Label = "Browse Communities" }, new OptionsMenuItem() { Id = "subscriptions", Href = "Subscriptions", Icon = "icon-subscriptions", Label = "My Subscriptions" }, new OptionsMenuItem() { Id = "subscribers", Href = "Subscribers", Icon = "icon-subscribers", Label = "Subscribers" } }; var optionMenu = new StringBuilder(); foreach (var item in menuItems) { menuitem.Bind(item); optionMenu.Append(menuitem.Render()); } scaffold.Data["options-menu"] = optionMenu.ToString(); scaffold.Data["body"] = body; //render base layout along with dashboard section return(base.Render(path, scaffold.Render())); }
private string GetSettings(int subscriptionId) { var subscription = Query.Subscriptions.GetInfo(subscriptionId); if (subscription != null) { var plans = Query.Plans.GetList(); var plan = plans.Where(p => p.planId == subscription.planId).First(); var scaffold = new Scaffold("/Views/Subscription/settings.html"); scaffold.Bind(new { subscription = new { plan.name, price = (subscription.pricePerUser * subscription.totalUsers).ToString("C"), users = subscription.totalUsers, schedule = subscription.paySchedule == 0 ? "month" : "year", plural = subscription.totalUsers > 1 ? "s" : "", owner = subscription.ownerName } }); if (subscription.userId == User.userId) { //subscription belongs to user, show billing info & other options (upgrade, downgrade, cancel) var outstanding = Query.Subscriptions.GetOutstandingBalance(User.userId); var subscriptionAge = (DateTime.Now - subscription.datestarted).TotalMinutes; scaffold.Bind(new { outstanding = new { price = outstanding.totalOwed.ToString("C"), duedate = outstanding.duedate.Value.ToShortDateString(), when = outstanding.duedate.Value < DateTime.Now ? "was" : "will be" } }); scaffold.Show("is-outstanding"); scaffold.Show("can-cancel"); if (outstanding.duedate.Value < DateTime.Now) { scaffold.Show("is-overdue"); } if (subscription.paySchedule == Query.Models.PaySchedule.monthly) { scaffold.Show("is-monthly"); } if (subscription.planId >= 1) { //show modify option scaffold.Show("can-modify"); if (subscription.totalUsers > 1) { scaffold.Show("is-team"); } else { scaffold.Show("is-not-team"); } if (subscription.planId == 1) { scaffold.Show("no-downgrade"); } } if ((subscription.planId != 4 && subscription.planId != 8) || subscription.totalUsers < 10000) { //show modify option scaffold.Show("can-modify"); } if (subscriptionAge < (5 * 24) * 60) { //TODO: Check for existing campaigns that have been ran //subscription is less than 5 days old & no campaigns have been run, //allow user to cancel subscription with a full refund scaffold.Show("is-new"); } else { if (subscription.paySchedule == Query.Models.PaySchedule.yearly) { scaffold.Show("is-old-year"); //get total months since subscription start until today var months = (int)Math.Round(((TimeSpan)(DateTime.Now - subscription.datestarted)).Days / 30.0); //calculate the end date for a yearly subscription ending //at the end of this monthly billing cycle var subscriptionEnd = subscription.datestarted.AddMonths(months + 1); subscriptionEnd = new DateTime(subscriptionEnd.Year, subscriptionEnd.Month, subscriptionEnd.Day, 0, 0, 0); //reset time to midnight scaffold.Bind(new { cancellation = new { enddate = subscriptionEnd.ToShortDateString() } }); } else { scaffold.Show("is-old-month"); } } //load payment history var paymentItem = new Scaffold("/Views/Subscription/settings/payment-item.html"); var payments = Query.Payments.GetList(User.userId); var html = new StringBuilder(); foreach (var payment in payments) { paymentItem.Bind(new { payment = new { datecreated = payment.datepaid.ToString("yyyy/MM/dd h:mm tt"), amount = payment.payment.ToString("C") } }); html.Append(paymentItem.Render()); } scaffold["payments"] = html.ToString(); //load invoices var invoiceItem = new Scaffold("/Views/Subscription/settings/invoice-item.html"); var invoices = Query.Invoices.GetList(User.userId); html = new StringBuilder(); var duedate = outstanding.duedate; if (duedate.HasValue) { duedate = (new DateTime(duedate.Value.Year, duedate.Value.Month, duedate.Value.Day)).AddDays(-3); } foreach (var invoice in invoices) { var item = new { datecreated = invoice.datedue.ToString("yyyy/MM/dd"), amount = invoice.subtotal.ToString("C"), status = outstanding.unpaidInvoiceId.HasValue ? (outstanding.unpaidInvoiceId.Value <= invoice.invoiceId ? (duedate >= DateTime.Now ? "Overdue" : "Due") : "Paid" ) : "Paid" }; invoiceItem.Bind(new { invoice = item }); if (item.status == "Due" || item.status == "Overdue") { invoiceItem.Show("important"); } html.Append(invoiceItem.Render()); } scaffold["invoices"] = html.ToString(); //load subscription changes var historyItem = new Scaffold("/Views/Subscription/settings/history-item.html"); var subscriptions = Query.Subscriptions.GetHistory(User.userId); var team = Query.Teams.GetByOwner(User.userId); var members = Query.TeamMembers.GetList(team.teamId).OrderByDescending(o => o.datecreated); html = new StringBuilder(); var items = new List <HistoryItem>(); var historyItems = new List <HistoryElement>(); //add list of members to history foreach (var member in members) { items.Add(new HistoryItem() { member = member, dateCreated = new DateTime(member.datecreated.Year, member.datecreated.Month, member.datecreated.Day), type = 0 }); } //add list of subscriptions to history foreach (var sub in subscriptions) { items.Add(new HistoryItem() { subscription = sub, dateCreated = new DateTime(sub.datestarted.Year, sub.datestarted.Month, sub.datestarted.Day), type = 1 }); } //sort history items items = items.OrderByDescending(o => o.dateCreated).ThenBy(o => o.type).ToList(); //generate subscription changes var currItem = new HistoryElement(); var currPlanId = -99; var count = 0; var actionType = ""; foreach (var item in items) { count += 1; var date = item.dateCreated.ToString("yyyy/MM/dd"); if (currItem.datecreated != date || item.type != currItem.type || item.type == 1) { if (item.type != 0 && item.subscription.planId == currPlanId) { continue; } if (item.type != 0) { currPlanId = item.subscription.planId; } if (currItem.description != null) { historyItems.Add(currItem); } if (count == items.Count) { actionType = "Started Subscription with "; } else { actionType = "Changed Subscription to "; } currItem = new HistoryElement() { datecreated = date, description = item.type == 0 ? "Added Member" : actionType + Common.Plans.NameFromId(item.subscription.planId) + " plan", members = item.type == 0 ? "1" : "", type = item.type }; } else { if (item.type == 0) { currItem.description = "Added Members"; currItem.members = (int.Parse(currItem.members) + 1).ToString(); } } } if (currItem.description != null) { historyItems.Add(currItem); } foreach (var item in historyItems) { historyItem.Bind(new { history = item }); html.Append(historyItem.Render()); } scaffold["history"] = html.ToString(); } return(scaffold.Render()); } else { return(Error("Subscription does not exist")); } }