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

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