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

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Authority

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

Authority support class of Optical Fiber Network (OFN) business model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Data;
   4:  using System.Linq;
   5:  using System.Web.Security;
   6:   
   7:  namespace Ia.Ngn.Cl.Model.Business
   8:  {
   9:      ////////////////////////////////////////////////////////////////////////////
  10:   
  11:      /// <summary publish="true">
  12:      /// Authority support class of Optical Fiber Network (OFN) business model.
  13:      /// </summary>
  14:      /// 
  15:      /// <remarks> 
  16:      /// Copyright © 2006-2020 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 class Authority
  29:      {
  30:          public enum SchedularFunction
  31:          {
  32:              ListOfPreviouslyPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport = 1,
  33:              ListOfPreviouslyQrnPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  34:              ListOfPreviouslyJblPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  35:              ListOfPreviouslySsbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  36:              ListOfPreviouslySlmaPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  37:              ListOfPreviouslySlmbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  38:              ListOfPreviouslyMsfPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  39:              ListOfPreviouslyFhhPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
  40:              StatusReport,
  41:              StatisticsReport,
  42:              NokiaReport,
  43:              HuaweiReport,
  44:              Maintenance,
  45:              Heartbeat,
  46:          };
  47:   
  48:          public enum PersistentStorageFunction { Create = 1, Read, Update, Delete };
  49:   
  50:          /// <summary/>
  51:          public int Id { get; set; }
  52:   
  53:          /// <summary/>
  54:          public string Name { get; set; }
  55:   
  56:          /// <summary/>
  57:          public string ArabicName { get; set; }
  58:   
  59:          /// <summary/>
  60:          public string AllowedFrameworkArabicName { get; set; }
  61:   
  62:          /// <summary/>
  63:          public bool HeadOnly { get; set; }
  64:   
  65:          /// <summary/>
  66:          public string Medium { get; set; }
  67:   
  68:          /// <summary/>
  69:          public string System { get; set; }
  70:   
  71:          /// <summary/>
  72:          public string Process { get; set; }
  73:   
  74:          /// <summary/>
  75:          public string Function { get; set; }
  76:   
  77:          /// <summary/>
  78:          public string ParameterRegex { get; set; }
  79:   
  80:          /// <summary/>
  81:          public string ResponseRegex { get; set; }
  82:   
  83:          /// <summary/>
  84:          public string Help { get; set; }
  85:   
  86:          ////////////////////////////////////////////////////////////////////////////
  87:   
  88:          /// <summary>
  89:          ///
  90:          /// </summary>
  91:          public Authority() { }
  92:   
  93:          ////////////////////////////////////////////////////////////////////////////    
  94:   
  95:          /// <summary>
  96:          ///
  97:          /// </summary>
  98:          public int AuthorityId(int parentId, int authorityId)
  99:          {
 100:              return parentId * 10 + authorityId;
 101:          }
 102:   
 103:          ////////////////////////////////////////////////////////////////////////////    
 104:   
 105:          /// <summary>
 106:          ///
 107:          /// </summary>
 108:          public int ParentId(long authorityId)
 109:          {
 110:              int i;
 111:              string s;
 112:   
 113:              s = authorityId.ToString();
 114:   
 115:              if (s.Length > 2)
 116:              {
 117:                  s = s.Substring(0, s.Length - 2);
 118:   
 119:                  i = (int.TryParse(s, out i)) ? i : 0;
 120:              }
 121:              else i = 0;
 122:   
 123:              return i;
 124:          }
 125:   
 126:          ////////////////////////////////////////////////////////////////////////////    
 127:   
 128:          /// <summary>
 129:          ///
 130:          /// </summary>
 131:          public static List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework> StaffFrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 132:          {
 133:              List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework> frameworkList, specialList, special2List, special3List, special4List, list;
 134:   
 135:              var staffList = new List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework>();
 136:              var staffHead = new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework();
 137:   
 138:              if (staff.Head != null) staffHead = new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 139:              {
 140:                  Guid = staff.Head.UserId,
 141:                  IsStaff = true,
 142:                  Name = staff.Head.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 143:              };
 144:   
 145:              var subordinatesList = (from s in staff.Subordinates
 146:                                      select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 147:                                      {
 148:                                          Guid = s.UserId,
 149:                                          IsStaff = true,
 150:                                          Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 151:                                      }).ToList();
 152:   
 153:              var colleagueList = (from s in staff.Colleagues
 154:                                   select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 155:                                   {
 156:                                       Guid = s.UserId,
 157:                                       IsStaff = true,
 158:                                       Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 159:                                   }).ToList();
 160:   
 161:              staffList.Add(staffHead);
 162:              staffList = staffList.Union(subordinatesList).Union(colleagueList).ToList();
 163:   
 164:   
 165:              // framework list: framework descendants, siblings and uncles (for head staff only)
 166:              if (staff.Framework.Parent != null)
 167:              {
 168:                  if (staff.IsHead)
 169:                  {
 170:                      frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Union(staff.Framework.Parent.Siblings).Concat(new[] { staff.Framework.Parent })
 171:                                       select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 172:                                       {
 173:                                           Guid = f.Guid,
 174:                                           IsFramework = true,
 175:                                           Name = f.FullyQualifiedArabicName //.ArabicName
 176:                                       }
 177:                                       ).OrderBy(c => c.Guid).ToList();
 178:                  }
 179:                  else
 180:                  {
 181:                      frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Concat(new[] { staff.Framework.Parent })
 182:                                       select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 183:                                       {
 184:                                           Guid = f.Guid,
 185:                                           IsFramework = true,
 186:                                           Name = f.FullyQualifiedArabicName //.ArabicName
 187:                                       }
 188:                                       ).OrderBy(c => c.Guid).ToList();
 189:                  }
 190:              }
 191:              else
 192:              {
 193:                  frameworkList = (from f in staff.Framework.Descendants
 194:                                   select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 195:                                   {
 196:                                       Guid = f.Guid,
 197:                                       IsFramework = true,
 198:                                       Name = f.FullyQualifiedArabicName //.ArabicName
 199:                                   }
 200:                                   ).OrderBy(c => c.Guid).ToList();
 201:              }
 202:   
 203:              // special list: list of special administrative assignments to certain staff and frameworks
 204:              if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة" || staff.Framework.ArabicName == "قسم تشغيل الخدمات")
 205:              {
 206:                  specialList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 207:                                 where
 208:                                 f.FullyQualifiedArabicName == "وزارة الإتصالات وتكنولوجيا المعلومات | قطاع الاتصالات والخدمات المساندة | إدارة صيانة الشبكة الهاتفية | مراقبة الصيانة | قسم الصيانة"
 209:                                 || f.FullyQualifiedArabicName == "نوكيا"
 210:                                 || f.FullyQualifiedArabicName == "هواوي"
 211:                                 || f.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع الاتصالات والخدمات المساندة | إدارة شبكة الألياف الضوئية")
 212:                                 || (f.FullyQualifiedArabicName.Contains("قسم الصيانة وتركيبات الهاتف") && f.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع خدمات المشتركين"))
 213:                                 || (f.FullyQualifiedArabicName.Contains("قسم الفحص والشكاوى") && f.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع خدمات المشتركين"))
 214:                                 select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 215:                                 {
 216:                                     Guid = f.Guid,
 217:                                     IsFramework = true,
 218:                                     Name = f.FullyQualifiedArabicName //.ArabicName
 219:                                 }
 220:                                       ).OrderBy(c => c.Guid).ToList();
 221:              }
 222:              else if (staff.Framework.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع خدمات المشتركين"))
 223:              {
 224:                  // قطاع خدمات المشتركين need to assign to قسم الدعم الفني للشبك
 225:                  specialList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 226:                                 where f.ArabicName == "قسم الدعم الفني للشبكة" || f.ArabicName == "قسم تشغيل الخدمات"
 227:                                 select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 228:                                 {
 229:                                     Guid = f.Guid,
 230:                                     IsFramework = true,
 231:                                     Name = f.FullyQualifiedArabicName //.ArabicName
 232:                                 }
 233:                                       ).OrderBy(c => c.Guid).ToList();
 234:              }
 235:              else
 236:              {
 237:                  specialList = new List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework>();
 238:              }
 239:   
 240:              // special: ability to assign to report creator
 241:              special2List = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 242:                              join s in Ia.Ngn.Cl.Model.Data.Staff.List on f.Id equals s.Framework.Id
 243:                              where s.UserId == report.UserId
 244:                              select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 245:                              {
 246:                                  Guid = f.Guid,
 247:                                  IsFramework = true,
 248:                                  Name = f.FullyQualifiedArabicName //.ArabicName
 249:                              }
 250:                                   ).OrderBy(c => c.Guid).ToList();
 251:   
 252:              // list of all staff members already report history excluding self
 253:              if (report.ReportHistories != null && report.ReportHistories.Count > 0)
 254:              {
 255:                  special3List = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 256:                                  where (report.ReportHistories.Any(u => u.UserId == s.UserId)) && staff.UserId != s.UserId
 257:                                  select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 258:                                  {
 259:                                      Guid = s.UserId,
 260:                                      IsStaff = true,
 261:                                      Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 262:                                  }
 263:                                       ).OrderBy(c => c.Guid).ToList();
 264:              }
 265:              else
 266:              {
 267:                  special3List = new List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework>();
 268:              }
 269:   
 270:              // list of staff member who created report excluding self
 271:              special4List = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 272:                              where report.UserId == s.UserId && staff.UserId != s.UserId
 273:                              select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 274:                              {
 275:                                  Guid = s.UserId,
 276:                                  IsStaff = true,
 277:                                  Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 278:                              }
 279:                                   ).OrderBy(c => c.Guid).ToList();
 280:   
 281:              list = staffList.Union(frameworkList).Union(specialList).Union(special2List).Union(special3List).Union(special4List).ToList();
 282:   
 283:              list = list.GroupBy(u => u.Guid).Select(u => u.FirstOrDefault()).ToList(); // returns distinct records
 284:   
 285:              list = list.Where(u => u.Guid != Guid.Empty).ToList();
 286:   
 287:              return list.OrderBy(c => c.IsFramework).ToList();
 288:          }
 289:   
 290:          ////////////////////////////////////////////////////////////////////////////    
 291:   
 292:          /// <summary>
 293:          ///
 294:          /// </summary>
 295:          public static bool StaffCanCreateReadUpdateDeleteReport(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 296:          {
 297:              bool isAllowed;
 298:   
 299:              if (staff != null)
 300:              {
 301:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 302:                  else
 303:                  {
 304:                      if (persistentStorageFunction == PersistentStorageFunction.Delete)
 305:                      {
 306:                          /*
 307:                          // below: a report can only be deleted by:
 308:                          // - one of the heads of the reporter.
 309:                          // - the reporter if he is a head
 310:  
 311:                          if (report.LastReportHistory == null && staff.UserId == report.UserId && staff.IsHead) isAllowed = true;
 312:                          else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId && staff.IsHead) isAllowed = true;
 313:                          else if (report.LastReportHistory == null && staff.IsHead) isAllowed = true;
 314:                          else if (staff.Subordinates != null)
 315:                          {
 316:                              if (report.LastReportHistory != null) isAllowed = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 317:                              else isAllowed = staff.Subordinates.Any(i => i.UserId == report.UserId);
 318:                          }
 319:                          else isAllowed = false;
 320:                          */
 321:   
 322:                          isAllowed = false; // reports can't be deleted by staff other than super user
 323:                      }
 324:                      else
 325:                      {
 326:                          /*
 327:                          // below: a report can be CRUD if
 328:                          // - last report does not exist
 329:                          // - last report exists and its UserId is same as staffs
 330:                          // - report owner is subordinate of staff
 331:                          // - report framework is within users frameworks
 332:  
 333:                          if (report.ReportHistories.Count == 0)
 334:                          {
 335:                              isAllowed = report.LastReportHistory.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 336:  
 337:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId))
 338:                              {
 339:                                  isAllowed = staff.Framework.Guid == report.LastReportHistory.UserId
 340:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.LastReportHistory.UserId);
 341:                              }
 342:                          }
 343:                          else
 344:                          {
 345:                              isAllowed = true; // report.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.UserId);
 346:  
 347:                              / *
 348:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId))
 349:                              {
 350:                                  isAllowed = staff.Framework.Guid == report.UserId 
 351:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.UserId);
 352:                              }
 353:                               * /
 354:                          }
 355:                          */
 356:   
 357:                          isAllowed = false; // undefined CRU
 358:                      }
 359:                  }
 360:              }
 361:              else isAllowed = false;
 362:   
 363:              return isAllowed;
 364:          }
 365:   
 366:          ////////////////////////////////////////////////////////////////////////////    
 367:   
 368:          /// <summary>
 369:          ///
 370:          /// </summary>
 371:          public static bool StaffCanSendFieldTnmdSupplierWorkorderEmail(Ia.Ngn.Cl.Model.Staff staff)
 372:          {
 373:              bool isAllowed;
 374:   
 375:              if (staff != null)
 376:              {
 377:                  if (staff.IsHead) isAllowed = true;
 378:                  else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 379:                  else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 380:                  else isAllowed = false;
 381:              }
 382:              else isAllowed = false;
 383:   
 384:              return isAllowed;
 385:          }
 386:   
 387:          ////////////////////////////////////////////////////////////////////////////    
 388:   
 389:          /// <summary>
 390:          ///
 391:          /// </summary>
 392:          public static bool StaffCanCreateReadUpdateDeleteReportHistory(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.ReportHistory reportHistory, Ia.Ngn.Cl.Model.Staff staff)
 393:          {
 394:              // below: I have to pass both Report and ReportHistory objects separately
 395:   
 396:              bool isAllowed;
 397:   
 398:              if (staff != null)
 399:              {
 400:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 401:                  else
 402:                  {
 403:                      if (function == PersistentStorageFunction.Delete)
 404:                      {
 405:                          // below: a report history can only be deleted by:
 406:                          // - one of the heads of the history user
 407:                          // - the history user if he is a head
 408:   
 409:                          /*
 410:                          if (reportHistory != null)
 411:                          {
 412:                              if (reportHistory.Report.ReportHistories.Max(r => r.Id) != reportHistory.Id) isAllowed = false;
 413:                              else
 414:                              {
 415:                                  if (staff.UserId == reportHistory.UserId && staff.IsHead) isAllowed = true;
 416:                                  else if (staff.Subordinates != null) isAllowed = staff.Subordinates.Any(i => i.UserId == reportHistory.UserId);
 417:                                  else isAllowed = false;
 418:                              }
 419:                          }
 420:                          else isAllowed = false;
 421:                          */
 422:   
 423:                          isAllowed = false; // report history can't be deleted by staff other than super user
 424:                      }
 425:                      else if (function == PersistentStorageFunction.Create)
 426:                      {
 427:                          // below: for create reportHistory must be null
 428:   
 429:                          // below: a report history can be created if:
 430:                          // - report userid is subordinate of staff
 431:                          // - report history userid framework is within staff frameworks
 432:   
 433:                          if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 434:                          else if (staff.IsHead && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 435:                          else if (report != null && reportHistory == null)
 436:                          {
 437:                              if (report.ReportHistories.Count == 0 && staff.UserId == report.UserId) isAllowed = true;
 438:                              else if (report.ReportHistories.Count == 0 && report.StatusIsOpen) isAllowed = true;
 439:   
 440:                              //else if (report.LastReportHistory != null && !staff.Colleagues.Any(r => r.UserId == report.LastReportHistory.UserId) && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
 441:   
 442:                              else if (report.LastReportHistory != null && staff.SubordinatesOrSelf.Any(i => i.UserId == report.LastReportHistory.UserId)) isAllowed = true;
 443:                              else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId) && staff.Framework.DescendantsOrSelf.Any(u => u.Guid == report.UserId)) isAllowed = true;
 444:                              else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId) && report.LastReportHistory != null && (staff.Framework.DescendantsOrSelf.Any(u => u.Guid == report.LastReportHistory.UserId) || staff.Framework.Ancestors.Any(u => u.Guid == report.LastReportHistory.UserId))) isAllowed = true;
 445:                              else isAllowed = false;
 446:                          }
 447:                          else isAllowed = false;
 448:                      }
 449:                      else
 450:                      {
 451:                          // below: a report history can be read, and updated if:
 452:                          // - report history UserId is same as staff's
 453:                          // - report userid is subordinate of staff
 454:                          // - report history userid framework is within staff frameworks
 455:   
 456:                          if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 457:                          else if (staff.IsHead && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 458:                          else if (reportHistory != null)
 459:                          {
 460:                              if (staff.UserId == reportHistory.UserId) isAllowed = true;
 461:                              else if (staff.Subordinates.Any(u => u.UserId == reportHistory.UserId)) isAllowed = true;
 462:                              else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(reportHistory.UserId))
 463:                              {
 464:                                  if (staff.Framework.DescendantsOrSelf.Any(u => u.Guid == reportHistory.UserId)) isAllowed = true;
 465:                                  else isAllowed = false;
 466:                              }
 467:                              else isAllowed = false;
 468:                          }
 469:                          else isAllowed = false;
 470:                      }
 471:                  }
 472:              }
 473:              else isAllowed = false;
 474:   
 475:              return isAllowed;
 476:          }
 477:   
 478:          ////////////////////////////////////////////////////////////////////////////    
 479:   
 480:          /// <summary>
 481:          ///
 482:          /// </summary>
 483:          public static bool StaffCanReopenClosedReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 484:          {
 485:              return StaffCanCloseReport(report, staff);
 486:          }
 487:   
 488:          ////////////////////////////////////////////////////////////////////////////    
 489:   
 490:          /// <summary>
 491:          ///
 492:          /// </summary>
 493:          public static bool StaffCanCloseReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 494:          {
 495:              bool canClose;
 496:   
 497:              if (staff != null)
 498:              {
 499:                  if (StaffIsSuperUser(staff)) canClose = true;
 500:                  //else if (FrameworkCanCloseReport(staff.Framework)) canClose = true; // make dedicated users to check with subscribers if reports are resolved
 501:                  else
 502:                  {
 503:                      if (report.LastReportHistory != null)
 504:                      {
 505:                          if (staff.IsHead)
 506:                          {
 507:                              if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") canClose = true;
 508:                              else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") canClose = true;
 509:                              else if (staff.UserId == report.UserId) canClose = true; // the report closer staff is himself
 510:                              else if (
 511:                                  (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قسم الفحص والشكاوى") || staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قسم الصيانة وتركيبات الهاتف"))
 512:                                  && staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قطاع خدمات المشتركين")
 513:                                  && (staff.SubordinatesOrSelf.Any(u => u.UserId == report.UserId)))
 514:                                  canClose = true;
 515:                              else if (staff.Subordinates.Any(u => u.UserId == report.LastReportHistory.UserId)) canClose = true; // the report history closer staff is himself or a head
 516:                              else canClose = false;
 517:                          }
 518:                          else canClose = false;
 519:                      }
 520:                      else canClose = false;
 521:                  }
 522:              }
 523:              else canClose = false;
 524:   
 525:              return canClose;
 526:          }
 527:   
 528:          ////////////////////////////////////////////////////////////////////////////    
 529:   
 530:          /// <summary>
 531:          ///
 532:          /// </summary>
 533:          public static bool StaffCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 534:          {
 535:              bool isAllowed;
 536:   
 537:              if (staff != null)
 538:              {
 539:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read)
 540:                  {
 541:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 542:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 543:                      else if (staff.Framework.ArabicName == "نوكيا") isAllowed = true;
 544:                      else if (staff.Framework.ArabicName == "هواوي") isAllowed = true;
 545:                      else isAllowed = false;
 546:                  }
 547:                  else if (function == PersistentStorageFunction.Update)
 548:                  {
 549:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 550:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 551:                      else isAllowed = false;
 552:                  }
 553:                  else if (function == PersistentStorageFunction.Delete)
 554:                  {
 555:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 556:                      else isAllowed = false;
 557:                  }
 558:                  else isAllowed = false;
 559:              }
 560:              else isAllowed = false;
 561:   
 562:              return isAllowed;
 563:          }
 564:   
 565:          ////////////////////////////////////////////////////////////////////////////    
 566:   
 567:          /// <summary>
 568:          ///
 569:          /// </summary>
 570:          public static bool StaffCanCreateDeleteLicList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Msan msan)
 571:          {
 572:              bool isAllowed;
 573:   
 574:              if (staff != null)
 575:              {
 576:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Delete)
 577:                  {
 578:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffCanExecuteTasks(staff, true))
 579:                      {
 580:                          if (StaffIsSuperUser(staff)) isAllowed = true;
 581:                          else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 582:                          else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 583:                          else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 584:                          else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 585:                          else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 586:                          else if (staff.Framework.ArabicName == "قسم تقنية المعلومات" && staff.IsHead) isAllowed = true;
 587:                          else if (staff.Framework != null && staff.Framework.Sites.Count > 0)
 588:                          {
 589:                              isAllowed = false;// staff.Framework.Sites.Any(u => u.Id == msan.Site.Id);
 590:                          }
 591:                          else isAllowed = false;
 592:                      }
 593:                      else isAllowed = false;
 594:                  }
 595:                  else isAllowed = false;
 596:              }
 597:              else isAllowed = false;
 598:   
 599:              return isAllowed;
 600:          }
 601:   
 602:          ////////////////////////////////////////////////////////////////////////////    
 603:   
 604:          /// <summary>
 605:          ///
 606:          /// </summary>
 607:          public static bool StaffCanCreateBulkLicList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 608:          {
 609:              bool isAllowed;
 610:   
 611:              if (staff != null)
 612:              {
 613:                  if (function == PersistentStorageFunction.Create)
 614:                  {
 615:                      if (Ia.Ngn.Cl.Model.Business.Authority.StaffCanExecuteTasks(staff, true))
 616:                      {
 617:                          if (StaffIsSuperUser(staff)) isAllowed = true;
 618:                          else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 619:                          else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 620:                          else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 621:                          else isAllowed = false;
 622:                      }
 623:                      else isAllowed = false;
 624:                  }
 625:                  else isAllowed = false;
 626:              }
 627:              else isAllowed = false;
 628:   
 629:              return isAllowed;
 630:          }
 631:   
 632:          ////////////////////////////////////////////////////////////////////////////    
 633:   
 634:          /// <summary>
 635:          ///
 636:          /// </summary>
 637:          public static bool StaffCanCreateReadUpdateDeleteInventoryList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 638:          {
 639:              bool isAllowed;
 640:   
 641:              if (staff != null)
 642:              {
 643:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
 644:                  {
 645:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 646:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 647:                      else isAllowed = false;
 648:                  }
 649:                  else isAllowed = false;
 650:              }
 651:              else isAllowed = false;
 652:   
 653:              return isAllowed;
 654:          }
 655:   
 656:          ////////////////////////////////////////////////////////////////////////////
 657:   
 658:          /// <summary>
 659:          ///
 660:          /// </summary>
 661:          public static bool StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 662:          {
 663:              bool isAllowed;
 664:   
 665:              if (staffContact != null)
 666:              {
 667:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 668:                  else if (function == PersistentStorageFunction.Read) isAllowed = true;
 669:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 670:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 671:                  else isAllowed = false;
 672:              }
 673:              else isAllowed = false;
 674:   
 675:              return isAllowed;
 676:          }
 677:   
 678:          ////////////////////////////////////////////////////////////////////////////
 679:   
 680:          /// <summary>
 681:          ///
 682:          /// </summary>
 683:          public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 684:          {
 685:              bool isAllowed;
 686:   
 687:              if (staffContact != null)
 688:              {
 689:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 690:                  else if (function == PersistentStorageFunction.Read) isAllowed = true;
 691:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 692:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 693:                  else isAllowed = false;
 694:              }
 695:              else isAllowed = false;
 696:   
 697:              return isAllowed;
 698:          }
 699:   
 700:          ////////////////////////////////////////////////////////////////////////////
 701:   
 702:          /// <summary>
 703:          ///
 704:          /// </summary>
 705:          public static bool FrameworkCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 706:          {
 707:              bool isAllowed;
 708:   
 709:              if (framework != null)
 710:              {
 711:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 712:                  else if (function == PersistentStorageFunction.Read) isAllowed = true;
 713:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 714:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 715:                  else isAllowed = false;
 716:              }
 717:              else isAllowed = false;
 718:   
 719:              return isAllowed;
 720:          }
 721:   
 722:          ////////////////////////////////////////////////////////////////////////////
 723:   
 724:          /// <summary>
 725:          ///
 726:          /// </summary>
 727:          public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 728:          {
 729:              bool isAllowed;
 730:   
 731:              if (staffContact != null)
 732:              {
 733:                  if (function == PersistentStorageFunction.Create) isAllowed = true;
 734:                  else if (function == PersistentStorageFunction.Read) isAllowed = true;
 735:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 736:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 737:                  else isAllowed = false;
 738:              }
 739:              else isAllowed = false;
 740:   
 741:              return isAllowed;
 742:          }
 743:   
 744:          ////////////////////////////////////////////////////////////////////////////
 745:   
 746:          /// <summary>
 747:          ///
 748:          /// </summary>
 749:          public static bool FrameworkCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 750:          {
 751:              bool isAllowed;
 752:   
 753:              if (framework != null)
 754:              {
 755:                  if (function == PersistentStorageFunction.Create) isAllowed = true;
 756:                  else if (function == PersistentStorageFunction.Read) isAllowed = true;
 757:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 758:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 759:                  else isAllowed = false;
 760:              }
 761:              else isAllowed = false;
 762:   
 763:              return isAllowed;
 764:          }
 765:   
 766:          ////////////////////////////////////////////////////////////////////////////
 767:          ////////////////////////////////////////////////////////////////////////////
 768:   
 769:          /// <summary>
 770:          ///
 771:          /// </summary>
 772:          public static bool StaffCanCreateReadUpdateDeleteServicePort(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 773:          {
 774:              bool isAllowed;
 775:   
 776:              if (staff != null)
 777:              {
 778:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 779:                  else isAllowed = false;
 780:              }
 781:              else isAllowed = false;
 782:   
 783:              return isAllowed;
 784:          }
 785:   
 786:          ////////////////////////////////////////////////////////////////////////////
 787:          ////////////////////////////////////////////////////////////////////////////
 788:   
 789:          /// <summary>
 790:          ///
 791:          /// </summary>
 792:          public static bool StaffCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 793:          {
 794:              bool isAllowed;
 795:   
 796:              if (staff != null)
 797:              {
 798:                  if (function == PersistentStorageFunction.Read)
 799:                  {
 800:                      isAllowed = true;
 801:                  }
 802:                  else if (function == PersistentStorageFunction.Update)
 803:                  {
 804:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 805:                      else isAllowed = false;
 806:                  }
 807:                  else
 808:                  {
 809:                      isAllowed = false;
 810:                  }
 811:              }
 812:              else isAllowed = false;
 813:   
 814:              return isAllowed;
 815:          }
 816:   
 817:          ////////////////////////////////////////////////////////////////////////////
 818:   
 819:          /// <summary>
 820:          ///
 821:          /// </summary>
 822:          public static bool StaffContactCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 823:          {
 824:              bool isAllowed;
 825:   
 826:              if (staffContact != null)
 827:              {
 828:                  if (persistentStorageFunction == PersistentStorageFunction.Read)
 829:                  {
 830:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
 831:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 832:                      else isAllowed = false;
 833:                  }
 834:                  else if (persistentStorageFunction == PersistentStorageFunction.Update)
 835:                  {
 836:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
 837:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 838:                      else isAllowed = false;
 839:                  }
 840:                  else
 841:                  {
 842:                      isAllowed = false;
 843:                  }
 844:              }
 845:              else isAllowed = false;
 846:   
 847:              return isAllowed;
 848:          }
 849:   
 850:          ////////////////////////////////////////////////////////////////////////////
 851:          ////////////////////////////////////////////////////////////////////////////
 852:   
 853:          /// <summary>
 854:          ///
 855:          /// </summary>
 856:          public static bool StaffUserNameCanLogFromAnyPcIp(string userName)
 857:          {
 858:              bool isAllowed;
 859:   
 860:              if (!string.IsNullOrEmpty(userName))
 861:              {
 862:                  if (userName == "jasem") isAllowed = true;
 863:                  else if (userName == "mohammad") isAllowed = true;
 864:                  else isAllowed = false;
 865:              }
 866:              else isAllowed = false;
 867:   
 868:              return isAllowed;
 869:          }
 870:   
 871:          ////////////////////////////////////////////////////////////////////////////
 872:          ////////////////////////////////////////////////////////////////////////////
 873:   
 874:          /// <summary>
 875:          ///
 876:          /// </summary>
 877:          public static Ia.Ngn.Cl.Model.Business.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
 878:          {
 879:              get
 880:              {
 881:                  Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
 882:   
 883:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "وزارة الإتصالات وتكنولوجيا المعلومات" select f).FirstOrDefault(); //.SingleOrDefault();
 884:   
 885:                  return framework;
 886:              }
 887:          }
 888:   
 889:          ////////////////////////////////////////////////////////////////////////////
 890:   
 891:          /// <summary>
 892:          ///
 893:          /// </summary>
 894:          public static bool FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 895:          {
 896:              bool isResponsible;
 897:   
 898:              if (framework.ArabicName == "قسم الدعم الفني للشبكة") isResponsible = true;
 899:              else if (framework.ArabicName == "قسم تشغيل الخدمات") isResponsible = true;
 900:              else if (framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isResponsible = true;
 901:              else if (framework.ArabicName == "مراقبة تشغيل الشبكة") isResponsible = true;
 902:              //else if (framework.ArabicName == "مراقبة تقنية المعلومات") isResponsible = true;
 903:              else if (framework.ArabicName == "مراقبة خدمات الشبكة") isResponsible = true;
 904:              else if (framework.ArabicName == "إدارة شبكة الألياف الضوئية") isResponsible = true;
 905:              else isResponsible = false;
 906:   
 907:              return isResponsible;
 908:          }
 909:   
 910:          ////////////////////////////////////////////////////////////////////////////
 911:   
 912:          /// <summary>
 913:          ///
 914:          /// </summary>
 915:          public static bool FrameworkIsResponsibleForMissingLic(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 916:          {
 917:              bool isResponsible;
 918:   
 919:              if (framework.ArabicName == "قسم تشغيل الخدمات") isResponsible = true;
 920:              else if (framework.ArabicName == "قسم خدمات الشبكة") isResponsible = true;
 921:              else if (framework.ArabicName == "مراقبة خدمات الشبكة") isResponsible = true;
 922:              else if (framework.ArabicName == "إدارة شبكة الألياف الضوئية") isResponsible = true;
 923:              else isResponsible = false;
 924:   
 925:              return isResponsible;
 926:          }
 927:   
 928:          ////////////////////////////////////////////////////////////////////////////
 929:   
 930:          /// <summary>
 931:          ///
 932:          /// </summary>
 933:          public static bool FrameworkCanCloseReport(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 934:          {
 935:              bool canClose;
 936:   
 937:              canClose = framework.ArabicName == "قسم الدعم الفني للشبكة";
 938:   
 939:              return canClose;
 940:          }
 941:   
 942:          ////////////////////////////////////////////////////////////////////////////
 943:   
 944:          /// <summary>
 945:          ///
 946:          /// </summary>
 947:          public static bool StaffIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Staff staff)
 948:          {
 949:              bool isResponsible;
 950:   
 951:              isResponsible = FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(staff.Framework);
 952:   
 953:              return isResponsible;
 954:          }
 955:   
 956:          ////////////////////////////////////////////////////////////////////////////
 957:          ////////////////////////////////////////////////////////////////////////////
 958:   
 959:          /// <summary>
 960:          ///
 961:          /// </summary>
 962:          public static bool StaffIsSuperUser(Ia.Ngn.Cl.Model.Staff staff)
 963:          {
 964:              bool isSuperUser;
 965:   
 966:              if (staff != null)
 967:              {
 968:                  isSuperUser = (SuperStaff != null && SuperStaff.Id == staff.Id || ApplicationStaff != null && ApplicationStaff.Id == staff.Id);
 969:              }
 970:              else isSuperUser = false;
 971:   
 972:              return isSuperUser;
 973:          }
 974:   
 975:          ////////////////////////////////////////////////////////////////////////////
 976:   
 977:          /// <summary>
 978:          ///
 979:          /// </summary>
 980:          public static bool StaffIsSuperOrDeputyUser(Ia.Ngn.Cl.Model.Staff staff)
 981:          {
 982:              bool isSuperOrDeputyUser;
 983:   
 984:              if (staff != null)
 985:              {
 986:                  isSuperOrDeputyUser = (SuperStaff != null && SuperStaff.Id == staff.Id || DeputyStaff != null && DeputyStaff.Id == staff.Id);
 987:              }
 988:              else isSuperOrDeputyUser = false;
 989:   
 990:              return isSuperOrDeputyUser;
 991:          }
 992:   
 993:          ////////////////////////////////////////////////////////////////////////////
 994:   
 995:          /// <summary>
 996:          ///
 997:          /// </summary>
 998:          public static bool FrameworkIsSuperFramework(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 999:          {
            bool isSuperFramework;
 
            if (framework != null)
            {
                if (framework.ArabicName == "قسم دعم تشغيل الشبكة") isSuperFramework = true;
                else if (framework.ArabicName == "التطبيقات المتكاملة") isSuperFramework = true;
                else isSuperFramework = false;
            }
            else isSuperFramework = false;
 
            return isSuperFramework;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool FrameworkIsApplication(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
        {
            bool isSuperFramework;
 
            if (framework != null)
            {
                if (framework.ArabicName == "التطبيقات المتكاملة") isSuperFramework = true;
                else isSuperFramework = false;
            }
            else isSuperFramework = false;
 
            return isSuperFramework;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Ia.Ngn.Cl.Model.Staff SuperStaff
        {
            get
            {
                var staff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
                             where s.Framework.ArabicName == "قسم دعم تشغيل الشبكة" && s.IsHead
                             select s).Single();  // me!
 
                return staff;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Ia.Ngn.Cl.Model.Staff ApplicationStaff
        {
            get
            {
                var staff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
                             where s.Framework.ArabicName == "التطبيقات المتكاملة" && s.IsHead
                             select s).SingleOrDefault();  // me!
 
                return staff;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Ia.Ngn.Cl.Model.Staff DeputyStaff
        {
            get
            {
                var staff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
                             where s.Framework.ArabicName == "قسم تقنية المعلومات" && s.IsHead
                             select s).Single();
 
                return staff;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static Ia.Ngn.Cl.Model.Business.Administration.Framework SuperFramework
        {
            get
            {
                Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
 
                framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
                             where f.ArabicName == "قسم دعم تشغيل الشبكة" || f.ArabicName == "التطبيقات المتكاملة"
                             select f).Single();
 
                return framework;
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (function == PersistentStorageFunction.Read)
                {
                    isAllowed = true;
                }
                else if (function == PersistentStorageFunction.Create)
                {
                    if (StaffIsSuperUser(staff)) isAllowed = true;
                    else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
                    else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                    else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                    else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
                    else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                    else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                    else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                    else isAllowed = false;
                }
                else if (function == PersistentStorageFunction.Update)
                {
                    if (StaffIsSuperUser(staff)) isAllowed = true;
                    else isAllowed = false;
                }
                else if (function == PersistentStorageFunction.Delete)
                {
                    if (StaffIsSuperUser(staff)) isAllowed = true;
                    else isAllowed = false;
                }
                else
                {
                    isAllowed = false;
                }
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanCreateReadUpdateAccessMail(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (function == PersistentStorageFunction.Read)
                {
                    isAllowed = true;
                }
                else if (function == PersistentStorageFunction.Update)
                {
                    if (StaffIsSuperUser(staff)) isAllowed = true;
                    else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
                    else isAllowed = false;
                }
                else
                {
                    isAllowed = false;
                }
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanUploadGponPhaseIiHomeConnectionAndMigrationCsvFile(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool FrameworkCanReadStatistics(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
        {
            bool isAllowed;
 
            if (framework != null)
            {
                if (FrameworkIsSuperFramework(framework)) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = true; // for now I will allow users with framework = null coming form telegram
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
        {
            bool isAllowed;
 
            if (staffContact != null)
            {
                if (function == PersistentStorageFunction.Create) isAllowed = true;
                else if (function == PersistentStorageFunction.Read) isAllowed = true;
                else if (function == PersistentStorageFunction.Update) isAllowed = false;
                else if (function == PersistentStorageFunction.Delete) isAllowed = false;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanOverrideRouterDomainRestrictionInCreatingService(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanReadUpdateService2Access(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات" && staff.IsHead) isAllowed = true;
                //else if (staff.Framework.ArabicName == "هواوي" && staff.IsHead) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanMigratePremisesFromPstnToFiber(Ia.Ngn.Cl.Model.Staff staff)
        {
            // see related sister function StaffCanMigratePremisesFromPstnToFiberForNddOnt()
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
                else
                {
                    if (staff.Framework != null && staff.Framework.Sites.Count > 0)
                    {
                        var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 
                        isAllowed = staff.Framework.Sites.Any(u => u.Routers.Any(v => v.Odfs.Any(w => w.Olts.Any(x => list.Contains(x.Id)))));
                    }
                    else isAllowed = false;
                }
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanMigratePremisesFromPstnToFiberForNddOnt(Ia.Ngn.Cl.Model.Staff staff, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
        {
            // see related sister function StaffCanMigratePremisesFromPstnToFiber()
            bool isAllowed;
 
            if (staff != null)
            {
                if (nddOnt != null)
                {
                    var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
 
                    if (list.Contains(nddOnt.Pon.PonGroup.Olt.Id))
                    {
                        if (StaffIsSuperUser(staff)) isAllowed = true;
                        else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                        else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                        else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                        else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                        else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                        else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
                        else
                        {
                            if (staff.Framework != null && staff.Framework.Sites.Count > 0)
                            {
                                isAllowed = staff.Framework.Sites.Any(u => u.Routers.Any(v => v.Odfs.Any(w => w.Olts.Any(x => nddOnt.Pon.PonGroup.Olt.Id == x.Id))));
                            }
                            else isAllowed = false;
                        }
                    }
                    else isAllowed = false;
                }
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanAccessAdministationFolder(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            /*
             * <allow roles="التطبيقات المتكاملة,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة,إدارة مشاريع الشبكة الهاتفية"/>
             * <allow roles="نوكيا,هواوي,وزارة الإتصالات وتكنولوجيا المعلومات" />
             * <deny users="*"/>
             * <allow users="mohammad"/>
             */
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "وزارة الإتصالات وتكنولوجيا المعلومات")) isAllowed = true;
                else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "هواوي")) isAllowed = true;
                else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "نوكيا")) isAllowed = true;
                else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "التطبيقات المتكاملة")) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanExecuteTasks(Ia.Ngn.Cl.Model.Staff staff)
        {
            return StaffCanExecuteTasks(staff, false);
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanExecuteTasks(Ia.Ngn.Cl.Model.Staff staff, bool overrideCondition)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                else if (overrideCondition) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffCanExecuteAccessTasks(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (StaffIsSuperUser(staff)) isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
                else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
                else if (Ia.Ngn.Cl.Model.Business.Authority.StaffIsInCustomerServiceSector(staff)) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffIsApplication(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة" && staff.FirstName == "جاسم"
                    || staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffIsInCustomerServiceSector(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (staff.Framework.Ancestors.Any(u => u.ArabicName == "قطاع خدمات المشتركين")) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffIsInOpticalFiberNetworkDepartment(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "إدارة شبكة الألياف الضوئية")) isAllowed = true;
                //else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "إدارة مشاريع الشبكة الهاتفية")) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffIsSupplier(Ia.Ngn.Cl.Model.Staff staff)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (staff.Framework.ArabicName == "نوكيا" || staff.Framework.ArabicName == "هواوي") isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool StaffIsInRole(Ia.Ngn.Cl.Model.Staff staff, string role)
        {
            bool isAllowed;
 
            if (staff != null)
            {
                if (staff.Framework.Ancestors.Any(u => u.ArabicName == role)) isAllowed = true;
                else isAllowed = false;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static List<Tuple<string, string>> EmailRecipientTupleList(Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction schedularFunction)
        {
            List<Tuple<string, string>> recipientTupleList;
 
            recipientTupleList = new List<Tuple<string, string>>();
 
            switch (schedularFunction)
            {
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslyPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("E. Shatti", "emad@moc.gov.kw"));
                        //recipientTupleList.Add(new Tuple<string, string>("M. Qattan", "qattan04@hotmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslyQrnPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("QRN Exchange", "qrnexchange@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslyJblPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("JBL Exchange", "jbl.exch@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslySsbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("SSB Exchange", "ssb.exch@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslySlmaPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("SLMA Exchange", "slmakw158@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslySlmbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("SLMB Exchange", "msfkw158@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslyMsfPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("MSF Exchange", "msfkw158@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.ListOfPreviouslyFhhPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("FHH Exchange", "fahaheel.2021@gmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
 
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.StatusReport:
                    {
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.StatisticsReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("Traffic", "khalaf.j@hotmail.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.NokiaReport:
                    {
                        recipientTupleList.Add(new Tuple<string, string>("R. Vizcara", "rumello.vizcara@nokia.com"));
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                case Ia.Ngn.Cl.Model.Business.Authority.SchedularFunction.HuaweiReport:
                    {
                        //recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
 
                        break;
                    }
                default: break;
            }
 
            return recipientTupleList;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool ServiceRequestIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
        {
            // below: this skips processing some service requests due to misc problems
            bool processingIsAllowed;
 
            // see ServiceRequestIdIsAllowedForProcessing in service-request.cs
 
            if (serviceRequest.Id == 1719402 || serviceRequest.Id == 1875029) processingIsAllowed = false;
            // 1719402    25232104    1    تم التنفيذ    2014-10-28 11:07    خط هاتف    هاتف    17    الادارة العامة للجمارك    جهات حكومية
            // 1875029    25232104    1    تعذر التنفيذ    2016-02-24 00:00    رفع خط    هاتف    17    الادارة العامة للجمارك    جهات حكومية
            else if (serviceRequest.Id == 1639637) processingIsAllowed = false;
            // 1639637    25430454    3    تم التنفيذ    2014-03-05 09:04    خط هاتف    هاتف    1619586    بدر ناصر غانم الارملي
            // above: wrong service record with serial 3, but later records reduce to 2
            else if (serviceRequest.Id == 361494) processingIsAllowed = false;
            // 361494    25518807    0    تم التنفيذ    2006-07-26 11:58    إيقاف كاشف    هاتف
            // above: causes call waiting to stop in the group service
            else processingIsAllowed = true;
 
            return processingIsAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool ServiceRequestHistoryIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory)
        {
            // below: this skips processing some service requests due to misc problems
            bool processingIsAllowed;
 
            if (serviceRequestHistory.Id == "25429778:1:965:0:66:2005-11-27") processingIsAllowed = false;
            // prevent the removal of service group
            else if (serviceRequestHistory.Id == "23900287:1:965:1:14:2005-07-06" || serviceRequestHistory.Id == "23900287:1:965:1:66:2008-12-25") processingIsAllowed = false;
            /*
            23900287    1    يعمل    2005-07-06        2005-07-06    كاشف رقم    هاتف    2019-03-29 22:01    2019-03-29 22:01
            23900287    1    يعمل    2005-07-06        2008-12-25    إيقاف كاشف    هاتف    2019-03-29 22:01    2019-03-29 22:01
            */
            else if (serviceRequestHistory.Id == "25518807:1:965:0:66:2002-10-27" || serviceRequestHistory.Id == "25518807:1:965:0:66:2006-07-26") processingIsAllowed = false;
            /*
            25518807:1:965:0:66:2002-10-27    25518807    0    7001    1986-05-29 00:00:00.000    1753-01-01 00:00:00.000    2002-10-27 00:00:00.000    66    3    2019-04-10 23:07:01.897    2019-04-10 23:07:01.897    NULL
            25518807:1:965:0:66:2006-07-26    25518807    0    7001    1986-05-29 00:00:00.000    1753-01-01 00:00:00.000    2006-07-26 00:00:00.000    66    3    2019-04-10 23:07:01.897    2019-04-10 23:07:01.897    NULL             
            */
            else if (serviceRequestHistory.Id == "25519290:1:965:1:66:2002-10-28") processingIsAllowed = false;
            /*
            25519290    1    يعمل    1998-03-28        2002-10-28    إيقاف كاشف    هاتف    2019-04-10 23:48    2019-04-10 23:48
            25519290:1:965:1:66:2002-10-28    25519290    1    7001    1998-03-28 00:00:00.000    1753-01-01 00:00:00.000    2002-10-28 00:00:00.000    66    3    2019-04-10 23:48:15.117    2019-04-10 23:48:15.117    NULL
            */
            else processingIsAllowed = true;
 
            return processingIsAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool ServiceProcessingIsAllowed(string service)
        {
            // below: this skips processing some services due to misc problems
            bool processingIsAllowed;
 
            if (!string.IsNullOrEmpty(service))
            {
                if (Ia.Ngn.Cl.Model.Data.ServiceExemption.ServiceList().Contains(service)) processingIsAllowed = false;
                else processingIsAllowed = true;
            }
            else processingIsAllowed = true;
 
            return processingIsAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
 
        /// <summary>
        ///
        /// </summary>
        public static bool TelegramUserCanReadFind(string chatId, int userId)
        {
            bool isAllowed;
 
            if (userId != 0)
            {
                isAllowed = true;
            }
            else isAllowed = false;
 
            return isAllowed;
        }
 
        ////////////////////////////////////////////////////////////////////////////    
 
        /// <summary>
        ///
        /// </summary>
        public static bool NumberIsWithinFrameworkSiteDomainList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string service)
        {
            bool isWithin;
 
            if (framework != null)
            {
                if (framework.Sites.Count > 0)
                {
                    if (framework.Sites.Any(w => w.DomainList.Any(u => service.StartsWith(u.ToString())))) isWithin = true;
                    else isWithin = true; // false; temp
                }
                else isWithin = true; // will allow number for framework.Site == null
            }
            else isWithin = true; // will allow for null framework because the function is used from systems that do not utilize ASP.NET membership like telegram and email.
 
            return isWithin;
        }
 
        ////////////////////////////////////////////////////////////////////////////    
 
        /// <summary>
        ///
        /// </summary>
        public static bool AccessNameIsWithinFrameworkSiteAreaSymbolList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string accessName)
        {
            bool isWithin;
 
            if (framework != null)
            {
                if (framework.Sites.Count > 0)
                {
                    if (framework.Sites.Any(u => u.AreaSymbolList.Any(v => accessName.StartsWith(v.ToString())))) isWithin = true;
                    else isWithin = true; // false; temp
                }
                else isWithin = true; // will allow number for framework.Site == null
            }
            else isWithin = true; // I will allow for null framework because the function is used from systems that do not utilize ASP.NET membership like telegram and email.
 
            return isWithin;
        }
 
        ////////////////////////////////////////////////////////////////////////////    
 
        /// <summary>
        ///
        /// </summary>
        public static void UpdateAdministrativeFrameworkRolesOfStaff(Ia.Ngn.Cl.Model.Staff staff)
        {
            string userName;
            MembershipUser membershipUser;
 
            membershipUser = Membership.GetUser(staff.UserId);
 
            if (membershipUser != null)
            {
                userName = membershipUser.UserName;
 
                // add user to IsHead role if he is head, and remove him otherwise
                if (staff.IsHead)
                {
                    if (!Roles.IsUserInRole(userName, "IsHead")) Roles.AddUserToRole(userName, "IsHead");
                }
                else
                {
                    if (Roles.IsUserInRole(userName, "IsHead")) Roles.RemoveUserFromRole(userName, "IsHead");
                }
 
                // add user to its direct role
                if (!Roles.IsUserInRole(userName, staff.Framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, staff.Framework.FullyQualifiedArabicName);
 
                // add user to its decendants roles
                foreach (var framework in staff.Framework.Descendants)
                {
                    if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
                }
 
                // add user to its ancestors roles
                foreach (var framework in staff.Framework.Ancestors)
                {
                    if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
                }
 
                // loop through all user roles and remove it from roles not in his description
                foreach (var framework in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList)
                {
                    if (framework.Id != staff.Framework.Id
                        && !staff.Framework.Descendants.Any(f => f.Id == framework.Id)
                        && !staff.Framework.Ancestors.Any(f => f.Id == framework.Id)
                        && Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName))
                        Roles.RemoveUserFromRole(userName, framework.FullyQualifiedArabicName);
                }
            }
        }
 
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////    
    }
 
    ////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////   
}