Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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 Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Web;
   3:  using System.Xml;
   4:  using System.Xml.Linq;
   5:  using System.IO;
   6:  using System.Configuration;
   7:  using System.Text;
   8:  using System.Text.RegularExpressions;
   9:  using System.Data;
  10:  using System.Data.SqlClient;
  11:  using System.Web.UI;
  12:  using System.Web.UI.WebControls;
  13:  using System.Collections;
  14:  using System.Collections.Generic;
  15:  using System.Linq;
  16:  using System.Reflection;
  17:   
  18:  namespace Ia.Ngn.Cl.Model.Business
  19:  {
  20:      ////////////////////////////////////////////////////////////////////////////
  21:   
  22:      /// <summary publish="true">
  23:      /// Authority support class of Next Generation Network'a (NGN's) business model.
  24:      /// </summary>
  25:      /// 
  26:      /// <remarks> 
  27:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  28:      ///
  29:      /// 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
  30:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  31:      ///
  32:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  33:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  34:      /// 
  35:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  36:      /// 
  37:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  38:      /// </remarks> 
  39:      public class Authority
  40:      {
  41:          private static Ia.Ngn.Cl.Model.Staff superUserStaff;
  42:   
  43:          public enum PersistentStorageFunction { Create = 1, Read, Update, Delete };
  44:   
  45:          ////////////////////////////////////////////////////////////////////////////
  46:   
  47:          /// <summary>
  48:          ///
  49:          /// </summary>
  50:          public Authority() { }
  51:   
  52:          ////////////////////////////////////////////////////////////////////////////    
  53:   
  54:          /// <summary>
  55:          ///
  56:          /// </summary>
  57:          public static List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> StaffFrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Staff staff)
  58:          {
  59:              List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> staffList, frameworkList, list;
  60:   
  61:              // staff list:
  62:              if (staff.Subordinates != null && staff.Colleagues != null)
  63:              {
  64:                  staffList = (from s in staff.Colleagues.Union(staff.Subordinates).Concat(new[] { staff.Head })
  65:                               select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  66:                               {
  67:                                   Id = s.UserId,
  68:                                   IsStaff = true,
  69:                                   Name = s.FirstAndMiddleName
  70:                               }
  71:                  ).ToList();
  72:              }
  73:              else if (staff.Colleagues != null)
  74:              {
  75:                  staffList = (from s in staff.Colleagues.Concat(new[] { staff.Head })
  76:                               select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  77:                               {
  78:                                   Id = s.UserId,
  79:                                   IsStaff = true,
  80:                                   Name = s.FirstAndMiddleName
  81:                               }
  82:                  ).ToList();
  83:              }
  84:              else
  85:              {
  86:                  staffList = (from s in (new[] { staff.Head })
  87:                               select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  88:                               {
  89:                                   Id = s.UserId,
  90:                                   IsStaff = true,
  91:                                   Name = s.FirstAndMiddleName
  92:                               }
  93:                               ).ToList();
  94:              }
  95:   
  96:              // framework list: framework descendants, siblings and uncles (for head staff only)
  97:              if (staff.Framework.Descendants != null && staff.Framework.Siblings != null)
  98:              {
  99:                  if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 100:                  {
 101:                      frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Union(staff.Framework.Parent.Siblings).Concat(new[] { staff.Framework.Parent })
 102:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 103:                                       {
 104:                                           Id = f.Guid,
 105:                                           IsFramework = true,
 106:                                           Name = f.ArabicName
 107:                                       }
 108:                                       ).OrderBy(c => c.Id).ToList();
 109:                  }
 110:                  else
 111:                  {
 112:                      frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Concat(new[] { staff.Framework.Parent })
 113:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 114:                                       {
 115:                                           Id = f.Guid,
 116:                                           IsFramework = true,
 117:                                           Name = f.ArabicName
 118:                                       }
 119:                                       ).OrderBy(c => c.Id).ToList();
 120:                  }
 121:              }
 122:              else if (staff.Framework.Descendants != null)
 123:              {
 124:                  if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 125:                  {
 126:                      frameworkList = (from f in staff.Framework.Descendants.Union(staff.Framework.Parent.Siblings).Concat(new[] { staff.Framework.Parent })
 127:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 128:                                       {
 129:                                           Id = f.Guid,
 130:                                           IsFramework = true,
 131:                                           Name = f.ArabicName
 132:                                       }
 133:                                       ).OrderBy(c => c.Id).ToList();
 134:                  }
 135:                  else
 136:                  {
 137:                      frameworkList = (from f in staff.Framework.Descendants.Concat(new[] { staff.Framework.Parent })
 138:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 139:                                       {
 140:                                           Id = f.Guid,
 141:                                           IsFramework = true,
 142:                                           Name = f.ArabicName
 143:                                       }
 144:                                       ).OrderBy(c => c.Id).ToList();
 145:                  }
 146:              }
 147:              else
 148:              {
 149:                  if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 150:                  {
 151:                      frameworkList = (from f in staff.Framework.Parent.Siblings.Concat(new[] { staff.Framework.Parent })
 152:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 153:                                       {
 154:                                           Id = f.Guid,
 155:                                           IsFramework = true,
 156:                                           Name = f.ArabicName
 157:                                       }
 158:                                       ).OrderBy(c => c.Id).ToList();
 159:                  }
 160:                  else
 161:                  {
 162:                      frameworkList = (from f in (new[] { staff.Framework.Parent })
 163:                                       select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 164:                                       {
 165:                                           Id = f.Guid,
 166:                                           IsFramework = true,
 167:                                           Name = f.ArabicName
 168:                                       }
 169:                                       ).OrderBy(c => c.Id).ToList();
 170:                  }
 171:              }
 172:   
 173:              list = staffList.Union(frameworkList).ToList();
 174:   
 175:              return list;
 176:          }
 177:   
 178:          ////////////////////////////////////////////////////////////////////////////    
 179:   
 180:          /// <summary>
 181:          ///
 182:          /// </summary>
 183:          public static bool StaffCanCreateReadUpdateDeleteReport(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 184:          {
 185:              bool isAllowed;
 186:   
 187:              if (staff != null)
 188:              {
 189:                  if (function == PersistentStorageFunction.Delete)
 190:                  {
 191:                      // below: a report can only by:
 192:                      // - one of the heads of the reporter.
 193:                      // - the reporter if he is a head
 194:   
 195:                      if (report.LastReportHistory == null && staff.UserId == report.UserId && staff.IsHead) isAllowed = true;
 196:                      else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId && staff.IsHead) isAllowed = true;
 197:                      else if (report.LastReportHistory == null && staff.IsHead) isAllowed = true;
 198:                      else if (staff.Subordinates != null)
 199:                      {
 200:                          if (report.LastReportHistory != null) isAllowed = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 201:                          else isAllowed = staff.Subordinates.Any(i => i.UserId == report.UserId);
 202:                      }
 203:                      else isAllowed = false;
 204:                  }
 205:                  else
 206:                  {
 207:                      // below: a report can be CRUD if
 208:                      // - last report does not exist
 209:                      // - last report exists and its UserId is same as staffs
 210:                      // - report owner is subordinate of staff
 211:                      // - report framework is within users frameworks
 212:   
 213:                      if (report.ReportHistories.Count == 0)
 214:                      {
 215:                          isAllowed = report.LastReportHistory.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 216:   
 217:                          if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId))
 218:                          {
 219:                              isAllowed = staff.Framework.Guid == report.LastReportHistory.UserId
 220:                                  || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.LastReportHistory.UserId);
 221:                          }
 222:                      }
 223:                      else
 224:                      {
 225:                          isAllowed = true; // report.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.UserId);
 226:   
 227:                          /*
 228:                          if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId))
 229:                          {
 230:                              isAllowed = staff.Framework.Guid == report.UserId 
 231:                                  || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.UserId);
 232:                          }
 233:                           */
 234:                      }
 235:                  }
 236:   
 237:                  if (staff.Id == SuperUserStaff.Id) isAllowed = true;
 238:              }
 239:              else isAllowed = false;
 240:   
 241:              return isAllowed;
 242:          }
 243:   
 244:          ////////////////////////////////////////////////////////////////////////////    
 245:   
 246:          /// <summary>
 247:          ///
 248:          /// </summary>
 249:          public static bool StaffCanSendFieldTndWorkorderEmail(Ia.Ngn.Cl.Model.Staff staff)
 250:          {
 251:              bool isAllowed;
 252:   
 253:              if (staff != null)
 254:              {
 255:                  if (staff.IsHead) isAllowed = true;
 256:                  else isAllowed = false;
 257:              }
 258:              else isAllowed = false;
 259:   
 260:              return isAllowed;
 261:          }
 262:   
 263:          ////////////////////////////////////////////////////////////////////////////    
 264:   
 265:          /// <summary>
 266:          ///
 267:          /// </summary>
 268:          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)
 269:          {
 270:              // below: I have to pass both Report and ReportHistory objects separately
 271:   
 272:              bool isAllowed;
 273:   
 274:              if (staff != null)
 275:              {
 276:                  if (function == PersistentStorageFunction.Delete)
 277:                  {
 278:                      // below: a report history can only be deleted by:
 279:                      // - one of the heads of the history user
 280:                      // - the history user if he is a head
 281:   
 282:                      if (reportHistory != null)
 283:                      {
 284:                          if (reportHistory.Report.ReportHistories.Max(r => r.Id) != reportHistory.Id) isAllowed = false;
 285:                          else
 286:                          {
 287:                              if (staff.UserId == reportHistory.UserId && staff.IsHead) isAllowed = true;
 288:                              else if (staff.Subordinates != null) isAllowed = staff.Subordinates.Any(i => i.UserId == reportHistory.UserId);
 289:                              else isAllowed = false;
 290:                          }
 291:                      }
 292:                      else isAllowed = false;
 293:                  }
 294:                  else if (function == PersistentStorageFunction.Create)
 295:                  {
 296:                      // below: for create reportHistory must be null
 297:   
 298:                      // below: a report history can be created if:
 299:                      // - report userid is subordinate of staff
 300:                      // - report history userid framework is within staff frameworks
 301:   
 302:                      if (report != null && reportHistory == null)
 303:                      {
 304:                          if (report.ReportHistories.Count == 0 && staff.UserId == report.UserId) isAllowed = true;
 305:                          else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId) isAllowed = true;
 306:                          else if (report.ReportHistories.Count == 0 && report.StatusIsOpen) isAllowed = true;
 307:                          else if (report.LastReportHistory != null && staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId)) isAllowed = true;
 308:                          else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId) && (staff.Framework.Guid == report.UserId || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.UserId))) isAllowed = true;
 309:                          else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId) && report.LastReportHistory != null && (staff.Framework.Guid == report.LastReportHistory.UserId || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.LastReportHistory.UserId) || staff.Framework.Ancestors != null && staff.Framework.Ancestors.Any(i => i.Guid == report.LastReportHistory.UserId))) isAllowed = true;
 310:                          else isAllowed = false;
 311:                      }
 312:                      else isAllowed = false;
 313:                  }
 314:                  else
 315:                  {
 316:                      // below: a report history can be read, and updated if:
 317:                      // - report history UserId is same as staff's
 318:                      // - report userid is subordinate of staff
 319:                      // - report history userid framework is within staff frameworks
 320:   
 321:                      if (reportHistory != null)
 322:                      {
 323:                          if (staff.UserId == reportHistory.UserId) isAllowed = true;
 324:                          else if (staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == reportHistory.UserId)) isAllowed = true;
 325:                          else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(reportHistory.UserId))
 326:                          {
 327:                              if (staff.Framework.Guid == reportHistory.UserId || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == reportHistory.UserId)) isAllowed = true;
 328:                              else isAllowed = false;
 329:                          }
 330:                          else isAllowed = false;
 331:                      }
 332:                      else isAllowed = false;
 333:                  }
 334:   
 335:                  if (staff.Id == SuperUserStaff.Id) isAllowed = true;
 336:              }
 337:              else isAllowed = false;
 338:   
 339:              return isAllowed;
 340:          }
 341:   
 342:          ////////////////////////////////////////////////////////////////////////////    
 343:   
 344:          /// <summary>
 345:          ///
 346:          /// </summary>
 347:          public static bool StaffCanReopenClosedReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 348:          {
 349:              return StaffCanCloseReport(report, staff);
 350:          }
 351:   
 352:          ////////////////////////////////////////////////////////////////////////////    
 353:   
 354:          /// <summary>
 355:          ///
 356:          /// </summary>
 357:          public static bool StaffCanCloseReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 358:          {
 359:              bool canClose;
 360:   
 361:              // below: a report can be closed if
 362:              // - there must be a history
 363:              // - the closer staff is himself, is the head or one of the heads of the last report staff
 364:   
 365:              if (staff != null)
 366:              {
 367:                  if (report.LastReportHistory != null && staff.Subordinates != null)
 368:                  {
 369:                      if (staff.UserId == report.LastReportHistory.UserId) canClose = true;
 370:                      else canClose = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 371:                  }
 372:                  else canClose = false;
 373:   
 374:                  if (staff.Id == SuperUserStaff.Id) canClose = true;
 375:              }
 376:              else canClose = false;
 377:   
 378:              return canClose;
 379:          }
 380:   
 381:          ////////////////////////////////////////////////////////////////////////////    
 382:   
 383:          /// <summary>
 384:          ///
 385:          /// </summary>
 386:          public static bool StaffCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 387:          {
 388:              bool isAllowed;
 389:   
 390:              if (staff != null)
 391:              {
 392:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
 393:                  {
 394:                      if (staff.Id == SuperUserStaff.Id) isAllowed = true;
 395:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 396:                      else isAllowed = false;
 397:                  }
 398:                  else
 399:                  {
 400:                      isAllowed = false;
 401:                  }
 402:              }
 403:              else isAllowed = false;
 404:   
 405:              return isAllowed;
 406:          }
 407:   
 408:          ////////////////////////////////////////////////////////////////////////////
 409:   
 410:          /// <summary>
 411:          ///
 412:          /// </summary>
 413:          public static bool StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 414:          {
 415:              bool isAllowed;
 416:   
 417:              if (staffContact != null)
 418:              {
 419:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 420:                  else if (function == PersistentStorageFunction.Read)
 421:                  {
 422:                      isAllowed = true;
 423:                  }
 424:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 425:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 426:                  else
 427:                  {
 428:                      isAllowed = false;
 429:                  }
 430:              }
 431:              else isAllowed = false;
 432:   
 433:              return isAllowed;
 434:          }
 435:   
 436:          ////////////////////////////////////////////////////////////////////////////
 437:   
 438:          /// <summary>
 439:          ///
 440:          /// </summary>
 441:          public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 442:          {
 443:              bool isAllowed;
 444:   
 445:              if (staffContact != null)
 446:              {
 447:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 448:                  else if (function == PersistentStorageFunction.Read)
 449:                  {
 450:                      isAllowed = true;
 451:                  }
 452:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 453:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 454:                  else
 455:                  {
 456:                      isAllowed = false;
 457:                  }
 458:              }
 459:              else isAllowed = false;
 460:   
 461:              return isAllowed;
 462:          }
 463:   
 464:          ////////////////////////////////////////////////////////////////////////////
 465:   
 466:          /// <summary>
 467:          ///
 468:          /// </summary>
 469:          public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 470:          {
 471:              bool isAllowed;
 472:   
 473:              if (staffContact != null)
 474:              {
 475:                  if (function == PersistentStorageFunction.Create)
 476:                  {
 477:                      isAllowed = true;
 478:                  }
 479:                  else if (function == PersistentStorageFunction.Read)
 480:                  {
 481:                      isAllowed = true;
 482:                  }
 483:                  else if (function == PersistentStorageFunction.Update)
 484:                  {
 485:                      isAllowed = false;
 486:                  }
 487:                  else if (function == PersistentStorageFunction.Delete)
 488:                  {
 489:                      isAllowed = false;
 490:                  }
 491:                  else
 492:                  {
 493:                      isAllowed = false;
 494:                  }
 495:              }
 496:              else isAllowed = false;
 497:   
 498:              return isAllowed;
 499:          }
 500:   
 501:          ////////////////////////////////////////////////////////////////////////////
 502:          ////////////////////////////////////////////////////////////////////////////
 503:   
 504:          /// <summary>
 505:          ///
 506:          /// </summary>
 507:          public static bool StaffCanCreateReadUpdateDeleteServiceLineCard(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 508:          {
 509:              bool isAllowed;
 510:   
 511:              if (staff != null)
 512:              {
 513:                  if (function == PersistentStorageFunction.Create)
 514:                  {
 515:                      if (staff.IsHead) isAllowed = true;
 516:                      else isAllowed = false;
 517:                  }
 518:                  else if (function == PersistentStorageFunction.Read)
 519:                  {
 520:                      isAllowed = true;
 521:                  }
 522:                  else if (function == PersistentStorageFunction.Update)
 523:                  {
 524:                      if (staff.IsHead) isAllowed = true;
 525:                      else isAllowed = false;
 526:                  }
 527:                  else if (function == PersistentStorageFunction.Delete)
 528:                  {
 529:                      if (staff.IsHead) isAllowed = true;
 530:                      else isAllowed = false;
 531:                  }
 532:                  else
 533:                  {
 534:                      isAllowed = false;
 535:                  }
 536:              }
 537:              else isAllowed = false;
 538:   
 539:              return isAllowed;
 540:          }
 541:   
 542:          ////////////////////////////////////////////////////////////////////////////
 543:          ////////////////////////////////////////////////////////////////////////////
 544:   
 545:          /// <summary>
 546:          ///
 547:          /// </summary>
 548:          public static bool StaffCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 549:          {
 550:              bool isAllowed;
 551:   
 552:              if (staff != null)
 553:              {
 554:                  if (function == PersistentStorageFunction.Read)
 555:                  {
 556:                      isAllowed = true;
 557:                  }
 558:                  else if (function == PersistentStorageFunction.Update)
 559:                  {
 560:                      if (staff.Id == SuperUserStaff.Id) isAllowed = true;
 561:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 562:                      else isAllowed = false;
 563:                  }
 564:                  else
 565:                  {
 566:                      isAllowed = false;
 567:                  }
 568:              }
 569:              else isAllowed = false;
 570:   
 571:              return isAllowed;
 572:          }
 573:   
 574:          ////////////////////////////////////////////////////////////////////////////
 575:          ////////////////////////////////////////////////////////////////////////////
 576:   
 577:          /// <summary>
 578:          ///
 579:          /// </summary>
 580:          public static Ia.Ngn.Cl.Model.Data.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
 581:          {
 582:              get
 583:              {
 584:                  Ia.Ngn.Cl.Model.Data.Administration.Framework framework;
 585:   
 586:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "إدارة شبكة الألياف الضوئية" select f).FirstOrDefault(); //.SingleOrDefault();
 587:   
 588:                  return framework;
 589:              }
 590:          }
 591:   
 592:          ////////////////////////////////////////////////////////////////////////////
 593:   
 594:          /// <summary>
 595:          ///
 596:          /// </summary>
 597:          public static Ia.Ngn.Cl.Model.Staff StaffResponsibleForAllOpenReportWithNoReportHistory
 598:          {
 599:              get
 600:              {
 601:                  Ia.Ngn.Cl.Model.Staff staff;
 602:   
 603:                  staff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.IsHead && s.Framework.ArabicName == "قسم الدعم الفني للشبكة" select s).SingleOrDefault();
 604:   
 605:                  return staff;
 606:              }
 607:          }
 608:   
 609:          ////////////////////////////////////////////////////////////////////////////
 610:          ////////////////////////////////////////////////////////////////////////////
 611:   
 612:          /// <summary>
 613:          ///
 614:          /// </summary>
 615:          public static Ia.Ngn.Cl.Model.Staff SuperUserStaff
 616:          {
 617:              get
 618:              {
 619:                  if (superUserStaff == null)
 620:                  {
 621:                      //superUserStaff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.IsHead && s.Framework.ArabicName == "قسم الدعم الفني للشبكة" select s).SingleOrDefault();
 622:                      superUserStaff = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where s.IsHead && s.Framework.ArabicName == "قسم دعم تشغيل الشبكة" select s).SingleOrDefault();
 623:                  }
 624:   
 625:                  return superUserStaff;
 626:              }
 627:          }
 628:   
 629:          ////////////////////////////////////////////////////////////////////////////
 630:          ////////////////////////////////////////////////////////////////////////////
 631:   
 632:          /// <summary>
 633:          ///
 634:          /// </summary>
 635:          public static bool StaffContactCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 636:          {
 637:              bool isAllowed;
 638:   
 639:              if (staffContact != null)
 640:              {
 641:                  if (function == PersistentStorageFunction.Read)
 642:                  {
 643:                      if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 644:                      else if (staffContact.Staff != null && staffContact.Staff.IsHead && staffContact.Staff.FirstName == "جاسم") isAllowed = true;
 645:                      else isAllowed = false;
 646:                  }
 647:                  else if (function == PersistentStorageFunction.Update)
 648:                  {
 649:                      if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 650:                      else if (staffContact.Staff != null && staffContact.Staff.IsHead && staffContact.Staff.FirstName == "جاسم") isAllowed = true;
 651:                      else isAllowed = false;
 652:                  }
 653:                  else
 654:                  {
 655:                      isAllowed = false;
 656:                  }
 657:              }
 658:              else isAllowed = false;
 659:   
 660:              return isAllowed;
 661:          }
 662:   
 663:          ////////////////////////////////////////////////////////////////////////////
 664:   
 665:          /// <summary>
 666:          ///
 667:          /// </summary>
 668:          public static bool StaffCanCreateReadUpdateDeleteHsiService(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 669:          {
 670:              bool isAllowed;
 671:   
 672:              if (staff != null)
 673:              {
 674:                  if (function == PersistentStorageFunction.Create)
 675:                  {
 676:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 677:                      else isAllowed = false;
 678:                  }
 679:                  else if (function == PersistentStorageFunction.Read)
 680:                  {
 681:                      isAllowed = true;
 682:                  }
 683:                  else if (function == PersistentStorageFunction.Update)
 684:                  {
 685:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 686:                      else isAllowed = false;
 687:                  }
 688:                  else if (function == PersistentStorageFunction.Delete)
 689:                  {
 690:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 691:                      else isAllowed = false;
 692:                  }
 693:                  else
 694:                  {
 695:                      isAllowed = false;
 696:                  }
 697:              }
 698:              else isAllowed = false;
 699:   
 700:              return isAllowed;
 701:          }
 702:   
 703:          ////////////////////////////////////////////////////////////////////////////
 704:   
 705:          /// <summary>
 706:          ///
 707:          /// </summary>
 708:          public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 709:          {
 710:              bool isAllowed;
 711:   
 712:              if (staff != null)
 713:              {
 714:                  if (function == PersistentStorageFunction.Read)
 715:                  {
 716:                      isAllowed = true;
 717:                  }
 718:                  else if (function == PersistentStorageFunction.Update)
 719:                  {
 720:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 721:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 722:                      else if ((staff.IsHead || staff.FirstName == "علي") && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 723:                      else isAllowed = false;
 724:                  }
 725:                  else if (function == PersistentStorageFunction.Delete)
 726:                  {
 727:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 728:                      else isAllowed = false;
 729:                  }
 730:                  else
 731:                  {
 732:                      isAllowed = false;
 733:                  }
 734:              }
 735:              else isAllowed = false;
 736:   
 737:              return isAllowed;
 738:          }
 739:   
 740:          ////////////////////////////////////////////////////////////////////////////
 741:   
 742:          /// <summary>
 743:          ///
 744:          /// </summary>
 745:          public static bool StaffCanCreateReadUpdateHsiMail(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 746:          {
 747:              bool isAllowed;
 748:   
 749:              if (staff != null)
 750:              {
 751:                  if (function == PersistentStorageFunction.Read)
 752:                  {
 753:                      isAllowed = true;
 754:                  }
 755:                  else if (function == PersistentStorageFunction.Update)
 756:                  {
 757:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 758:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 759:                      else isAllowed = false;
 760:                  }
 761:                  else
 762:                  {
 763:                      isAllowed = false;
 764:                  }
 765:              }
 766:              else isAllowed = false;
 767:   
 768:              return isAllowed;
 769:          }
 770:   
 771:          ////////////////////////////////////////////////////////////////////////////
 772:   
 773:          /// <summary>
 774:          ///
 775:          /// </summary>
 776:          public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Staff staff)
 777:          {
 778:              bool isAllowed;
 779:   
 780:              if (staff != null)
 781:              {
 782:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 783:                  else if (staff.IsHead) isAllowed = true;
 784:                  else isAllowed = false;
 785:              }
 786:              else isAllowed = false;
 787:   
 788:              return isAllowed;
 789:          }
 790:   
 791:          ////////////////////////////////////////////////////////////////////////////
 792:   
 793:          /// <summary>
 794:          ///
 795:          /// </summary>
 796:          public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 797:          {
 798:              bool isAllowed;
 799:   
 800:              if (staffContact != null)
 801:              {
 802:                  if (function == PersistentStorageFunction.Create)
 803:                  {
 804:                      isAllowed = true;
 805:                  }
 806:                  else if (function == PersistentStorageFunction.Read)
 807:                  {
 808:                      isAllowed = true;
 809:                  }
 810:                  else if (function == PersistentStorageFunction.Update)
 811:                  {
 812:                      isAllowed = false;
 813:                  }
 814:                  else if (function == PersistentStorageFunction.Delete)
 815:                  {
 816:                      isAllowed = false;
 817:                  }
 818:                  else
 819:                  {
 820:                      isAllowed = false;
 821:                  }
 822:              }
 823:              else isAllowed = false;
 824:   
 825:              return isAllowed;
 826:          }
 827:   
 828:          ////////////////////////////////////////////////////////////////////////////
 829:          ////////////////////////////////////////////////////////////////////////////
 830:   
 831:          /// <summary>
 832:          ///
 833:          /// </summary>
 834:          public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ngn.Cl.Model.Staff staff)
 835:          {
 836:              bool isAllowed;
 837:   
 838:              if (staff != null)
 839:              {
 840:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 841:                  else isAllowed = false;
 842:              }
 843:              else isAllowed = false;
 844:   
 845:              return isAllowed;
 846:          }
 847:   
 848:          ////////////////////////////////////////////////////////////////////////////
 849:   
 850:          /// <summary>
 851:          ///
 852:          /// </summary>
 853:          public static bool StaffCanAccessAdministationFolder(Ia.Ngn.Cl.Model.Staff staff)
 854:          {
 855:              bool isAllowed;
 856:   
 857:              /*
 858:               * <allow roles="Application,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة"/>
 859:               * <deny users="*"/>
 860:               * <allow users="mohammad"/>
 861:               */
 862:   
 863:              string[] sp = { "Application", "إدارة شبكة الألياف الضوئية", "مراقبة خدمات الشبكة", "مراقبة الدعم الفنى للشبكة", "مراقبة تقنية المعلومات", "مراقبة تشغيل الشبكة", "قسم دعم تشغيل الشبكة" };
 864:   
 865:              if (staff != null)
 866:              {
 867:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 868:                  else if (staff.IsHead && staff.User.UserName == "mohammad") isAllowed = true;
 869:                  else if (sp.Contains(staff.Framework.ArabicName)) isAllowed = true;
 870:                  else isAllowed = false;
 871:              }
 872:              else isAllowed = false;
 873:   
 874:              return isAllowed;
 875:          }
 876:   
 877:          ////////////////////////////////////////////////////////////////////////////
 878:          ////////////////////////////////////////////////////////////////////////////
 879:   
 880:          /// <summary>
 881:          ///
 882:          /// </summary>
 883:          public static List<Tuple<string, string>> EmailRecipientTupleList(string function)
 884:          {
 885:              List<Tuple<string, string>> recipientTupleList;
 886:   
 887:              recipientTupleList = new List<Tuple<string, string>>();
 888:   
 889:              switch (function)
 890:              {
 891:                  case "email-list-with-ont-list-provisioned-and-ready-but-do-not-exist-in-customer-department-database":
 892:                      {
 893:                          recipientTupleList.Add(new Tuple<string, string>("Customer Department Database", "eng.salah.alfaraihan@gmail.com"));
 894:                          //recipientTupleList.Add(new Tuple<string, string>("W. Mutawa", "wesalmutawa@hotmail.com"));
 895:                          //recipientTupleList.Add(new Tuple<string, string>("B. Kandiri", "bek1973@hotmail.com"));
 896:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
 897:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 898:   
 899:                          break;
 900:                      }
 901:                  case "email-daily-ofn-status-report":
 902:                      {
 903:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 904:                          break;
 905:                      }
 906:                  case "email-weekly-ofn-statistics-report":
 907:                      {
 908:                          recipientTupleList.Add(new Tuple<string, string>("MOC Traffic Section", "traffic_section@yahoo.com"));
 909:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
 910:                          //recipientTupleList.Add(new Tuple<string, string>("A. Obaidan", "6677221@gmail.com"));
 911:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 912:                          break;
 913:                      }
 914:                  case "email-monthly-ofn-statistics-report":
 915:                      {
 916:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 917:   
 918:                          break;
 919:                      }
 920:                  case "email-weekly-ofn-nokia-report":
 921:                      {
 922:                          //recepientTupleList.Add(new Tuple<string, string>("Ahmed Shehata", "ahmed.shehata@nokia.com"));
 923:                          recipientTupleList.Add(new Tuple<string, string>("O. Kandemir", "oguzhan.kandemir@nokia.com"));
 924:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 925:                          break;
 926:                      }
 927:                  case "email-weekly-ofn-huawei-report":
 928:                      {
 929:                          recipientTupleList.Add(new Tuple<string, string>("A. Bikawi", "ahmadk.bikawi@huawei.com"));
 930:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
 931:                          break;
 932:                      }
 933:                  default: break;
 934:              }
 935:   
 936:              return recipientTupleList;
 937:          }
 938:   
 939:          ////////////////////////////////////////////////////////////////////////////
 940:          ////////////////////////////////////////////////////////////////////////////
 941:   
 942:          /// <summary>
 943:          ///
 944:          /// </summary>
 945:          public static bool ServiceRequestIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
 946:          {
 947:              // below: this skips processing some service requests due to misc problems
 948:              bool processingIsAllowed;
 949:   
 950:              processingIsAllowed = true;
 951:   
 952:              // we will skip service order dates before 2004-01-01
 953:              if (serviceRequest.RequestDateTime > DateTime.Parse("2004-01-01"))
 954:              {
 955:                  // <service id="40" allowProcessing="true" arabicName="رفع خط" />
 956:                  if (serviceRequest.Number >= 25410000
 957:                      && serviceRequest.Number <= 25419999
 958:                      && serviceRequest.ServiceId == 40
 959:                      && (serviceRequest.RequestDateTime.Year == 2014 || serviceRequest.RequestDateTime.Year == 2015 || serviceRequest.RequestDateTime.Year == 2016)) processingIsAllowed = false;
 960:                  else
 961:                  {
 962:                  }
 963:              }
 964:              else
 965:              {
 966:                  processingIsAllowed = false;
 967:              }
 968:   
 969:              return processingIsAllowed;
 970:          }
 971:   
 972:          ////////////////////////////////////////////////////////////////////////////
 973:   
 974:          /// <summary>
 975:          ///
 976:          /// </summary>
 977:          public static bool ServiceProcessingIsAllowed(string service)
 978:          {
 979:              // below: this skips processing some services due to misc problems
 980:              bool processingIsAllowed;
 981:   
 982:              if (!string.IsNullOrEmpty(service))
 983:              {
 984:                  if (Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceList.Contains(service)) processingIsAllowed = false;
 985:                  else processingIsAllowed = true;
 986:              }
 987:              else processingIsAllowed = true;
 988:   
 989:              return processingIsAllowed;
 990:          }
 991:   
 992:          ////////////////////////////////////////////////////////////////////////////
 993:          ////////////////////////////////////////////////////////////////////////////
 994:   
 995:          /// <summary>
 996:          ///
 997:          /// </summary>
 998:          public static bool TelegramUserCanReadFind(string chatId, int userId)
 999:          {
1000:              bool isAllowed;
1001:   
1002:              if (userId != 0)
1003:              {
1004:                  isAllowed = true;
1005:              }
1006:              else isAllowed = false;
1007:   
1008:              return isAllowed;
1009:          }
1010:   
1011:          ////////////////////////////////////////////////////////////////////////////
1012:          ////////////////////////////////////////////////////////////////////////////    
1013:      }
1014:   
1015:      ////////////////////////////////////////////////////////////////////////////
1016:      ////////////////////////////////////////////////////////////////////////////   
1017:  }