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

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