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

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