شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

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