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

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 Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Data;
   3:  using System.Collections.Generic;
   4:  using System.Linq;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Business
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Authority support class of Next Generation Network'a (NGN's) business model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2006-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public class Authority
  28:      {
  29:          private static Ia.Ngn.Cl.Model.Staff superUserStaff;
  30:   
  31:          public enum PersistentStorageFunction { Create = 1, Read, Update, Delete };
  32:   
  33:          ////////////////////////////////////////////////////////////////////////////
  34:   
  35:          /// <summary>
  36:          ///
  37:          /// </summary>
  38:          public Authority() { }
  39:   
  40:          ////////////////////////////////////////////////////////////////////////////    
  41:   
  42:          /// <summary>
  43:          ///
  44:          /// </summary>
  45:          public static List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> StaffFrameworkListOfAllowedReportAssignsByStaff(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
  46:          {
  47:              List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework> staffList, frameworkList, specialList, special2List, list;
  48:   
  49:              // staff list:
  50:              if (staff.Subordinates != null && staff.Colleagues != null && staff.Colleagues.Count != 0)
  51:              {
  52:                  if (staff.Head != null)
  53:                  {
  54:                      staffList = (from s in staff.Colleagues.Union(staff.Subordinates).Concat(new[] { staff.Head })
  55:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  56:                                   {
  57:                                       Guid = s.UserId,
  58:                                       IsStaff = true,
  59:                                       Name = s.FirstAndMiddleName
  60:                                   }
  61:                  ).ToList();
  62:                  }
  63:                  else
  64:                  {
  65:                      staffList = (from s in staff.Colleagues.Union(staff.Subordinates)
  66:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  67:                                   {
  68:                                       Guid = s.UserId,
  69:                                       IsStaff = true,
  70:                                       Name = s.FirstAndMiddleName
  71:                                   }
  72:                  ).ToList();
  73:                  }
  74:              }
  75:              else if (staff.Colleagues != null && staff.Colleagues.Count != 0)
  76:              {
  77:                  if (staff.Head != null)
  78:                  {
  79:                      staffList = (from s in staff.Colleagues.Concat(new[] { staff.Head })
  80:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  81:                                   {
  82:                                       Guid = s.UserId,
  83:                                       IsStaff = true,
  84:                                       Name = s.FirstAndMiddleName
  85:                                   }
  86:                  ).ToList();
  87:                  }
  88:                  else
  89:                  {
  90:                      staffList = (from s in staff.Colleagues
  91:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
  92:                                   {
  93:                                       Guid = s.UserId,
  94:                                       IsStaff = true,
  95:                                       Name = s.FirstAndMiddleName
  96:                                   }
  97:                  ).ToList();
  98:                  }
  99:              }
 100:              else
 101:              {
 102:                  if (staff.Head != null)
 103:                  {
 104:                      staffList = (from s in (new[] { staff.Head })
 105:                                   select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 106:                                   {
 107:                                       Guid = s.UserId,
 108:                                       IsStaff = true,
 109:                                       Name = s.FirstAndMiddleName
 110:                                   }
 111:                                   ).ToList();
 112:                  }
 113:                  else
 114:                  {
 115:                      staffList = new List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework>();
 116:                  }
 117:              }
 118:   
 119:              // framework list: framework descendants, siblings and uncles (for head staff only)
 120:              if (staff.Framework.Parent != null)
 121:              {
 122:                  if (staff.Framework.Descendants != null && staff.Framework.Siblings != null)
 123:                  {
 124:                      if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 125:                      {
 126:                          frameworkList = (from f in staff.Framework.Siblings.Union(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:                                               Guid = f.Guid,
 130:                                               IsFramework = true,
 131:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 132:                                           }
 133:                                           ).OrderBy(c => c.Guid).ToList();
 134:                      }
 135:                      else
 136:                      {
 137:                          frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Concat(new[] { staff.Framework.Parent })
 138:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 139:                                           {
 140:                                               Guid = f.Guid,
 141:                                               IsFramework = true,
 142:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 143:                                           }
 144:                                           ).OrderBy(c => c.Guid).ToList();
 145:                      }
 146:                  }
 147:                  else if (staff.Framework.Descendants != null)
 148:                  {
 149:                      if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 150:                      {
 151:                          frameworkList = (from f in staff.Framework.Descendants.Union(staff.Framework.Parent.Siblings).Concat(new[] { staff.Framework.Parent })
 152:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 153:                                           {
 154:                                               Guid = f.Guid,
 155:                                               IsFramework = true,
 156:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 157:                                           }
 158:                                           ).OrderBy(c => c.Guid).ToList();
 159:                      }
 160:                      else
 161:                      {
 162:                          frameworkList = (from f in staff.Framework.Descendants.Concat(new[] { staff.Framework.Parent })
 163:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 164:                                           {
 165:                                               Guid = f.Guid,
 166:                                               IsFramework = true,
 167:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 168:                                           }
 169:                                           ).OrderBy(c => c.Guid).ToList();
 170:                      }
 171:                  }
 172:                  else
 173:                  {
 174:                      if (staff.Framework.Parent.Siblings != null && staff.IsHead)
 175:                      {
 176:                          frameworkList = (from f in staff.Framework.Parent.Siblings.Concat(new[] { staff.Framework.Parent })
 177:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 178:                                           {
 179:                                               Guid = f.Guid,
 180:                                               IsFramework = true,
 181:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 182:                                           }
 183:                                           ).OrderBy(c => c.Guid).ToList();
 184:                      }
 185:                      else
 186:                      {
 187:                          frameworkList = (from f in (new[] { staff.Framework.Parent })
 188:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 189:                                           {
 190:                                               Guid = f.Guid,
 191:                                               IsFramework = true,
 192:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 193:                                           }
 194:                                           ).OrderBy(c => c.Guid).ToList();
 195:                      }
 196:                  }
 197:              }
 198:              else
 199:              {
 200:                  if (staff.Framework.Descendants != null)
 201:                  {
 202:                      if (staff.IsHead)
 203:                      {
 204:                          frameworkList = (from f in staff.Framework.Descendants
 205:                                           select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 206:                                           {
 207:                                               Guid = f.Guid,
 208:                                               IsFramework = true,
 209:                                               Name = f.FullyQualifiedArabicName //.ArabicName
 210:                                           }
 211:                                           ).OrderBy(c => c.Guid).ToList();
 212:                      }
 213:                      else
 214:                      {
 215:                          frameworkList = new List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework>();
 216:                      }
 217:                  }
 218:                  else
 219:                  {
 220:                      frameworkList = new List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework>();
 221:                  }
 222:              }
 223:   
 224:   
 225:              // special list: list of special administrative assignments to certain staff and frameworks
 226:              if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة")
 227:              {
 228:                  specialList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 229:                                 where
 230:                                 f.FullyQualifiedArabicName == "وزارة شؤون الخدمات | قطاع الاتصالات والخدمات المساندة | إدارة صيانة الشبكة الهاتفية | مراقبة الصيانة | قسم الصيانة"
 231:                                 || f.FullyQualifiedArabicName == "نوكيا"
 232:                                 || f.FullyQualifiedArabicName == "هواوي"
 233:                                 || (f.FullyQualifiedArabicName.Contains("قسم الصيانة وتركيبات الهاتف") && f.FullyQualifiedArabicName.Contains("وزارة شؤون الخدمات | قطاع خدمات المشتركين"))
 234:   
 235:                                 select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 236:                                 {
 237:                                     Guid = f.Guid,
 238:                                     IsFramework = true,
 239:                                     Name = f.FullyQualifiedArabicName //.ArabicName
 240:                                 }
 241:                                       ).OrderBy(c => c.Guid).ToList();
 242:              }
 243:              else
 244:              {
 245:                  specialList = new List<Ia.Ngn.Cl.Model.Data.Administration.StaffFramework>();
 246:              }
 247:   
 248:              // special: ability to assign to report creator
 249:              special2List = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList
 250:                              join s in Ia.Ngn.Cl.Model.Data.Staff.List on f.Id equals s.Framework.Id
 251:                              where s.UserId == report.UserId
 252:                              select new Ia.Ngn.Cl.Model.Data.Administration.StaffFramework
 253:                              {
 254:                                  Guid = f.Guid,
 255:                                  IsFramework = true,
 256:                                  Name = f.FullyQualifiedArabicName //.ArabicName
 257:                              }
 258:                                   ).OrderBy(c => c.Guid).ToList();
 259:   
 260:   
 261:   
 262:              list = staffList.Union(frameworkList).Union(specialList).Union(special2List).ToList();
 263:   
 264:              return list;
 265:          }
 266:   
 267:          ////////////////////////////////////////////////////////////////////////////    
 268:   
 269:          /// <summary>
 270:          ///
 271:          /// </summary>
 272:          public static List<Guid> FieldFrameworkAndStaffGuidList
 273:          {
 274:              get
 275:              {
 276:                  List<Guid> frameworkList, staffList;
 277:   
 278:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where (f.FullyQualifiedArabicName.Contains("قسم الصيانة وتركيبات الهاتف") && f.FullyQualifiedArabicName.Contains("وزارة شؤون الخدمات | قطاع خدمات المشتركين")) select f.Guid).ToList();
 279:   
 280:                  // below: fix later
 281:                  try
 282:                  {
 283:                      staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where frameworkList.Contains(s.Framework.Guid) || s.Framework.Ancestors.Any(u => frameworkList.Contains(u.Guid)) select s.UserId).ToList();
 284:                  }
 285:                  catch (Exception e)
 286:                  {
 287:                      staffList = new List<Guid>();
 288:                  }
 289:   
 290:                  return frameworkList.Union(staffList).ToList();
 291:              }
 292:          }
 293:   
 294:          ////////////////////////////////////////////////////////////////////////////    
 295:   
 296:          /// <summary>
 297:          ///
 298:          /// </summary>
 299:          public static List<Guid> TnmdFrameworkAndStaffGuidList
 300:          {
 301:              get
 302:              {
 303:                  List<Guid> frameworkList, staffList;
 304:   
 305:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "وزارة شؤون الخدمات | قطاع الاتصالات والخدمات المساندة | إدارة صيانة الشبكة الهاتفية | مراقبة الصيانة | قسم الصيانة" select f.Guid).ToList();
 306:   
 307:                  // below: fix later
 308:                  try
 309:                  {
 310:                      staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where frameworkList.Contains(s.Framework.Guid) || s.Framework.Ancestors.Any(u => frameworkList.Contains(u.Guid)) select s.UserId).ToList();
 311:                  }
 312:                  catch (Exception e)
 313:                  {
 314:                      staffList = new List<Guid>();
 315:                  }
 316:   
 317:                  return frameworkList.Union(staffList).ToList();
 318:              }
 319:          }
 320:   
 321:          ////////////////////////////////////////////////////////////////////////////    
 322:   
 323:          /// <summary>
 324:          ///
 325:          /// </summary>
 326:          public static List<Guid> NokiaFrameworkAndStaffGuidList
 327:          {
 328:              get
 329:              {
 330:                  List<Guid> frameworkList, staffList;
 331:   
 332:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "نوكيا" select f.Guid).ToList();
 333:   
 334:                  // below: fix later
 335:                  try
 336:                  {
 337:                      staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where frameworkList.Contains(s.Framework.Guid) || s.Framework.Ancestors.Any(u => frameworkList.Contains(u.Guid)) select s.UserId).ToList();
 338:                  }
 339:                  catch (Exception e)
 340:                  {
 341:                      staffList = new List<Guid>();
 342:                  }
 343:   
 344:                  return frameworkList.Union(staffList).ToList();
 345:              }
 346:          }
 347:   
 348:          ////////////////////////////////////////////////////////////////////////////    
 349:   
 350:          /// <summary>
 351:          ///
 352:          /// </summary>
 353:          public static List<Guid> HuaweiFrameworkAndStaffGuidList
 354:          {
 355:              get
 356:              {
 357:                  List<Guid> frameworkList, staffList;
 358:   
 359:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "هواوي" select f.Guid).ToList();
 360:   
 361:                  // below: fix later
 362:                  try
 363:                  {
 364:                      staffList = (from s in Ia.Ngn.Cl.Model.Data.Staff.List where frameworkList.Contains(s.Framework.Guid) || s.Framework.Ancestors.Any(u => frameworkList.Contains(u.Guid)) select s.UserId).ToList();
 365:                  }
 366:                  catch (Exception e)
 367:                  {
 368:                      staffList = new List<Guid>();
 369:                  }
 370:   
 371:                  return frameworkList.Union(staffList).ToList();
 372:              }
 373:          }
 374:   
 375:          ////////////////////////////////////////////////////////////////////////////    
 376:   
 377:          /// <summary>
 378:          ///
 379:          /// </summary>
 380:          public static bool StaffCanCreateReadUpdateDeleteReport(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 381:          {
 382:              bool isAllowed;
 383:   
 384:              if (staff != null)
 385:              {
 386:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 387:                  else
 388:                  {
 389:                      if (persistentStorageFunction == PersistentStorageFunction.Delete)
 390:                      {
 391:                          /*
 392:                          // below: a report can only be deleted by:
 393:                          // - one of the heads of the reporter.
 394:                          // - the reporter if he is a head
 395:  
 396:                          if (report.LastReportHistory == null && staff.UserId == report.UserId && staff.IsHead) isAllowed = true;
 397:                          else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId && staff.IsHead) isAllowed = true;
 398:                          else if (report.LastReportHistory == null && staff.IsHead) isAllowed = true;
 399:                          else if (staff.Subordinates != null)
 400:                          {
 401:                              if (report.LastReportHistory != null) isAllowed = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 402:                              else isAllowed = staff.Subordinates.Any(i => i.UserId == report.UserId);
 403:                          }
 404:                          else isAllowed = false;
 405:                          */
 406:   
 407:                          isAllowed = false; // reports can't be deleted by staff other than super user
 408:                      }
 409:                      else
 410:                      {
 411:                          /*
 412:                          // below: a report can be CRUD if
 413:                          // - last report does not exist
 414:                          // - last report exists and its UserId is same as staffs
 415:                          // - report owner is subordinate of staff
 416:                          // - report framework is within users frameworks
 417:  
 418:                          if (report.ReportHistories.Count == 0)
 419:                          {
 420:                              isAllowed = report.LastReportHistory.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 421:  
 422:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId))
 423:                              {
 424:                                  isAllowed = staff.Framework.Guid == report.LastReportHistory.UserId
 425:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.LastReportHistory.UserId);
 426:                              }
 427:                          }
 428:                          else
 429:                          {
 430:                              isAllowed = true; // report.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.UserId);
 431:  
 432:                              / *
 433:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId))
 434:                              {
 435:                                  isAllowed = staff.Framework.Guid == report.UserId 
 436:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.UserId);
 437:                              }
 438:                               * /
 439:                          }
 440:                          */
 441:   
 442:                          isAllowed = false; // undefined CRU
 443:                      }
 444:                  }
 445:              }
 446:              else isAllowed = false;
 447:   
 448:              return isAllowed;
 449:          }
 450:   
 451:          ////////////////////////////////////////////////////////////////////////////    
 452:   
 453:          /// <summary>
 454:          ///
 455:          /// </summary>
 456:          public static bool StaffCanSendFieldTnmdSupplierWorkorderEmail(Ia.Ngn.Cl.Model.Staff staff)
 457:          {
 458:              bool isAllowed;
 459:   
 460:              if (staff != null)
 461:              {
 462:                  if (staff.IsHead) isAllowed = true;
 463:                  else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
 464:                  else isAllowed = false;
 465:              }
 466:              else isAllowed = false;
 467:   
 468:              return isAllowed;
 469:          }
 470:   
 471:          ////////////////////////////////////////////////////////////////////////////    
 472:   
 473:          /// <summary>
 474:          ///
 475:          /// </summary>
 476:          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)
 477:          {
 478:              // below: I have to pass both Report and ReportHistory objects separately
 479:   
 480:              bool isAllowed;
 481:   
 482:              if (staff != null)
 483:              {
 484:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 485:                  else
 486:                  {
 487:                      if (function == PersistentStorageFunction.Delete)
 488:                      {
 489:                          // below: a report history can only be deleted by:
 490:                          // - one of the heads of the history user
 491:                          // - the history user if he is a head
 492:   
 493:                          /*
 494:                          if (reportHistory != null)
 495:                          {
 496:                              if (reportHistory.Report.ReportHistories.Max(r => r.Id) != reportHistory.Id) isAllowed = false;
 497:                              else
 498:                              {
 499:                                  if (staff.UserId == reportHistory.UserId && staff.IsHead) isAllowed = true;
 500:                                  else if (staff.Subordinates != null) isAllowed = staff.Subordinates.Any(i => i.UserId == reportHistory.UserId);
 501:                                  else isAllowed = false;
 502:                              }
 503:                          }
 504:                          else isAllowed = false;
 505:                          */
 506:   
 507:                          isAllowed = false; // reports history can't be deleted by staff other than super user
 508:                      }
 509:                      else if (function == PersistentStorageFunction.Create)
 510:                      {
 511:                          // below: for create reportHistory must be null
 512:   
 513:                          // below: a report history can be created if:
 514:                          // - report userid is subordinate of staff
 515:                          // - report history userid framework is within staff frameworks
 516:   
 517:                          if (report != null && reportHistory == null)
 518:                          {
 519:                              if (report.ReportHistories.Count == 0 && staff.UserId == report.UserId) isAllowed = true;
 520:                              else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId) isAllowed = true;
 521:                              else if (report.ReportHistories.Count == 0 && report.StatusIsOpen) isAllowed = true;
 522:                              else if (report.LastReportHistory != null && staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId)) isAllowed = true;
 523:                              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;
 524:                              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;
 525:                              else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
 526:                              else isAllowed = false;
 527:                          }
 528:                          else isAllowed = false;
 529:                      }
 530:                      else
 531:                      {
 532:                          // below: a report history can be read, and updated if:
 533:                          // - report history UserId is same as staff's
 534:                          // - report userid is subordinate of staff
 535:                          // - report history userid framework is within staff frameworks
 536:   
 537:                          if (reportHistory != null)
 538:                          {
 539:                              if (staff.UserId == reportHistory.UserId) isAllowed = true;
 540:                              else if (staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == reportHistory.UserId)) isAllowed = true;
 541:                              else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(reportHistory.UserId))
 542:                              {
 543:                                  if (staff.Framework.Guid == reportHistory.UserId || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == reportHistory.UserId)) isAllowed = true;
 544:                                  else isAllowed = false;
 545:                              }
 546:                              else isAllowed = false;
 547:                          }
 548:                          else isAllowed = false;
 549:                      }
 550:                  }
 551:              }
 552:              else isAllowed = false;
 553:   
 554:              return isAllowed;
 555:          }
 556:   
 557:          ////////////////////////////////////////////////////////////////////////////    
 558:   
 559:          /// <summary>
 560:          ///
 561:          /// </summary>
 562:          public static bool StaffCanReopenClosedReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 563:          {
 564:              return StaffCanCloseReport(report, staff);
 565:          }
 566:   
 567:          ////////////////////////////////////////////////////////////////////////////    
 568:   
 569:          /// <summary>
 570:          ///
 571:          /// </summary>
 572:          public static bool StaffCanCloseReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 573:          {
 574:              bool canClose;
 575:   
 576:              // below: a report can be closed if
 577:   
 578:              if (staff != null)
 579:              {
 580:                  if (StaffIsSuperUser(staff)) canClose = true;
 581:                  //else if (FrameworkCanCloseReport(staff.Framework)) canClose = true; // make dedicated users to check with subscribers if reports are resolved
 582:                  else
 583:                  {
 584:                      // - there must be a history
 585:                      if (report.LastReportHistory != null)
 586:                      {
 587:                          /*
 588:                          // - the closer staff is himself, is the head or one of the heads of the last report staff
 589:                          if (staff.Subordinates != null)
 590:                          {
 591:                              if (staff.UserId == report.LastReportHistory.UserId) canClose = true;
 592:                              else canClose = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 593:                          }
 594:                          else*/
 595:                          if (staff.IsHead == true && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") canClose = true;
 596:                          else if (staff.Framework.FullyQualifiedArabicName.Contains("قسم الفحص والشكاوى")
 597:                              && staff.Framework.FullyQualifiedArabicName.Contains("وزارة شؤون الخدمات | قطاع خدمات المشتركين")
 598:                              && (staff.UserId == report.UserId || staff.Subordinates.Any(i => i.UserId == report.UserId))
 599:                              ) canClose = true;
 600:                          else canClose = false;
 601:                      }
 602:                      else canClose = false;
 603:                  }
 604:   
 605:              }
 606:              else canClose = false;
 607:   
 608:              return canClose;
 609:          }
 610:   
 611:          ////////////////////////////////////////////////////////////////////////////    
 612:   
 613:          /// <summary>
 614:          ///
 615:          /// </summary>
 616:          public static bool StaffCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 617:          {
 618:              bool isAllowed;
 619:   
 620:              if (staff != null)
 621:              {
 622:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
 623:                  {
 624:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 625:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 626:                      else isAllowed = false;
 627:                  }
 628:                  else
 629:                  {
 630:                      isAllowed = false;
 631:                  }
 632:              }
 633:              else isAllowed = false;
 634:   
 635:              return isAllowed;
 636:          }
 637:   
 638:          ////////////////////////////////////////////////////////////////////////////
 639:   
 640:          /// <summary>
 641:          ///
 642:          /// </summary>
 643:          public static bool StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 644:          {
 645:              bool isAllowed;
 646:   
 647:              if (staffContact != null)
 648:              {
 649:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 650:                  else if (function == PersistentStorageFunction.Read)
 651:                  {
 652:                      isAllowed = true;
 653:                  }
 654:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 655:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 656:                  else
 657:                  {
 658:                      isAllowed = false;
 659:                  }
 660:              }
 661:              else isAllowed = false;
 662:   
 663:              return isAllowed;
 664:          }
 665:   
 666:          ////////////////////////////////////////////////////////////////////////////
 667:   
 668:          /// <summary>
 669:          ///
 670:          /// </summary>
 671:          public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 672:          {
 673:              bool isAllowed;
 674:   
 675:              if (staffContact != null)
 676:              {
 677:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 678:                  else if (function == PersistentStorageFunction.Read)
 679:                  {
 680:                      isAllowed = true;
 681:                  }
 682:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 683:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 684:                  else
 685:                  {
 686:                      isAllowed = false;
 687:                  }
 688:              }
 689:              else isAllowed = false;
 690:   
 691:              return isAllowed;
 692:          }
 693:   
 694:          ////////////////////////////////////////////////////////////////////////////
 695:   
 696:          /// <summary>
 697:          ///
 698:          /// </summary>
 699:          public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 700:          {
 701:              bool isAllowed;
 702:   
 703:              if (staffContact != null)
 704:              {
 705:                  if (function == PersistentStorageFunction.Create)
 706:                  {
 707:                      isAllowed = true;
 708:                  }
 709:                  else if (function == PersistentStorageFunction.Read)
 710:                  {
 711:                      isAllowed = true;
 712:                  }
 713:                  else if (function == PersistentStorageFunction.Update)
 714:                  {
 715:                      isAllowed = false;
 716:                  }
 717:                  else if (function == PersistentStorageFunction.Delete)
 718:                  {
 719:                      isAllowed = false;
 720:                  }
 721:                  else
 722:                  {
 723:                      isAllowed = false;
 724:                  }
 725:              }
 726:              else isAllowed = false;
 727:   
 728:              return isAllowed;
 729:          }
 730:   
 731:          ////////////////////////////////////////////////////////////////////////////
 732:          ////////////////////////////////////////////////////////////////////////////
 733:   
 734:          /// <summary>
 735:          ///
 736:          /// </summary>
 737:          public static bool StaffCanCreateReadUpdateDeleteServiceLineCard(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 738:          {
 739:              bool isAllowed;
 740:   
 741:              if (staff != null)
 742:              {
 743:                  if (function == PersistentStorageFunction.Create)
 744:                  {
 745:                      if (staff.IsHead) isAllowed = true;
 746:                      else isAllowed = false;
 747:                  }
 748:                  else if (function == PersistentStorageFunction.Read)
 749:                  {
 750:                      isAllowed = true;
 751:                  }
 752:                  else if (function == PersistentStorageFunction.Update)
 753:                  {
 754:                      if (staff.IsHead) isAllowed = true;
 755:                      else isAllowed = false;
 756:                  }
 757:                  else if (function == PersistentStorageFunction.Delete)
 758:                  {
 759:                      if (staff.IsHead) isAllowed = true;
 760:                      else isAllowed = false;
 761:                  }
 762:                  else
 763:                  {
 764:                      isAllowed = false;
 765:                  }
 766:              }
 767:              else isAllowed = false;
 768:   
 769:              return isAllowed;
 770:          }
 771:   
 772:          ////////////////////////////////////////////////////////////////////////////
 773:          ////////////////////////////////////////////////////////////////////////////
 774:   
 775:          /// <summary>
 776:          ///
 777:          /// </summary>
 778:          public static bool StaffCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 779:          {
 780:              bool isAllowed;
 781:   
 782:              if (staff != null)
 783:              {
 784:                  if (function == PersistentStorageFunction.Read)
 785:                  {
 786:                      isAllowed = true;
 787:                  }
 788:                  else if (function == PersistentStorageFunction.Update)
 789:                  {
 790:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 791:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 792:                      else isAllowed = false;
 793:                  }
 794:                  else
 795:                  {
 796:                      isAllowed = false;
 797:                  }
 798:              }
 799:              else isAllowed = false;
 800:   
 801:              return isAllowed;
 802:          }
 803:   
 804:          ////////////////////////////////////////////////////////////////////////////
 805:          ////////////////////////////////////////////////////////////////////////////
 806:   
 807:          /// <summary>
 808:          ///
 809:          /// </summary>
 810:          public static Ia.Ngn.Cl.Model.Data.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
 811:          {
 812:              get
 813:              {
 814:                  Ia.Ngn.Cl.Model.Data.Administration.Framework framework;
 815:   
 816:                  //framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "إدارة شبكة الألياف الضوئية" select f).FirstOrDefault(); //.SingleOrDefault();
 817:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "وزارة شؤون الخدمات" select f).FirstOrDefault(); //.SingleOrDefault();
 818:   
 819:                  return framework;
 820:              }
 821:          }
 822:   
 823:          ////////////////////////////////////////////////////////////////////////////
 824:   
 825:          /// <summary>
 826:          ///
 827:          /// </summary>
 828:          public static bool FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Data.Administration.Framework framework)
 829:          {
 830:              bool isResponsible;
 831:   
 832:              isResponsible = framework.ArabicName == "قسم الدعم الفني للشبكة";
 833:   
 834:              return isResponsible;
 835:          }
 836:   
 837:          ////////////////////////////////////////////////////////////////////////////
 838:   
 839:          /// <summary>
 840:          ///
 841:          /// </summary>
 842:          public static bool FrameworkCanCloseReport(Ia.Ngn.Cl.Model.Data.Administration.Framework framework)
 843:          {
 844:              bool canClose;
 845:   
 846:              canClose = framework.ArabicName == "قسم الدعم الفني للشبكة";
 847:   
 848:              return canClose;
 849:          }
 850:   
 851:          ////////////////////////////////////////////////////////////////////////////
 852:   
 853:          /// <summary>
 854:          ///
 855:          /// </summary>
 856:          public static bool StaffIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Staff staff)
 857:          {
 858:              bool isResponsible;
 859:   
 860:              isResponsible = FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(staff.Framework);
 861:   
 862:              return isResponsible;
 863:          }
 864:   
 865:          ////////////////////////////////////////////////////////////////////////////
 866:          ////////////////////////////////////////////////////////////////////////////
 867:   
 868:          /// <summary>
 869:          ///
 870:          /// </summary>
 871:          public static bool StaffIsSuperUser(Ia.Ngn.Cl.Model.Staff staff)
 872:          {
 873:              bool isSuperUser;
 874:   
 875:              if (staff != null) isSuperUser = staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة";
 876:              else isSuperUser = false;
 877:   
 878:              return isSuperUser;
 879:          }
 880:   
 881:          ////////////////////////////////////////////////////////////////////////////
 882:          ////////////////////////////////////////////////////////////////////////////
 883:   
 884:          /// <summary>
 885:          ///
 886:          /// </summary>
 887:          public static bool StaffContactCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 888:          {
 889:              bool isAllowed;
 890:   
 891:              if (staffContact != null)
 892:              {
 893:                  if (function == PersistentStorageFunction.Read)
 894:                  {
 895:                      if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 896:                      else if (staffContact.Staff != null && staffContact.Staff.IsHead && staffContact.Staff.FirstName == "جاسم") isAllowed = true;
 897:                      else isAllowed = false;
 898:                  }
 899:                  else if (function == PersistentStorageFunction.Update)
 900:                  {
 901:                      if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
 902:                      else if (staffContact.Staff != null && staffContact.Staff.IsHead && staffContact.Staff.FirstName == "جاسم") isAllowed = true;
 903:                      else isAllowed = false;
 904:                  }
 905:                  else
 906:                  {
 907:                      isAllowed = false;
 908:                  }
 909:              }
 910:              else isAllowed = false;
 911:   
 912:              return isAllowed;
 913:          }
 914:   
 915:          ////////////////////////////////////////////////////////////////////////////
 916:   
 917:          /// <summary>
 918:          ///
 919:          /// </summary>
 920:          public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 921:          {
 922:              bool isAllowed;
 923:   
 924:              if (staff != null)
 925:              {
 926:                  if (function == PersistentStorageFunction.Read)
 927:                  {
 928:                      isAllowed = true;
 929:                  }
 930:                  else if (function == PersistentStorageFunction.Update)
 931:                  {
 932:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 933:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 934:                      else if ((staff.IsHead || staff.FirstName == "علي") && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 935:                      else isAllowed = false;
 936:                  }
 937:                  else if (function == PersistentStorageFunction.Delete)
 938:                  {
 939:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 940:                      else isAllowed = false;
 941:                  }
 942:                  else
 943:                  {
 944:                      isAllowed = false;
 945:                  }
 946:              }
 947:              else isAllowed = false;
 948:   
 949:              return isAllowed;
 950:          }
 951:   
 952:          ////////////////////////////////////////////////////////////////////////////
 953:   
 954:          /// <summary>
 955:          ///
 956:          /// </summary>
 957:          public static bool StaffCanCreateReadUpdateAccessMail(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 958:          {
 959:              bool isAllowed;
 960:   
 961:              if (staff != null)
 962:              {
 963:                  if (function == PersistentStorageFunction.Read)
 964:                  {
 965:                      isAllowed = true;
 966:                  }
 967:                  else if (function == PersistentStorageFunction.Update)
 968:                  {
 969:                      if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 970:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 971:                      else isAllowed = false;
 972:                  }
 973:                  else
 974:                  {
 975:                      isAllowed = false;
 976:                  }
 977:              }
 978:              else isAllowed = false;
 979:   
 980:              return isAllowed;
 981:          }
 982:   
 983:          ////////////////////////////////////////////////////////////////////////////
 984:   
 985:          /// <summary>
 986:          ///
 987:          /// </summary>
 988:          public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Staff staff)
 989:          {
 990:              bool isAllowed;
 991:   
 992:              if (staff != null)
 993:              {
 994:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
 995:                  else if (staff.IsHead) isAllowed = true;
 996:                  else isAllowed = false;
 997:              }
 998:              else isAllowed = false;
 999:   
1000:              return isAllowed;
1001:          }
1002:   
1003:          ////////////////////////////////////////////////////////////////////////////
1004:   
1005:          /// <summary>
1006:          ///
1007:          /// </summary>
1008:          public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
1009:          {
1010:              bool isAllowed;
1011:   
1012:              if (staffContact != null)
1013:              {
1014:                  if (function == PersistentStorageFunction.Create)
1015:                  {
1016:                      isAllowed = true;
1017:                  }
1018:                  else if (function == PersistentStorageFunction.Read)
1019:                  {
1020:                      isAllowed = true;
1021:                  }
1022:                  else if (function == PersistentStorageFunction.Update)
1023:                  {
1024:                      isAllowed = false;
1025:                  }
1026:                  else if (function == PersistentStorageFunction.Delete)
1027:                  {
1028:                      isAllowed = false;
1029:                  }
1030:                  else
1031:                  {
1032:                      isAllowed = false;
1033:                  }
1034:              }
1035:              else isAllowed = false;
1036:   
1037:              return isAllowed;
1038:          }
1039:   
1040:          ////////////////////////////////////////////////////////////////////////////
1041:          ////////////////////////////////////////////////////////////////////////////
1042:   
1043:          /// <summary>
1044:          ///
1045:          /// </summary>
1046:          public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ngn.Cl.Model.Staff staff)
1047:          {
1048:              bool isAllowed;
1049:   
1050:              if (staff != null)
1051:              {
1052:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
1053:                  else isAllowed = false;
1054:              }
1055:              else isAllowed = false;
1056:   
1057:              return isAllowed;
1058:          }
1059:   
1060:          ////////////////////////////////////////////////////////////////////////////
1061:   
1062:          /// <summary>
1063:          ///
1064:          /// </summary>
1065:          public static bool StaffCanAccessAdministationFolder(Ia.Ngn.Cl.Model.Staff staff)
1066:          {
1067:              bool isAllowed;
1068:   
1069:              /*
1070:               * <allow roles="Application,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة"/>
1071:               * <deny users="*"/>
1072:               * <allow users="mohammad"/>
1073:               */
1074:   
1075:              string[] sp = { "Application", "إدارة شبكة الألياف الضوئية", "مراقبة خدمات الشبكة", "مراقبة الدعم الفنى للشبكة", "مراقبة تقنية المعلومات", "مراقبة تشغيل الشبكة", "قسم دعم تشغيل الشبكة" };
1076:   
1077:              if (staff != null)
1078:              {
1079:                  if (staff.IsHead && staff.FirstName == "جاسم") isAllowed = true;
1080:                  else if (staff.IsHead && staff.User.UserName == "mohammad") isAllowed = true;
1081:                  else if (sp.Contains(staff.Framework.ArabicName)) isAllowed = true;
1082:                  else isAllowed = false;
1083:              }
1084:              else isAllowed = false;
1085:   
1086:              return isAllowed;
1087:          }
1088:   
1089:          ////////////////////////////////////////////////////////////////////////////
1090:   
1091:          /// <summary>
1092:          ///
1093:          /// </summary>
1094:          public static bool StaffIsApplication(Ia.Ngn.Cl.Model.Staff staff)
1095:          {
1096:              bool isAllowed;
1097:   
1098:              if (staff != null)
1099:              {
1100:                  if (staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة") isAllowed = true;
1101:                  else isAllowed = false;
1102:              }
1103:              else isAllowed = false;
1104:   
1105:              return isAllowed;
1106:          }
1107:   
1108:          ////////////////////////////////////////////////////////////////////////////
1109:   
1110:          /// <summary>
1111:          ///
1112:          /// </summary>
1113:          public static bool StaffIsInCustomerServiceSector(Ia.Ngn.Cl.Model.Staff staff)
1114:          {
1115:              bool isAllowed;
1116:   
1117:              if (staff != null)
1118:              {
1119:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == "قطاع خدمات المشتركين")) isAllowed = true;
1120:                  else isAllowed = false;
1121:              }
1122:              else isAllowed = false;
1123:   
1124:              return isAllowed;
1125:          }
1126:   
1127:          ////////////////////////////////////////////////////////////////////////////
1128:   
1129:          /// <summary>
1130:          ///
1131:          /// </summary>
1132:          public static bool StaffIsInOpticalFiberNetworkDepartment(Ia.Ngn.Cl.Model.Staff staff)
1133:          {
1134:              bool isAllowed;
1135:   
1136:              if (staff != null)
1137:              {
1138:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == "إدارة شبكة الألياف الضوئية")) isAllowed = true;
1139:                  else isAllowed = false;
1140:              }
1141:              else isAllowed = false;
1142:   
1143:              return isAllowed;
1144:          }
1145:   
1146:          ////////////////////////////////////////////////////////////////////////////
1147:   
1148:          /// <summary>
1149:          ///
1150:          /// </summary>
1151:          public static bool StaffIsSupplier(Ia.Ngn.Cl.Model.Staff staff)
1152:          {
1153:              bool isAllowed;
1154:   
1155:              if (staff != null)
1156:              {
1157:                  if (staff.Framework.ArabicName == "نوكيا" || staff.Framework.ArabicName == "هواوي") isAllowed = true;
1158:                  else isAllowed = false;
1159:              }
1160:              else isAllowed = false;
1161:   
1162:              return isAllowed;
1163:          }
1164:   
1165:          ////////////////////////////////////////////////////////////////////////////
1166:   
1167:          /// <summary>
1168:          ///
1169:          /// </summary>
1170:          public static bool StaffIsInRole(Ia.Ngn.Cl.Model.Staff staff, string role)
1171:          {
1172:              bool isAllowed;
1173:   
1174:              if (staff != null)
1175:              {
1176:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == role)) isAllowed = true;
1177:                  else isAllowed = false;
1178:              }
1179:              else isAllowed = false;
1180:   
1181:              return isAllowed;
1182:          }
1183:   
1184:          ////////////////////////////////////////////////////////////////////////////
1185:          ////////////////////////////////////////////////////////////////////////////
1186:   
1187:          /// <summary>
1188:          ///
1189:          /// </summary>
1190:          public static List<Tuple<string, string>> EmailRecipientTupleList(string function)
1191:          {
1192:              List<Tuple<string, string>> recipientTupleList;
1193:   
1194:              recipientTupleList = new List<Tuple<string, string>>();
1195:   
1196:              switch (function)
1197:              {
1198:                  case "email-list-with-ont-list-provisioned-and-ready-but-do-not-exist-in-customer-department-database":
1199:                      {
1200:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1201:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1202:   
1203:                          break;
1204:                      }
1205:                  case "email-daily-ofn-status-report":
1206:                      {
1207:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1208:                          break;
1209:                      }
1210:                  case "email-weekly-ofn-statistics-report":
1211:                      {
1212:                          recipientTupleList.Add(new Tuple<string, string>("MOC Traffic Section", "traffic_section@yahoo.com"));
1213:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1214:                          //recipientTupleList.Add(new Tuple<string, string>("A. Obaidan", "6677221@gmail.com"));
1215:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1216:                          break;
1217:                      }
1218:                  case "email-monthly-ofn-statistics-report":
1219:                      {
1220:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1221:   
1222:                          break;
1223:                      }
1224:                  case "email-weekly-ofn-nokia-report":
1225:                      {
1226:                          recipientTupleList.Add(new Tuple<string, string>("O. Kandemir", "oguzhan.kandemir@nokia.com"));
1227:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1228:                          break;
1229:                      }
1230:                  case "email-weekly-ofn-huawei-report":
1231:                      {
1232:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1233:                          break;
1234:                      }
1235:                  default: break;
1236:              }
1237:   
1238:              return recipientTupleList;
1239:          }
1240:   
1241:          ////////////////////////////////////////////////////////////////////////////
1242:          ////////////////////////////////////////////////////////////////////////////
1243:   
1244:          /// <summary>
1245:          ///
1246:          /// </summary>
1247:          public static bool ServiceRequestIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
1248:          {
1249:              // below: this skips processing some service requests due to misc problems
1250:              bool processingIsAllowed;
1251:   
1252:              processingIsAllowed = true;
1253:   
1254:              // we will skip service order dates before 2004-01-01
1255:              if (serviceRequest.RequestDateTime > DateTime.Parse("2004-01-01"))
1256:              {
1257:                  // <service id="40" allowProcessing="true" arabicName="رفع خط" />
1258:                  if (serviceRequest.Number >= 25410000
1259:                      && serviceRequest.Number <= 25419999
1260:                      && serviceRequest.ServiceId == 40
1261:                      && (serviceRequest.RequestDateTime.Year == 2014 || serviceRequest.RequestDateTime.Year == 2015 || serviceRequest.RequestDateTime.Year == 2016)) processingIsAllowed = false;
1262:                  else
1263:                  {
1264:                  }
1265:              }
1266:              else
1267:              {
1268:                  processingIsAllowed = false;
1269:              }
1270:   
1271:              return processingIsAllowed;
1272:          }
1273:   
1274:          ////////////////////////////////////////////////////////////////////////////
1275:   
1276:          /// <summary>
1277:          ///
1278:          /// </summary>
1279:          public static bool ServiceProcessingIsAllowed(string service)
1280:          {
1281:              // below: this skips processing some services due to misc problems
1282:              bool processingIsAllowed;
1283:   
1284:              if (!string.IsNullOrEmpty(service))
1285:              {
1286:                  if (Ia.Ngn.Cl.Model.Data.ServiceExemption.ReadServiceList.Contains(service)) processingIsAllowed = false;
1287:                  else processingIsAllowed = true;
1288:              }
1289:              else processingIsAllowed = true;
1290:   
1291:              return processingIsAllowed;
1292:          }
1293:   
1294:          ////////////////////////////////////////////////////////////////////////////
1295:          ////////////////////////////////////////////////////////////////////////////
1296:   
1297:          /// <summary>
1298:          ///
1299:          /// </summary>
1300:          public static bool TelegramUserCanReadFind(string chatId, int userId)
1301:          {
1302:              bool isAllowed;
1303:   
1304:              if (userId != 0)
1305:              {
1306:                  isAllowed = true;
1307:              }
1308:              else isAllowed = false;
1309:   
1310:              return isAllowed;
1311:          }
1312:   
1313:          ////////////////////////////////////////////////////////////////////////////    
1314:   
1315:          /// <summary>
1316:          ///
1317:          /// </summary>
1318:          public static bool NumberIsWithinStaffSiteDomainList(Ia.Ngn.Cl.Model.Staff staff, string service)
1319:          {
1320:              bool isWithin;
1321:   
1322:              if (staff != null)
1323:              {
1324:                  if (staff.Framework != null)
1325:                  {
1326:                      if (staff.Framework.Site != null)
1327:                      {
1328:                          if (staff.Framework.Site.DomainList.Any(u => service.StartsWith(u.ToString()))) isWithin = true;
1329:                          else isWithin = false;
1330:                      }
1331:                      else isWithin = true; // will allow number for staff.Framework.Site == null
1332:                  }
1333:                  else isWithin = false;
1334:              }
1335:              else isWithin = true; // I will allow for null staff because the function is used from systems that do not utilize ASP.NET membership like telegram and email.
1336:   
1337:              return true;// isWithin; debugging. temp
1338:          }
1339:   
1340:          ////////////////////////////////////////////////////////////////////////////    
1341:   
1342:          /// <summary>
1343:          ///
1344:          /// </summary>
1345:          public static bool AccessNameIsWithinStaffSiteAreaSymbolList(Ia.Ngn.Cl.Model.Staff staff, string accessName)
1346:          {
1347:              bool isWithin;
1348:   
1349:              if (staff != null)
1350:              {
1351:                  if (staff.Framework != null)
1352:                  {
1353:                      if (staff.Framework.Site != null)
1354:                      {
1355:                          if (staff.Framework.Site.AreaSymbolList.Any(u => accessName.StartsWith(u.ToString()))) isWithin = true;
1356:                          else isWithin = false;
1357:                      }
1358:                      else isWithin = true; // will allow number for staff.Framework.Site == null
1359:                  }
1360:                  else isWithin = false;
1361:              }
1362:              else isWithin = true; // I will allow for null staff because the function is used from systems that do not utilize ASP.NET membership like telegram and email.
1363:   
1364:              return true;// isWithin; debugging. temp
1365:          }
1366:   
1367:          ////////////////////////////////////////////////////////////////////////////
1368:          ////////////////////////////////////////////////////////////////////////////    
1369:      }
1370:   
1371:      ////////////////////////////////////////////////////////////////////////////
1372:      ////////////////////////////////////////////////////////////////////////////   
1373:  }