using System; using System.Collections.Generic; using System.Linq; using Neo.Afx.ComponentModel; namespace Neo.Afx.Admin.Crm { /// /// Afx admin database /// public class AfxAdminCrmDatabase : Database { /// /// Constructor /// public AfxAdminCrmDatabase() : base(new AfxAdminCrmContext()) { } /// /// Get list of messages from the crm.Messages table /// ///Top number of rows to be returned. ///List of messages public IEnumerable GetMessages(int? count) { if(count.HasValue) { return (from m in Context.Messages orderby m.MessageID descending select m).Take(count.Value).ToList(); } return (from m in Context.Messages orderby m.MessageID descending select m).ToList(); } #region GetQueryTypes /// /// Get all data from table. /// /// List of objects public IEnumerable GetQueryTypes() { return (from item in Context.QueryTypes where !item.IsCancelled select item).ToList(); } /// /// Get data from table based on count. /// /// Restricts amount returned items in the collection. /// List of objects. public IEnumerable GetQueryTypes(int count) { return (from item in Context.QueryTypes where !item.IsCancelled select item).Take(count).ToList(); } #endregion #region GetQueryStatus /// /// Get all data from table. /// /// List of objects public IEnumerable GetQueryStatus() { return (from item in Context.QueryStatus where !item.IsCancelled select item).ToList(); } /// /// Get data from table based on count. /// /// Restricts amount returned items in the collection. /// List of objects. public IEnumerable GetQueryStatus(int count) { return (from item in Context.QueryStatus where !item.IsCancelled select item).Take(count).ToList(); } #endregion #region GetQuerySources /// /// Get all data from table. /// /// List of objects public IEnumerable GetQuerySources() { return (from item in Context.QuerySources where !item.IsCancelled select item).ToList(); } /// /// Get data from table based on count. /// /// Restricts amount returned items in the collection. /// List of objects. public IEnumerable GetQuerySources(int count) { return (from item in Context.QuerySources where !item.IsCancelled select item).Take(count).ToList(); } #endregion /// /// Searches Messages Table and return a collection of matching results /// /// The Entity /// The Item /// The Sender /// The Recipients /// Is the Message HTML /// Who Created the Message /// The Start Date to search from /// The End Date to search up untill /// public IEnumerable SearchMessages(short entityID, long itemID, string sender, string recipients, bool? isHtml, long createdByID, DateTime startDate, DateTime endDate) { return Context.Pr_MessageSearch(entityID, itemID, sender, recipients, isHtml, startDate, endDate).ToList(); } /// /// Messages the template HTML tester. /// /// The entity ID. /// The item ID. /// The message template ID. /// public MessageTemplate MessageTemplateHtmlTester(short entityID, long itemID, long messageTemplateID) { return Context.Pr_MessageTemplateTester(entityID, itemID, messageTemplateID).FirstOrDefault(); } /// /// Messages the template SQL tester. /// /// The message template ID. /// public IEnumerable MessageTemplateSqlTester(long messageTemplateID) { return Context.Pr_MessageTemplateSqlTester(messageTemplateID); } } }