Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » ReportHistory

Public general use code classes and xml files that we've compiled and used over the years:

Report History support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Xml.Linq;
   3:  using System.IO;
   4:  using System.Data;
   5:  using System.Data.Entity;
   6:  using System.Collections.Generic;
   7:  using System.Reflection;
   8:  using System.Linq;
   9:  using System.Diagnostics;
  10:   
  11:  namespace Ia.Ngn.Cl.Model.Data
  12:  {
  13:      ////////////////////////////////////////////////////////////////////////////
  14:   
  15:      /// <summary publish="true">
  16:      /// Report History support class for Next Generation Network (NGN) data model.
  17:      /// </summary>
  18:      /// 
  19:      /// <remarks> 
  20:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  21:      ///
  22:      /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
  23:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  24:      ///
  25:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  26:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  27:      /// 
  28:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  29:      /// 
  30:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  31:      /// </remarks> 
  32:      public partial class ReportHistory
  33:      {
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public ReportHistory() { }
  40:   
  41:          ////////////////////////////////////////////////////////////////////////////
  42:   
  43:          /// <summary>
  44:          ///
  45:          /// </summary>
  46:          public static bool Create(Ia.Ngn.Cl.Model.ReportHistory reportHistory, out string result)
  47:          {
  48:              bool b;
  49:   
  50:              b = false;
  51:              result = "";
  52:   
  53:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  54:              {
  55:                  reportHistory.Report = (from r in db.Reports where r.Id == reportHistory.Report.Id select r).SingleOrDefault();
  56:   
  57:                  reportHistory.Created = reportHistory.Updated = DateTime.UtcNow.AddHours(3);
  58:   
  59:                  db.ReportHistories.Add(reportHistory);
  60:                  db.SaveChanges();
  61:   
  62:                  DbContextProbablyUpdated();
  63:   
  64:                  b = true;
  65:              }
  66:   
  67:              return b;
  68:          }
  69:   
  70:          ////////////////////////////////////////////////////////////////////////////
  71:   
  72:          /// <summary>
  73:          ///
  74:          /// </summary>
  75:          public static Ia.Ngn.Cl.Model.ReportHistory Read(int reportHistoryId)
  76:          {
  77:              Ia.Ngn.Cl.Model.ReportHistory reportHistory;
  78:   
  79:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  80:              {
  81:                  reportHistory = (from rh in db.ReportHistories where rh.Id == reportHistoryId select rh).Include(u => u.Report).Include(u => u.Report.ReportHistories).SingleOrDefault();
  82:              }
  83:   
  84:              return reportHistory;
  85:          }
  86:   
  87:          ////////////////////////////////////////////////////////////////////////////
  88:   
  89:          /// <summary>
  90:          ///
  91:          /// </summary>
  92:          public static List<Ia.Ngn.Cl.Model.ReportHistory> ReadListForReportId(int reportId)
  93:          {
  94:              List<Ia.Ngn.Cl.Model.ReportHistory> reportHistoryList;
  95:   
  96:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  97:              {
  98:                  reportHistoryList = (from rh in db.ReportHistories where rh.Report.Id == reportId select rh).Include(x => x.Report).Include(x => x.Report.ReportHistories).ToList();
  99:              }
 100:   
 101:              return reportHistoryList;
 102:          }
 103:   
 104:          ////////////////////////////////////////////////////////////////////////////
 105:   
 106:          /// <summary>
 107:          ///
 108:          /// </summary>
 109:          public static bool UpdateMigratedList(List<Ia.Ngn.Cl.Model.ReportHistory> reportHistoryList, out string result)
 110:          {
 111:              bool b;
 112:              Ia.Ngn.Cl.Model.ReportHistory reportHistory;
 113:   
 114:              b = false;
 115:              result = "";
 116:   
 117:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 118:              {
 119:                  foreach (Ia.Ngn.Cl.Model.ReportHistory updatedReportHistory in reportHistoryList)
 120:                  {
 121:                      reportHistory = (from rh in db.ReportHistories where rh.Id == updatedReportHistory.Id select rh).SingleOrDefault();
 122:   
 123:                      if (reportHistory == null)
 124:                      {
 125:                          //updatedReport.Created = updatedReport.Updated = DateTime.UtcNow.AddHours(3);
 126:   
 127:                          db.ReportHistories.Add(updatedReportHistory);
 128:                      }
 129:                      else
 130:                      {
 131:                          // below: copy values from updatedReport to report
 132:   
 133:                          reportHistory.UpdateMigrated(updatedReportHistory);
 134:   
 135:                          db.ReportHistories.Attach(reportHistory);
 136:   
 137:                          db.Entry(reportHistory).State = System.Data.Entity.EntityState.Modified;
 138:                      }
 139:   
 140:                      b = true;
 141:                  }
 142:   
 143:                  db.SaveChanges();
 144:   
 145:                  DbContextProbablyUpdated();
 146:   
 147:                  b = true;
 148:              }
 149:   
 150:              return b;
 151:          }
 152:   
 153:          ////////////////////////////////////////////////////////////////////////////
 154:   
 155:          /// <summary>
 156:          ///
 157:          /// </summary>
 158:          public static bool NullifyUserId(Guid userId, out int numberOfRecordsUpdated)
 159:          {
 160:              return MoveUserId(userId, Guid.Empty, out numberOfRecordsUpdated);
 161:          }
 162:   
 163:          ////////////////////////////////////////////////////////////////////////////
 164:   
 165:          /// <summary>
 166:          ///
 167:          /// </summary>
 168:          public static bool MoveUserId(Guid fromUserId, Guid toUserId, out int numberOfRecordsUpdated)
 169:          {
 170:              bool b;
 171:   
 172:              b = false;
 173:              numberOfRecordsUpdated = 0;
 174:   
 175:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 176:              {
 177:                  var query = (from rh in db.ReportHistories where rh.UserId == fromUserId select rh).ToList();
 178:   
 179:                  foreach (var v in query)
 180:                  {
 181:                      v.UserId = toUserId;
 182:                      numberOfRecordsUpdated++;
 183:                  }
 184:   
 185:                  db.SaveChanges();
 186:   
 187:                  DbContextProbablyUpdated();
 188:   
 189:                  b = true;
 190:              }
 191:   
 192:              return b;
 193:          }
 194:   
 195:          ////////////////////////////////////////////////////////////////////////////
 196:   
 197:          /// <summary>
 198:          ///
 199:          /// </summary>
 200:          public static bool Delete(int id/*, out string result*/)
 201:          {
 202:              bool b;
 203:   
 204:              b = false;
 205:              //result = "";
 206:   
 207:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 208:              {
 209:                  var v = (from rh in db.ReportHistories where rh.Id == id select rh).FirstOrDefault();
 210:   
 211:                  db.ReportHistories.Remove(v);
 212:                  db.SaveChanges();
 213:   
 214:                  DbContextProbablyUpdated();
 215:   
 216:                  b = true;
 217:              }
 218:   
 219:              return b;
 220:          }
 221:   
 222:          ////////////////////////////////////////////////////////////////////////////
 223:   
 224:          /// <summary>
 225:          /// When a report history is updated I will reset local lists to null, and reset the report lists to null, to generate new list
 226:          /// </summary>
 227:          private static void DbContextProbablyUpdated()
 228:          {
 229:              //openStatusOrClosedStatusWithinLast24HourReportList = null;
 230:   
 231:              Ia.Ngn.Cl.Model.Data.Report.DbContextProbablyUpdated();
 232:          }
 233:   
 234:          ////////////////////////////////////////////////////////////////////////////
 235:          ////////////////////////////////////////////////////////////////////////////
 236:      }
 237:   
 238:      ////////////////////////////////////////////////////////////////////////////
 239:      ////////////////////////////////////////////////////////////////////////////   
 240:  }