public ContactListModule() { this.RequiresAuthentication(); Get["/contact/list"] = parameters => { return(View["View/contactlist.sshtml", new ContactListViewModel(Database, Translator, CurrentSession)]); }; Get["/contact/list/settings/list"] = parameters => { var settingsList = Database .Query <SearchSettings>(DC.Equal("userid", CurrentSession.User.Id.Value)) .ToList(); var result = new JArray(); if (!settingsList.Any()) { var settings = new SearchSettings(Guid.NewGuid()); settings.User.Value = CurrentSession.User; settings.Name.Value = Translate("Contact.List.Settings.DefaultName", "Default name for new search settings", "Default"); Database.Save(settings); settingsList.Add(settings); } foreach (var settings in settingsList) { result.Add( new JObject( new JProperty("Id", settings.Id.Value), new JProperty("Name", settings.Name.Value))); } return(result.ToString()); }; Get["/contact/list/settings/get/{ssid}"] = parameters => { string searchSettingsId = parameters.ssid; var settings = Database.Query <SearchSettings>(searchSettingsId); if (settings == null || settings.User.Value != CurrentSession.User) { return(null); } var update = new SearchSettingsUpdate(settings); return(JsonConvert.SerializeObject(update).ToString()); }; Post["/contact/list/settings/set/{ssid}"] = parameters => { var update = JsonConvert.DeserializeObject <SearchSettingsUpdate>(ReadBody()); string searchSettingsId = parameters.ssid; var settings = Database.Query <SearchSettings>(searchSettingsId); var status = CreateStatus(); if (settings == null) { settings = new SearchSettings(Guid.NewGuid()); settings.User.Value = CurrentSession.User; } else if (settings.User.Value != CurrentSession.User) { status.SetErrorAccessDenied(); } update.Apply(Database, settings); Database.Save(settings); return(status.CreateJsonData()); }; Get["/contact/list/data/{ssid}"] = parameters => { string searchSettingsId = parameters.ssid; var settings = Database.Query <SearchSettings>(searchSettingsId); if (settings == null) { return(null); } var contacts = Database.Query <Contact>() .Where(c => Filter(c, settings)); var skip = settings.ItemsPerPage * settings.CurrentPage; if (skip > contacts.Count()) { skip = 0; } var page = contacts .OrderBy(c => c.SortName) .Skip(skip) .Take(settings.ItemsPerPage); return(View["View/contactlist_data.sshtml", new ContactListDataViewModel(Database, Translator, page, settings, CurrentSession)]); }; Get["/contact/list/pages/{ssid}"] = parameters => { string searchSettingsId = parameters.ssid; var settings = Database.Query <SearchSettings>(searchSettingsId); if (settings == null) { return(null); } var personCount = Database.Query <Contact>() .Count(c => Filter(c, settings)); var itemsPerPage = Math.Max(1, settings.ItemsPerPage.Value); var pageCount = Math.Max(1, (personCount / itemsPerPage) + Math.Min(personCount % itemsPerPage, 1)); if (settings.CurrentPage.Value >= pageCount) { settings.CurrentPage.Value = 0; Database.Save(settings); } return(View["View/contactlist_pages.sshtml", new ContactPagesViewModel(Translator, pageCount, settings)]); }; }
public ContactDetailJournalViewModel(Translator translator, IDatabase database, Session session, Contact contact) { Id = contact.Id.Value.ToString(); List = new List <ContactDetailJournalItemViewModel>(database .Query <JournalEntry>(DC.Equal("contactid", contact.Id.Value)) .OrderByDescending(d => d.Moment.Value) .Select(d => new ContactDetailJournalItemViewModel(translator, d))); PhraseHeaderMoment = translator.Get("Contact.Detail.Journal.Header.Moment", "Column 'Moment' on the journal tab of the contact detail page", "When").EscapeHtml(); PhraseHeaderSubject = translator.Get("Contact.Detail.Journal.Header.Subject", "Column 'Subject' on the journal tab of the contact detail page", "Who").EscapeHtml(); PhraseHeaderText = translator.Get("Contact.Detail.Journal.Header.Text", "Column 'Text' on the journal tab of the contact detail page", "What").EscapeHtml(); }
public MailingScheduledViewModel(Translator translator, IDatabase db, Session session, Mailing mailing) : this(translator, session) { Id = mailing.Id.Value.ToString(); Title = mailing.Title.Value.EscapeHtml(); Recipients = mailing.RecipientFeed.Value.Name.Value[translator.Language]; if (mailing.RecipientTag.Value != null) { Recipients = " / " + mailing.RecipientTag.Value.Name.Value[translator.Language]; } if (mailing.RecipientLanguage.Value.HasValue) { Recipients = " / " + mailing.RecipientLanguage.Value.Value.Translate(translator); } var number = db .Query <Contact>() .Count(p => p.ActiveSubscriptions.Any(m => m.Feed == mailing.RecipientFeed.Value) && (mailing.RecipientTag.Value == null || p.TagAssignments.Any(t => t.Tag == mailing.RecipientTag.Value))); Recipients += " / " + translator.Get("Mailing.Scheduled.Fields.Recipients.Contacts", "Contacts in the recipients field on the scheduled mailing page", "circa {0} contacts", number); Subject = mailing.Subject.Value.EscapeHtml(); var sendingDate = mailing.SendingDate.Value.HasValue ? mailing.SendingDate.Value.Value.ToLocalTime().ToString("dd.MM.yyyy HH:mm") : string.Empty; var sentDate = mailing.SentDate.Value.HasValue ? mailing.SentDate.Value.Value.ToLocalTime().ToString("dd.MM.yyyy HH:mm") : string.Empty; switch (mailing.Status.Value) { case MailingStatus.Scheduled: Status = translator.Get("Mailing.Scheduled.Field.Status.Scheduled", "Scheduled status in the status field the scheduled mailing page", "Scheduled for {0}", sendingDate).EscapeHtml(); break; case MailingStatus.Sending: Status = translator.Get("Mailing.Scheduled.Field.Status.Sending", "Sending status in the status field the scheduled mailing page", "Sending since {0}", sendingDate).EscapeHtml(); break; case MailingStatus.Sent: Status = translator.Get("Mailing.Scheduled.Field.Status.Sent", "Sent status in the status field the scheduled mailing page", "Sent at {0}", sentDate).EscapeHtml(); break; case MailingStatus.Canceled: Status = translator.Get("Mailing.Scheduled.Field.Status.Canceled", "Canceled status in the status field the scheduled mailing page", "Canceled").EscapeHtml(); break; default: throw new NotSupportedException(); } Sendings = new List <MailingSendingViewModel>(db .Query <Sending>(DC.Equal("mailingid", mailing.Id.Value)) .Select(s => new MailingSendingViewModel(translator, s))); Cancelable = mailing.Status.Value == MailingStatus.Scheduled || mailing.Status.Value == MailingStatus.Sending; }