public void SendAllEmails() { Log.Info("Running Summary Email Reports ..."); using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { List <SummaryEmail> emails = new TableOperations <SummaryEmail>(connection).QueryRecords().ToList(); emails.ForEach(item => { try { string xmlData = connection.ExecuteScalar <string>(item.DataSQL).Replace("&", "&").Replace(">", ">"); xmlData = xmlData.Replace("<", "<"); string htmlText = xmlData.ApplyXSLTransform(item.Template); XDocument htmlDocument = XDocument.Parse(htmlText, LoadOptions.PreserveWhitespace); htmlDocument.TransformAll("format", element => element.Format()); SendEmail(item.Subject, htmlDocument .ToString(SaveOptions.DisableFormatting) .Replace("&", "&") .Replace("<", "<") .Replace(">", ">")); Log.Info($"Sent email: {item.Subject}"); } catch (Exception ex) { Log.Error(ex.Message, ex); } }); } }
public IHttpActionResult Update(string id) { int xdaID = int.Parse(id); List <T> xdaObj = new List <T>(); try { using (AdoDataConnection connection = new AdoDataConnection(Connection)) { if (xdaID < 0) { xdaObj = (new TableOperations <T>(connection)).QueryRecords().ToList(); } else { if ((new TableOperations <T>(connection)).QueryRecordCountWhere("ID = {0}", xdaID) > 0) { xdaObj.Add((new TableOperations <T>(connection)).QueryRecordsWhere("ID = {0}", xdaID).First()); } } } } catch (Exception ex) { return(InternalServerError(ex)); } List <Model.ExternalDBField> result = new List <Model.ExternalDBField>(); List <Model.AdditionalField> fields = new List <Model.AdditionalField>(); List <Model.ExternalOpenXDAField> xdaFields = new List <Model.ExternalOpenXDAField>(); TableNameAttribute tableNameAttribute; string tableName; if (typeof(T).TryGetAttribute(out tableNameAttribute)) { tableName = tableNameAttribute.TableName; } else { tableName = typeof(T).Name; } try { using (AdoDataConnection connection = new AdoDataConnection(AdditionalFieldConnection)) { fields = new TableOperations <Model.AdditionalField>(connection).QueryRecordsWhere("ParentTable = {0} AND ExternalDB = {1}", tableName, extDBName).ToList(); xdaFields = new TableOperations <Model.ExternalOpenXDAField>(connection).QueryRecordsWhere("ParentTable = {0} AND ExternalDB = {1}", tableName, extDBName).ToList(); IEnumerable <IGrouping <string, Model.AdditionalField> > fieldGroups = fields.GroupBy(item => item.ExternalDBTable); IEnumerable <IGrouping <string, Model.ExternalOpenXDAField> > xdafieldGroups = xdaFields.GroupBy(item => item.ExternalDBTable); foreach (string tbl in fieldGroups.Select(item => item.Key).Union(xdafieldGroups.Select(item => item.Key))) { IGrouping <string, Model.AdditionalField> fieldgroup = fieldGroups.Where(item => item.Key == tbl).FirstOrDefault(); IGrouping <string, Model.ExternalOpenXDAField> xDAgroup = xdafieldGroups.Where(item => item.Key == tbl).FirstOrDefault(); foreach (T asset in xdaObj) { try { result = result.Concat(GetTable(tbl, new Tuple <IEnumerable <Model.AdditionalField>, IEnumerable <Model.ExternalOpenXDAField> >( (fieldgroup == null ? new List <Model.AdditionalField>() : fieldgroup.ToList()), (xDAgroup == null ? new List <Model.ExternalOpenXDAField>() : xDAgroup.ToList())), asset)).ToList(); } catch (Exception ex) { return(InternalServerError(ex)); } } } fields.ForEach(item => xdaObj.ForEach(asset => connection.ExecuteNonQuery("UPDATE AdditionalFieldValue SET [UpdatedOn] = sysdatetime() WHERE ParentTableID = {0} AND AdditionalFieldID = {1}", asset.GetType().GetProperty("ID").GetValue(asset), item.ID) ) ); } } catch (Exception ex) { return(InternalServerError(ex)); } return(Ok(result)); }