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

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 Microsoft.EntityFrameworkCore;
   2:  using System;
   3:  using System.Collections.Generic;
   4:  using System.Data;
   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), Integrated 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 
  78:                                   where rh.Id == reportHistoryId 
  79:                                   select rh).Include(u => u.Report).ThenInclude(u => u.ReportHistories).SingleOrDefault();
  80:              }
  81:   
  82:              return reportHistory;
  83:          }
  84:   
  85:          ////////////////////////////////////////////////////////////////////////////
  86:   
  87:          /// <summary>
  88:          ///
  89:          /// </summary>
  90:          public static List<Ia.Ngn.Cl.Model.ReportHistory> ReadListForReportId(int reportId)
  91:          {
  92:              List<Ia.Ngn.Cl.Model.ReportHistory> reportHistoryList;
  93:   
  94:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  95:              {
  96:                  reportHistoryList = (from rh in db.ReportHistories 
  97:                                       where rh.Report.Id == reportId 
  98:                                       select rh).Include(u => u.Report).ThenInclude(u => u.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 = string.Empty;
 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
 122:                                       where rh.Id == updatedReportHistory.Id
 123:                                       select rh).Include(u => u.Report).ThenInclude(u => u.ReportHistories).SingleOrDefault();
 124:   
 125:                      if (reportHistory == null)
 126:                      {
 127:                          //updatedReport.Created = updatedReport.Updated = DateTime.UtcNow.AddHours(3);
 128:   
 129:                          db.ReportHistories.Add(updatedReportHistory);
 130:                      }
 131:                      else
 132:                      {
 133:                          // below: copy values from updatedReport to report
 134:   
 135:                          reportHistory.UpdateMigrated(updatedReportHistory);
 136:   
 137:                          db.ReportHistories.Attach(reportHistory);
 138:   
 139:                          db.Entry(reportHistory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
 140:                      }
 141:   
 142:                      b = true;
 143:                  }
 144:   
 145:                  db.SaveChanges();
 146:   
 147:                  DbContextProbablyUpdated();
 148:   
 149:                  b = true;
 150:              }
 151:   
 152:              return b;
 153:          }
 154:   
 155:          ////////////////////////////////////////////////////////////////////////////
 156:   
 157:          /// <summary>
 158:          ///
 159:          /// </summary>
 160:          public static bool NullifyUserId(Guid userId, out int numberOfRecordsUpdated)
 161:          {
 162:              return MoveUserId(userId, Guid.Empty, out numberOfRecordsUpdated);
 163:          }
 164:   
 165:          ////////////////////////////////////////////////////////////////////////////
 166:   
 167:          /// <summary>
 168:          ///
 169:          /// </summary>
 170:          public static bool MoveUserId(Guid fromUserId, Guid toUserId, out int numberOfRecordsUpdated)
 171:          {
 172:              bool b;
 173:   
 174:              b = false;
 175:              numberOfRecordsUpdated = 0;
 176:   
 177:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 178:              {
 179:                  var query = (from rh in db.ReportHistories where rh.UserId == fromUserId select rh).ToList();
 180:   
 181:                  foreach (var v in query)
 182:                  {
 183:                      v.UserId = toUserId;
 184:                      numberOfRecordsUpdated++;
 185:                  }
 186:   
 187:                  db.SaveChanges();
 188:   
 189:                  DbContextProbablyUpdated();
 190:   
 191:                  b = true;
 192:              }
 193:   
 194:              return b;
 195:          }
 196:   
 197:          ////////////////////////////////////////////////////////////////////////////
 198:   
 199:          /// <summary>
 200:          ///
 201:          /// </summary>
 202:          public static bool Delete(int id/*, out string result*/)
 203:          {
 204:              bool b;
 205:   
 206:              b = false;
 207:              //result = string.Empty;
 208:   
 209:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 210:              {
 211:                  var v = (from rh in db.ReportHistories where rh.Id == id select rh).FirstOrDefault();
 212:   
 213:                  db.ReportHistories.Remove(v);
 214:                  db.SaveChanges();
 215:   
 216:                  DbContextProbablyUpdated();
 217:   
 218:                  b = true;
 219:              }
 220:   
 221:              return b;
 222:          }
 223:   
 224:          ////////////////////////////////////////////////////////////////////////////
 225:   
 226:          /// <summary>
 227:          /// When a report history is updated I will reset local lists to null, and reset the report lists to null, to generate new list
 228:          /// </summary>
 229:          private static void DbContextProbablyUpdated()
 230:          {
 231:              //openStatusOrClosedStatusWithinLast24HourReportList = null;
 232:   
 233:              Ia.Ngn.Cl.Model.Data.Report.OpenStatusOrClosedWithinLast24HourAndResponsibilityAndReadabilityReportListClear();
 234:          }
 235:   
 236:          ////////////////////////////////////////////////////////////////////////////
 237:          ////////////////////////////////////////////////////////////////////////////
 238:      }
 239:   
 240:      ////////////////////////////////////////////////////////////////////////////
 241:      ////////////////////////////////////////////////////////////////////////////   
 242:  }