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

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-2020 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, special3List, special4List, 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.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 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.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 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.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 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.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 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.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 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:              // list of all staff members already report history excluding self
 325:              if (report.ReportHistories != null && report.ReportHistories.Count > 0)
 326:              {
 327:                  special3List = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 328:                                  where (report.ReportHistories.Any(u => u.UserId == s.UserId)) && staff.UserId != s.UserId
 329:                                  select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 330:                                  {
 331:                                      Guid = s.UserId,
 332:                                      IsStaff = true,
 333:                                      Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 334:                                  }
 335:                                       ).OrderBy(c => c.Guid).ToList();
 336:              }
 337:              else
 338:              {
 339:                  special3List = new List<Ia.Ngn.Cl.Model.Business.Administration.StaffFramework>();
 340:              }
 341:   
 342:              // list of staff member who created report excluding self
 343:              special4List = (from s in Ia.Ngn.Cl.Model.Data.Staff.List
 344:                              where report.UserId == s.UserId && staff.UserId != s.UserId
 345:                              select new Ia.Ngn.Cl.Model.Business.Administration.StaffFramework
 346:                              {
 347:                                  Guid = s.UserId,
 348:                                  IsStaff = true,
 349:                                  Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
 350:                              }
 351:                                   ).OrderBy(c => c.Guid).ToList();
 352:   
 353:              list = staffList.Union(frameworkList).Union(specialList).Union(special2List).Union(special3List).Union(special4List).ToList();
 354:   
 355:              list = list.GroupBy(u => u.Guid).Select(u => u.FirstOrDefault()).ToList(); // returns distinct records
 356:   
 357:              return list.OrderBy(c => c.IsFramework).ToList();
 358:          }
 359:   
 360:          ////////////////////////////////////////////////////////////////////////////    
 361:   
 362:          /// <summary>
 363:          ///
 364:          /// </summary>
 365:          public static List<Guid> FieldFrameworkAndStaffGuidList
 366:          {
 367:              get
 368:              {
 369:                  List<Guid> frameworkList, staffList;
 370:   
 371:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where (f.FullyQualifiedArabicName.Contains("قسم الصيانة وتركيبات الهاتف") && f.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع خدمات المشتركين")) select f.Guid).ToList();
 372:   
 373:                  // below: fix later
 374:                  try
 375:                  {
 376:                      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();
 377:                  }
 378:                  catch (Exception)// e)
 379:                  {
 380:                      staffList = new List<Guid>();
 381:                  }
 382:   
 383:                  return frameworkList.Union(staffList).ToList();
 384:              }
 385:          }
 386:   
 387:          ////////////////////////////////////////////////////////////////////////////    
 388:   
 389:          /// <summary>
 390:          ///
 391:          /// </summary>
 392:          public static List<Guid> TnmdFrameworkAndStaffGuidList
 393:          {
 394:              get
 395:              {
 396:                  List<Guid> frameworkList, staffList;
 397:   
 398:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "وزارة الإتصالات وتكنولوجيا المعلومات | قطاع الاتصالات والخدمات المساندة | إدارة صيانة الشبكة الهاتفية | مراقبة الصيانة | قسم الصيانة" select f.Guid).ToList();
 399:   
 400:                  // below: fix later
 401:                  try
 402:                  {
 403:                      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();
 404:                  }
 405:                  catch (Exception)// e)
 406:                  {
 407:                      staffList = new List<Guid>();
 408:                  }
 409:   
 410:                  return frameworkList.Union(staffList).ToList();
 411:              }
 412:          }
 413:   
 414:          ////////////////////////////////////////////////////////////////////////////    
 415:   
 416:          /// <summary>
 417:          ///
 418:          /// </summary>
 419:          public static List<Guid> NokiaFrameworkAndStaffGuidList
 420:          {
 421:              get
 422:              {
 423:                  List<Guid> frameworkList, staffList;
 424:   
 425:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "نوكيا" select f.Guid).ToList();
 426:   
 427:                  // below: fix later
 428:                  try
 429:                  {
 430:                      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();
 431:                  }
 432:                  catch (Exception)// e)
 433:                  {
 434:                      staffList = new List<Guid>();
 435:                  }
 436:   
 437:                  return frameworkList.Union(staffList).ToList();
 438:              }
 439:          }
 440:   
 441:          ////////////////////////////////////////////////////////////////////////////    
 442:   
 443:          /// <summary>
 444:          ///
 445:          /// </summary>
 446:          public static List<Guid> HuaweiFrameworkAndStaffGuidList
 447:          {
 448:              get
 449:              {
 450:                  List<Guid> frameworkList, staffList;
 451:   
 452:                  frameworkList = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.FullyQualifiedArabicName == "هواوي" select f.Guid).ToList();
 453:   
 454:                  // below: fix later
 455:                  try
 456:                  {
 457:                      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();
 458:                  }
 459:                  catch (Exception)// e)
 460:                  {
 461:                      staffList = new List<Guid>();
 462:                  }
 463:   
 464:                  return frameworkList.Union(staffList).ToList();
 465:              }
 466:          }
 467:   
 468:          ////////////////////////////////////////////////////////////////////////////    
 469:   
 470:          /// <summary>
 471:          ///
 472:          /// </summary>
 473:          public static bool StaffCanCreateReadUpdateDeleteReport(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 474:          {
 475:              bool isAllowed;
 476:   
 477:              if (staff != null)
 478:              {
 479:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 480:                  else
 481:                  {
 482:                      if (persistentStorageFunction == PersistentStorageFunction.Delete)
 483:                      {
 484:                          /*
 485:                          // below: a report can only be deleted by:
 486:                          // - one of the heads of the reporter.
 487:                          // - the reporter if he is a head
 488:  
 489:                          if (report.LastReportHistory == null && staff.UserId == report.UserId && staff.IsHead) isAllowed = true;
 490:                          else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId && staff.IsHead) isAllowed = true;
 491:                          else if (report.LastReportHistory == null && staff.IsHead) isAllowed = true;
 492:                          else if (staff.Subordinates != null)
 493:                          {
 494:                              if (report.LastReportHistory != null) isAllowed = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 495:                              else isAllowed = staff.Subordinates.Any(i => i.UserId == report.UserId);
 496:                          }
 497:                          else isAllowed = false;
 498:                          */
 499:   
 500:                          isAllowed = false; // reports can't be deleted by staff other than super user
 501:                      }
 502:                      else
 503:                      {
 504:                          /*
 505:                          // below: a report can be CRUD if
 506:                          // - last report does not exist
 507:                          // - last report exists and its UserId is same as staffs
 508:                          // - report owner is subordinate of staff
 509:                          // - report framework is within users frameworks
 510:  
 511:                          if (report.ReportHistories.Count == 0)
 512:                          {
 513:                              isAllowed = report.LastReportHistory.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId);
 514:  
 515:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.LastReportHistory.UserId))
 516:                              {
 517:                                  isAllowed = staff.Framework.Guid == report.LastReportHistory.UserId
 518:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.LastReportHistory.UserId);
 519:                              }
 520:                          }
 521:                          else
 522:                          {
 523:                              isAllowed = true; // report.UserId == staff.UserId || staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.UserId);
 524:  
 525:                              / *
 526:                              if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(report.UserId))
 527:                              {
 528:                                  isAllowed = staff.Framework.Guid == report.UserId 
 529:                                      || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == report.UserId);
 530:                              }
 531:                               * /
 532:                          }
 533:                          */
 534:   
 535:                          isAllowed = false; // undefined CRU
 536:                      }
 537:                  }
 538:              }
 539:              else isAllowed = false;
 540:   
 541:              return isAllowed;
 542:          }
 543:   
 544:          ////////////////////////////////////////////////////////////////////////////    
 545:   
 546:          /// <summary>
 547:          ///
 548:          /// </summary>
 549:          public static bool StaffCanSendFieldTnmdSupplierWorkorderEmail(Ia.Ngn.Cl.Model.Staff staff)
 550:          {
 551:              bool isAllowed;
 552:   
 553:              if (staff != null)
 554:              {
 555:                  if (staff.IsHead) isAllowed = true;
 556:                  else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
 557:                  else isAllowed = false;
 558:              }
 559:              else isAllowed = false;
 560:   
 561:              return isAllowed;
 562:          }
 563:   
 564:          ////////////////////////////////////////////////////////////////////////////    
 565:   
 566:          /// <summary>
 567:          ///
 568:          /// </summary>
 569:          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)
 570:          {
 571:              // below: I have to pass both Report and ReportHistory objects separately
 572:   
 573:              bool isAllowed;
 574:   
 575:              if (staff != null)
 576:              {
 577:                  if (StaffIsSuperUser(staff)) isAllowed = true;
 578:                  else
 579:                  {
 580:                      if (function == PersistentStorageFunction.Delete)
 581:                      {
 582:                          // below: a report history can only be deleted by:
 583:                          // - one of the heads of the history user
 584:                          // - the history user if he is a head
 585:   
 586:                          /*
 587:                          if (reportHistory != null)
 588:                          {
 589:                              if (reportHistory.Report.ReportHistories.Max(r => r.Id) != reportHistory.Id) isAllowed = false;
 590:                              else
 591:                              {
 592:                                  if (staff.UserId == reportHistory.UserId && staff.IsHead) isAllowed = true;
 593:                                  else if (staff.Subordinates != null) isAllowed = staff.Subordinates.Any(i => i.UserId == reportHistory.UserId);
 594:                                  else isAllowed = false;
 595:                              }
 596:                          }
 597:                          else isAllowed = false;
 598:                          */
 599:   
 600:                          isAllowed = false; // report history can't be deleted by staff other than super user
 601:                      }
 602:                      else if (function == PersistentStorageFunction.Create)
 603:                      {
 604:                          // below: for create reportHistory must be null
 605:   
 606:                          // below: a report history can be created if:
 607:                          // - report userid is subordinate of staff
 608:                          // - report history userid framework is within staff frameworks
 609:   
 610:                          if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 611:                          else if (report != null && reportHistory == null)
 612:                          {
 613:                              if (report.ReportHistories.Count == 0 && staff.UserId == report.UserId) isAllowed = true;
 614:                              else if (report.ReportHistories.Count == 0 && report.StatusIsOpen) isAllowed = true;
 615:   
 616:                              //else if (report.LastReportHistory != null && !staff.Colleagues.Any(r => r.UserId == report.LastReportHistory.UserId) && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
 617:   
 618:                              else if (report.LastReportHistory != null && staff.UserId == report.LastReportHistory.UserId) isAllowed = true;
 619:                              else if (report.LastReportHistory != null && staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId)) isAllowed = true;
 620:                              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;
 621:                              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;
 622:                              else isAllowed = false;
 623:                          }
 624:                          else isAllowed = false;
 625:                      }
 626:                      else
 627:                      {
 628:                          // below: a report history can be read, and updated if:
 629:                          // - report history UserId is same as staff's
 630:                          // - report userid is subordinate of staff
 631:                          // - report history userid framework is within staff frameworks
 632:   
 633:                          if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 634:                          else if (reportHistory != null)
 635:                          {
 636:                              if (staff.UserId == reportHistory.UserId) isAllowed = true;
 637:                              else if (staff.Subordinates != null && staff.Subordinates.Any(i => i.UserId == reportHistory.UserId)) isAllowed = true;
 638:                              else if (Ia.Ngn.Cl.Model.Business.Administration.IsFrameworkGuid(reportHistory.UserId))
 639:                              {
 640:                                  if (staff.Framework.Guid == reportHistory.UserId || staff.Framework.Descendants != null && staff.Framework.Descendants.Any(i => i.Guid == reportHistory.UserId)) isAllowed = true;
 641:                                  else isAllowed = false;
 642:                              }
 643:                              else isAllowed = false;
 644:                          }
 645:                          else isAllowed = false;
 646:                      }
 647:                  }
 648:              }
 649:              else isAllowed = false;
 650:   
 651:              return isAllowed;
 652:          }
 653:   
 654:          ////////////////////////////////////////////////////////////////////////////    
 655:   
 656:          /// <summary>
 657:          ///
 658:          /// </summary>
 659:          public static bool StaffCanReopenClosedReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 660:          {
 661:              return StaffCanCloseReport(report, staff);
 662:          }
 663:   
 664:          ////////////////////////////////////////////////////////////////////////////    
 665:   
 666:          /// <summary>
 667:          ///
 668:          /// </summary>
 669:          public static bool StaffCanCloseReport(Ia.Ngn.Cl.Model.Report report, Ia.Ngn.Cl.Model.Staff staff)
 670:          {
 671:              bool canClose;
 672:   
 673:              // below: a report can be closed if
 674:   
 675:              if (staff != null)
 676:              {
 677:                  if (StaffIsSuperUser(staff)) canClose = true;
 678:                  //else if (FrameworkCanCloseReport(staff.Framework)) canClose = true; // make dedicated users to check with subscribers if reports are resolved
 679:                  else
 680:                  {
 681:                      // - there must be a history
 682:                      if (report.LastReportHistory != null)
 683:                      {
 684:                          // must be head
 685:                          if (staff.IsHead)
 686:                          {
 687:                              if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") canClose = true;
 688:                              else if (staff.UserId == report.UserId) canClose = true; // the report closer staff is himself
 689:                              else if (staff.Framework.FullyQualifiedArabicName.Contains("قسم الفحص والشكاوى") && staff.Framework.FullyQualifiedArabicName.Contains("وزارة الإتصالات وتكنولوجيا المعلومات | قطاع خدمات المشتركين") && (staff.UserId == report.UserId || staff.Subordinates.Any(i => i.UserId == report.UserId))) canClose = true;
 690:                              // one of the heads of the last report staff
 691:                              else if (staff.UserId == report.LastReportHistory.UserId) canClose = true; // the report history closer staff is himself
 692:                              else
 693:                              {
 694:                                  if (staff.Subordinates != null)
 695:                                  {
 696:                                      canClose = staff.Subordinates.Any(i => i.UserId == report.LastReportHistory.UserId); // the report history closer staff is head of a reported
 697:                                  }
 698:                                  else canClose = false;
 699:                              }
 700:                          }
 701:                          else canClose = false;
 702:                      }
 703:                      else canClose = false;
 704:                  }
 705:              }
 706:              else canClose = false;
 707:   
 708:              return canClose;
 709:          }
 710:   
 711:          ////////////////////////////////////////////////////////////////////////////    
 712:   
 713:          /// <summary>
 714:          ///
 715:          /// </summary>
 716:          public static bool StaffCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 717:          {
 718:              bool isAllowed;
 719:   
 720:              if (staff != null)
 721:              {
 722:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
 723:                  {
 724:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 725:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 726:                      else isAllowed = false;
 727:                  }
 728:                  else
 729:                  {
 730:                      isAllowed = false;
 731:                  }
 732:              }
 733:              else isAllowed = false;
 734:   
 735:              return isAllowed;
 736:          }
 737:   
 738:          ////////////////////////////////////////////////////////////////////////////    
 739:   
 740:          /// <summary>
 741:          ///
 742:          /// </summary>
 743:          public static bool StaffCanCreateReadUpdateDeleteInventoryList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 744:          {
 745:              bool isAllowed;
 746:   
 747:              if (staff != null)
 748:              {
 749:                  if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
 750:                  {
 751:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 752:                      else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 753:                      else isAllowed = false;
 754:                  }
 755:                  else
 756:                  {
 757:                      isAllowed = false;
 758:                  }
 759:              }
 760:              else isAllowed = false;
 761:   
 762:              return isAllowed;
 763:          }
 764:   
 765:          ////////////////////////////////////////////////////////////////////////////
 766:   
 767:          /// <summary>
 768:          ///
 769:          /// </summary>
 770:          public static bool StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 771:          {
 772:              bool isAllowed;
 773:   
 774:              if (staffContact != null)
 775:              {
 776:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 777:                  else if (function == PersistentStorageFunction.Read)
 778:                  {
 779:                      isAllowed = true;
 780:                  }
 781:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 782:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 783:                  else
 784:                  {
 785:                      isAllowed = false;
 786:                  }
 787:              }
 788:              else isAllowed = false;
 789:   
 790:              return isAllowed;
 791:          }
 792:   
 793:          ////////////////////////////////////////////////////////////////////////////
 794:   
 795:          /// <summary>
 796:          ///
 797:          /// </summary>
 798:          public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 799:          {
 800:              bool isAllowed;
 801:   
 802:              if (staffContact != null)
 803:              {
 804:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 805:                  else if (function == PersistentStorageFunction.Read)
 806:                  {
 807:                      isAllowed = true;
 808:                  }
 809:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 810:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 811:                  else
 812:                  {
 813:                      isAllowed = false;
 814:                  }
 815:              }
 816:              else isAllowed = false;
 817:   
 818:              return isAllowed;
 819:          }
 820:   
 821:          ////////////////////////////////////////////////////////////////////////////
 822:   
 823:          /// <summary>
 824:          ///
 825:          /// </summary>
 826:          public static bool FrameworkCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 827:          {
 828:              bool isAllowed;
 829:   
 830:              if (framework != null)
 831:              {
 832:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 833:                  else if (function == PersistentStorageFunction.Read)
 834:                  {
 835:                      isAllowed = true;
 836:                  }
 837:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 838:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 839:                  else
 840:                  {
 841:                      isAllowed = false;
 842:                  }
 843:              }
 844:              else isAllowed = false;
 845:   
 846:              return isAllowed;
 847:          }
 848:   
 849:          ////////////////////////////////////////////////////////////////////////////
 850:   
 851:          /// <summary>
 852:          ///
 853:          /// </summary>
 854:          public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 855:          {
 856:              bool isAllowed;
 857:   
 858:              if (staffContact != null)
 859:              {
 860:                  if (function == PersistentStorageFunction.Create)
 861:                  {
 862:                      isAllowed = true;
 863:                  }
 864:                  else if (function == PersistentStorageFunction.Read)
 865:                  {
 866:                      isAllowed = true;
 867:                  }
 868:                  else if (function == PersistentStorageFunction.Update)
 869:                  {
 870:                      isAllowed = false;
 871:                  }
 872:                  else if (function == PersistentStorageFunction.Delete)
 873:                  {
 874:                      isAllowed = false;
 875:                  }
 876:                  else
 877:                  {
 878:                      isAllowed = false;
 879:                  }
 880:              }
 881:              else isAllowed = false;
 882:   
 883:              return isAllowed;
 884:          }
 885:   
 886:          ////////////////////////////////////////////////////////////////////////////
 887:   
 888:          /// <summary>
 889:          ///
 890:          /// </summary>
 891:          public static bool FrameworkCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 892:          {
 893:              bool isAllowed;
 894:   
 895:              if (framework != null)
 896:              {
 897:                  if (function == PersistentStorageFunction.Create)
 898:                  {
 899:                      isAllowed = true;
 900:                  }
 901:                  else if (function == PersistentStorageFunction.Read)
 902:                  {
 903:                      isAllowed = true;
 904:                  }
 905:                  else if (function == PersistentStorageFunction.Update)
 906:                  {
 907:                      isAllowed = false;
 908:                  }
 909:                  else if (function == PersistentStorageFunction.Delete)
 910:                  {
 911:                      isAllowed = false;
 912:                  }
 913:                  else
 914:                  {
 915:                      isAllowed = false;
 916:                  }
 917:              }
 918:              else isAllowed = false;
 919:   
 920:              return isAllowed;
 921:          }
 922:   
 923:          ////////////////////////////////////////////////////////////////////////////
 924:          ////////////////////////////////////////////////////////////////////////////
 925:   
 926:          /// <summary>
 927:          ///
 928:          /// </summary>
 929:          public static bool StaffCanCreateReadUpdateDeleteServicePort(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 930:          {
 931:              bool isAllowed;
 932:   
 933:              if (staff != null)
 934:              {
 935:                  //if (StaffIsSuperUser(staff)) isAllowed = true;
 936:                  isAllowed = false;
 937:              }
 938:              else isAllowed = false;
 939:   
 940:              return isAllowed;
 941:          }
 942:   
 943:          ////////////////////////////////////////////////////////////////////////////
 944:          ////////////////////////////////////////////////////////////////////////////
 945:   
 946:          /// <summary>
 947:          ///
 948:          /// </summary>
 949:          public static bool StaffCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 950:          {
 951:              bool isAllowed;
 952:   
 953:              if (staff != null)
 954:              {
 955:                  if (function == PersistentStorageFunction.Read)
 956:                  {
 957:                      isAllowed = true;
 958:                  }
 959:                  else if (function == PersistentStorageFunction.Update)
 960:                  {
 961:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 962:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 963:                      else isAllowed = false;
 964:                  }
 965:                  else
 966:                  {
 967:                      isAllowed = false;
 968:                  }
 969:              }
 970:              else isAllowed = false;
 971:   
 972:              return isAllowed;
 973:          }
 974:   
 975:          ////////////////////////////////////////////////////////////////////////////
 976:          ////////////////////////////////////////////////////////////////////////////
 977:   
 978:          /// <summary>
 979:          ///
 980:          /// </summary>
 981:          public static bool StaffUserNameCanLogFromAnyPcIp(string userName)
 982:          {
 983:              bool isAllowed;
 984:   
 985:              if (!string.IsNullOrEmpty(userName))
 986:              {
 987:                  if (userName == "mohammad") isAllowed = true;
 988:                  else if (userName == "jaber") isAllowed = true;
 989:                  else if (userName == "yousef") isAllowed = true;
 990:                  else isAllowed = false;
 991:              }
 992:              else isAllowed = false;
 993:   
 994:              return isAllowed;
 995:          }
 996:   
 997:          ////////////////////////////////////////////////////////////////////////////
 998:          ////////////////////////////////////////////////////////////////////////////
 999:   
1000:          /// <summary>
1001:          ///
1002:          /// </summary>
1003:          public static Ia.Ngn.Cl.Model.Business.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
1004:          {
1005:              get
1006:              {
1007:                  Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
1008:   
1009:                  //framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "إدارة شبكة الألياف الضوئية" select f).FirstOrDefault(); //.SingleOrDefault();
1010:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "وزارة الإتصالات وتكنولوجيا المعلومات" select f).FirstOrDefault(); //.SingleOrDefault();
1011:   
1012:                  return framework;
1013:              }
1014:          }
1015:   
1016:          ////////////////////////////////////////////////////////////////////////////
1017:   
1018:          /// <summary>
1019:          ///
1020:          /// </summary>
1021:          public static bool FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1022:          {
1023:              bool isResponsible;
1024:   
1025:              isResponsible = framework.ArabicName == "قسم الدعم الفني للشبكة";
1026:   
1027:              return isResponsible;
1028:          }
1029:   
1030:          ////////////////////////////////////////////////////////////////////////////
1031:   
1032:          /// <summary>
1033:          ///
1034:          /// </summary>
1035:          public static bool FrameworkCanCloseReport(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1036:          {
1037:              bool canClose;
1038:   
1039:              canClose = framework.ArabicName == "قسم الدعم الفني للشبكة";
1040:   
1041:              return canClose;
1042:          }
1043:   
1044:          ////////////////////////////////////////////////////////////////////////////
1045:   
1046:          /// <summary>
1047:          ///
1048:          /// </summary>
1049:          public static bool StaffIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Staff staff)
1050:          {
1051:              bool isResponsible;
1052:   
1053:              isResponsible = FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(staff.Framework);
1054:   
1055:              return isResponsible;
1056:          }
1057:   
1058:          ////////////////////////////////////////////////////////////////////////////
1059:          ////////////////////////////////////////////////////////////////////////////
1060:   
1061:          /// <summary>
1062:          ///
1063:          /// </summary>
1064:          public static bool StaffIsSuperUser(Ia.Ngn.Cl.Model.Staff staff)
1065:          {
1066:              bool isSuperUser;
1067:   
1068:              if (staff != null) isSuperUser = staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة" && staff.IsHead; // me!
1069:              else isSuperUser = false;
1070:   
1071:              return isSuperUser;
1072:          }
1073:   
1074:          ////////////////////////////////////////////////////////////////////////////
1075:   
1076:          /// <summary>
1077:          ///
1078:          /// </summary>
1079:          public static bool FrameworkIsSuperFramework(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1080:          {
1081:              bool isSuperFramework;
1082:   
1083:              if (framework != null) isSuperFramework = framework.ArabicName == "قسم دعم تشغيل الشبكة";
1084:              else isSuperFramework = false;
1085:   
1086:              return isSuperFramework;
1087:          }
1088:   
1089:          ////////////////////////////////////////////////////////////////////////////
1090:   
1091:          /// <summary>
1092:          ///
1093:          /// </summary>
1094:          public static Ia.Ngn.Cl.Model.Business.Administration.Framework SuperFramework
1095:          {
1096:              get
1097:              {
1098:                  Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
1099:   
1100:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "قسم دعم تشغيل الشبكة" select f).Single();
1101:   
1102:                  return framework;
1103:              }
1104:          }
1105:   
1106:          ////////////////////////////////////////////////////////////////////////////
1107:          ////////////////////////////////////////////////////////////////////////////
1108:   
1109:          /// <summary>
1110:          ///
1111:          /// </summary>
1112:          public static bool StaffContactCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
1113:          {
1114:              bool isAllowed;
1115:   
1116:              if (staffContact != null)
1117:              {
1118:                  if (persistentStorageFunction == PersistentStorageFunction.Read)
1119:                  {
1120:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
1121:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
1122:                      else isAllowed = false;
1123:                  }
1124:                  else if (persistentStorageFunction == PersistentStorageFunction.Update)
1125:                  {
1126:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
1127:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
1128:                      else isAllowed = false;
1129:                  }
1130:                  else
1131:                  {
1132:                      isAllowed = false;
1133:                  }
1134:              }
1135:              else isAllowed = false;
1136:   
1137:              return isAllowed;
1138:          }
1139:   
1140:          ////////////////////////////////////////////////////////////////////////////
1141:   
1142:          /// <summary>
1143:          ///
1144:          /// </summary>
1145:          public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
1146:          {
1147:              bool isAllowed;
1148:   
1149:              if (staff != null)
1150:              {
1151:                  if (function == PersistentStorageFunction.Read)
1152:                  {
1153:                      isAllowed = true;
1154:                  }
1155:                  else if (function == PersistentStorageFunction.Update)
1156:                  {
1157:                      if (StaffIsSuperUser(staff)) isAllowed = true;
1158:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1159:                      else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
1160:                      else isAllowed = false;
1161:                  }
1162:                  else if (function == PersistentStorageFunction.Delete)
1163:                  {
1164:                      if (StaffIsSuperUser(staff)) isAllowed = true;
1165:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1166:                      else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
1167:                      else isAllowed = false;
1168:                  }
1169:                  else
1170:                  {
1171:                      isAllowed = false;
1172:                  }
1173:              }
1174:              else isAllowed = false;
1175:   
1176:              return isAllowed;
1177:          }
1178:   
1179:          ////////////////////////////////////////////////////////////////////////////
1180:   
1181:          /// <summary>
1182:          ///
1183:          /// </summary>
1184:          public static bool StaffCanCreateReadUpdateAccessMail(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
1185:          {
1186:              bool isAllowed;
1187:   
1188:              if (staff != null)
1189:              {
1190:                  if (function == PersistentStorageFunction.Read)
1191:                  {
1192:                      isAllowed = true;
1193:                  }
1194:                  else if (function == PersistentStorageFunction.Update)
1195:                  {
1196:                      if (StaffIsSuperUser(staff)) isAllowed = true;
1197:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
1198:                      else isAllowed = false;
1199:                  }
1200:                  else
1201:                  {
1202:                      isAllowed = false;
1203:                  }
1204:              }
1205:              else isAllowed = false;
1206:   
1207:              return isAllowed;
1208:          }
1209:   
1210:          ////////////////////////////////////////////////////////////////////////////
1211:   
1212:          /// <summary>
1213:          ///
1214:          /// </summary>
1215:          public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Staff staff)
1216:          {
1217:              bool isAllowed;
1218:   
1219:              if (staff != null)
1220:              {
1221:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1222:                  else isAllowed = false;
1223:              }
1224:              else isAllowed = false;
1225:   
1226:              return isAllowed;
1227:          }
1228:   
1229:          ////////////////////////////////////////////////////////////////////////////
1230:   
1231:          /// <summary>
1232:          ///
1233:          /// </summary>
1234:          public static bool StaffCanUploadGponPhaseIiHomeConnectionAndMigrationCsvFile(Ia.Ngn.Cl.Model.Staff staff)
1235:          {
1236:              bool isAllowed;
1237:   
1238:              if (staff != null)
1239:              {
1240:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1241:                  else isAllowed = false;
1242:              }
1243:              else isAllowed = false;
1244:   
1245:              return isAllowed;
1246:          }
1247:   
1248:          ////////////////////////////////////////////////////////////////////////////
1249:   
1250:          /// <summary>
1251:          ///
1252:          /// </summary>
1253:          public static bool FrameworkCanReadStatistics(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1254:          {
1255:              bool isAllowed;
1256:   
1257:              if (framework != null)
1258:              {
1259:                  if (FrameworkIsSuperFramework(framework)) isAllowed = true;
1260:                  else isAllowed = false;
1261:              }
1262:              else isAllowed = true; // for now I will allow users with framework = null coming form telegram
1263:   
1264:              return isAllowed;
1265:          }
1266:   
1267:          ////////////////////////////////////////////////////////////////////////////
1268:   
1269:          /// <summary>
1270:          ///
1271:          /// </summary>
1272:          public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
1273:          {
1274:              bool isAllowed;
1275:   
1276:              if (staffContact != null)
1277:              {
1278:                  if (function == PersistentStorageFunction.Create)
1279:                  {
1280:                      isAllowed = true;
1281:                  }
1282:                  else if (function == PersistentStorageFunction.Read)
1283:                  {
1284:                      isAllowed = true;
1285:                  }
1286:                  else if (function == PersistentStorageFunction.Update)
1287:                  {
1288:                      isAllowed = false;
1289:                  }
1290:                  else if (function == PersistentStorageFunction.Delete)
1291:                  {
1292:                      isAllowed = false;
1293:                  }
1294:                  else
1295:                  {
1296:                      isAllowed = false;
1297:                  }
1298:              }
1299:              else isAllowed = false;
1300:   
1301:              return isAllowed;
1302:          }
1303:   
1304:          ////////////////////////////////////////////////////////////////////////////
1305:          ////////////////////////////////////////////////////////////////////////////
1306:   
1307:          /// <summary>
1308:          ///
1309:          /// </summary>
1310:          public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ngn.Cl.Model.Staff staff)
1311:          {
1312:              bool isAllowed;
1313:   
1314:              if (staff != null)
1315:              {
1316:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1317:                  //else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
1318:                  else isAllowed = false;
1319:              }
1320:              else isAllowed = false;
1321:   
1322:              return isAllowed;
1323:          }
1324:   
1325:          ////////////////////////////////////////////////////////////////////////////
1326:   
1327:          /// <summary>
1328:          ///
1329:          /// </summary>
1330:          public static bool StaffCanReadUpdateService2Access(Ia.Ngn.Cl.Model.Staff staff)
1331:          {
1332:              bool isAllowed;
1333:   
1334:              if (staff != null)
1335:              {
1336:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1337:                  else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات" && staff.IsHead) isAllowed = true;
1338:                  else if (staff.Framework.ArabicName == "هواوي" && staff.IsHead) isAllowed = true;
1339:                  else isAllowed = false;
1340:              }
1341:              else isAllowed = false;
1342:   
1343:              return isAllowed;
1344:          }
1345:   
1346:          ////////////////////////////////////////////////////////////////////////////
1347:   
1348:          /// <summary>
1349:          ///
1350:          /// </summary>
1351:          public static bool StaffCanMigratePremisesFromPstnToGpon(Ia.Ngn.Cl.Model.Staff staff)
1352:          {
1353:              // see related sister function StaffCanMigratePremisesFromPstnToGponForNddOnt()
1354:              bool isAllowed;
1355:   
1356:              if (staff != null)
1357:              {
1358:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1359:                  else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1360:                  else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
1361:                  else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
1362:                  else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
1363:                  else
1364:                  {
1365:                      if (staff.Framework != null && staff.Framework.Sites != null && staff.Framework.Sites.Count > 0)
1366:                      {
1367:                          var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
1368:   
1369:                          isAllowed = staff.Framework.Sites.Any(u => u.Routers.Any(v => v.Odfs.Any(w => w.Olts.Any(x => list.Contains(x.Id)))));
1370:                      }
1371:                      else isAllowed = false;
1372:                  }
1373:              }
1374:              else isAllowed = false;
1375:   
1376:              return isAllowed;
1377:          }
1378:   
1379:          ////////////////////////////////////////////////////////////////////////////
1380:   
1381:          /// <summary>
1382:          ///
1383:          /// </summary>
1384:          public static bool StaffCanMigratePremisesFromPstnToGponForNddOnt(Ia.Ngn.Cl.Model.Staff staff, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
1385:          {
1386:              // see related sister function StaffCanMigratePremisesFromPstnToGpon()
1387:              bool isAllowed;
1388:   
1389:              if (staff != null)
1390:              {
1391:                  if (nddOnt != null)
1392:                  {
1393:                      var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
1394:   
1395:                      if (list.Contains(nddOnt.Pon.PonGroup.Olt.Id))
1396:                      {
1397:                          if (StaffIsSuperUser(staff)) isAllowed = true;
1398:                          else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1399:                          else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
1400:                          else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
1401:                          else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
1402:                          else
1403:                          {
1404:                              if (staff.Framework != null && staff.Framework.Sites != null && staff.Framework.Sites.Count > 0)
1405:                              {
1406:                                  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))));
1407:                              }
1408:                              else isAllowed = false;
1409:                          }
1410:                      }
1411:                      else isAllowed = false;
1412:                  }
1413:                  else isAllowed = false;
1414:              }
1415:              else isAllowed = false;
1416:   
1417:              return isAllowed;
1418:          }
1419:   
1420:          ////////////////////////////////////////////////////////////////////////////
1421:   
1422:          /// <summary>
1423:          ///
1424:          /// </summary>
1425:          public static bool StaffCanAccessAdministationFolder(Ia.Ngn.Cl.Model.Staff staff)
1426:          {
1427:              bool isAllowed;
1428:   
1429:              /*
1430:               * <allow roles="Application,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة,إدارة مشاريع الشبكة الهاتفية"/>
1431:               * <deny users="*"/>
1432:               * <allow users="mohammad"/>
1433:               */
1434:   
1435:              string[] sp = { "Application", "إدارة شبكة الألياف الضوئية", "مراقبة خدمات الشبكة", "مراقبة الدعم الفنى للشبكة", "مراقبة تقنية المعلومات", "مراقبة تشغيل الشبكة", "قسم دعم تشغيل الشبكة", "إدارة مشاريع الشبكة الهاتفية" };
1436:   
1437:              if (staff != null)
1438:              {
1439:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1440:                  else if (staff.IsHead && staff.User.UserName == "mohammad") isAllowed = true;
1441:                  else if (sp.Contains(staff.Framework.ArabicName)) isAllowed = true;
1442:                  else isAllowed = false;
1443:              }
1444:              else isAllowed = false;
1445:   
1446:              return isAllowed;
1447:          }
1448:   
1449:          ////////////////////////////////////////////////////////////////////////////
1450:   
1451:          /// <summary>
1452:          ///
1453:          /// </summary>
1454:          public static bool StaffCanExecuteTasks(Ia.Ngn.Cl.Model.Staff staff)
1455:          {
1456:              bool isAllowed;
1457:   
1458:              if (staff != null)
1459:              {
1460:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1461:                  //else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
1462:                  else isAllowed = false;
1463:              }
1464:              else isAllowed = false;
1465:   
1466:              return isAllowed;
1467:          }
1468:   
1469:          ////////////////////////////////////////////////////////////////////////////
1470:   
1471:          /// <summary>
1472:          ///
1473:          /// </summary>
1474:          public static bool StaffIsApplication(Ia.Ngn.Cl.Model.Staff staff)
1475:          {
1476:              bool isAllowed;
1477:   
1478:              if (staff != null)
1479:              {
1480:                  if (staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة") isAllowed = true;
1481:                  else isAllowed = false;
1482:              }
1483:              else isAllowed = false;
1484:   
1485:              return isAllowed;
1486:          }
1487:   
1488:          ////////////////////////////////////////////////////////////////////////////
1489:   
1490:          /// <summary>
1491:          ///
1492:          /// </summary>
1493:          public static bool StaffIsInCustomerServiceSector(Ia.Ngn.Cl.Model.Staff staff)
1494:          {
1495:              bool isAllowed;
1496:   
1497:              if (staff != null)
1498:              {
1499:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == "قطاع خدمات المشتركين")) isAllowed = true;
1500:                  else isAllowed = false;
1501:              }
1502:              else isAllowed = false;
1503:   
1504:              return isAllowed;
1505:          }
1506:   
1507:          ////////////////////////////////////////////////////////////////////////////
1508:   
1509:          /// <summary>
1510:          ///
1511:          /// </summary>
1512:          public static bool StaffIsInOpticalFiberNetworkDepartment(Ia.Ngn.Cl.Model.Staff staff)
1513:          {
1514:              bool isAllowed;
1515:   
1516:              if (staff != null)
1517:              {
1518:                  if (staff.Framework.ArabicName == "إدارة شبكة الألياف الضوئية" || staff.Framework.Ancestors.Any(u => u.ArabicName == "إدارة شبكة الألياف الضوئية")) isAllowed = true;
1519:                  else if (staff.Framework.ArabicName == "إدارة مشاريع الشبكة الهاتفية" || staff.Framework.Ancestors.Any(u => u.ArabicName == "إدارة مشاريع الشبكة الهاتفية")) isAllowed = true; // temp
1520:                  else isAllowed = false;
1521:              }
1522:              else isAllowed = false;
1523:   
1524:              return isAllowed;
1525:          }
1526:   
1527:          ////////////////////////////////////////////////////////////////////////////
1528:   
1529:          /// <summary>
1530:          ///
1531:          /// </summary>
1532:          public static bool StaffIsSupplier(Ia.Ngn.Cl.Model.Staff staff)
1533:          {
1534:              bool isAllowed;
1535:   
1536:              if (staff != null)
1537:              {
1538:                  if (staff.Framework.ArabicName == "نوكيا" || staff.Framework.ArabicName == "هواوي") isAllowed = true;
1539:                  else isAllowed = false;
1540:              }
1541:              else isAllowed = false;
1542:   
1543:              return isAllowed;
1544:          }
1545:   
1546:          ////////////////////////////////////////////////////////////////////////////
1547:   
1548:          /// <summary>
1549:          ///
1550:          /// </summary>
1551:          public static bool StaffIsInRole(Ia.Ngn.Cl.Model.Staff staff, string role)
1552:          {
1553:              bool isAllowed;
1554:   
1555:              if (staff != null)
1556:              {
1557:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == role)) isAllowed = true;
1558:                  else isAllowed = false;
1559:              }
1560:              else isAllowed = false;
1561:   
1562:              return isAllowed;
1563:          }
1564:   
1565:          ////////////////////////////////////////////////////////////////////////////
1566:          ////////////////////////////////////////////////////////////////////////////
1567:   
1568:          /// <summary>
1569:          ///
1570:          /// </summary>
1571:          public static List<Tuple<string, string>> EmailRecipientTupleList(string function)
1572:          {
1573:              List<Tuple<string, string>> recipientTupleList;
1574:   
1575:              recipientTupleList = new List<Tuple<string, string>>();
1576:   
1577:              switch (function)
1578:              {
1579:                  case "list-with-ont-list-provisioned-and-ready-but-do-not-exist-in-customer-department-database":
1580:                  case "list-of-pstn-to-gpon-migrated-and-provisioned-services-in-allowed-to-be-migrated-olts":
1581:                      {
1582:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1583:                          recipientTupleList.Add(new Tuple<string, string>("E. Shatti", "emad@moc.gov.kw"));
1584:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
1585:   
1586:                          break;
1587:                      }
1588:                  case "ofn-status-report":
1589:                      {
1590:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
1591:                          break;
1592:                      }
1593:                  case "ofn-statistics-report":
1594:                      {
1595:                          recipientTupleList.Add(new Tuple<string, string>("MOC Traffic Section", "traffic_section@yahoo.com"));
1596:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1597:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
1598:                          break;
1599:                      }
1600:                  case "ofn-nokia-report":
1601:                      {
1602:                          recipientTupleList.Add(new Tuple<string, string>("O. Kandemir", "oguzhan.kandemir@nokia.com"));
1603:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
1604:                          break;
1605:                      }
1606:                  case "ofn-huawei-report":
1607:                      {
1608:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "info@ia.com.kw"));
1609:                          break;
1610:                      }
1611:                  default: break;
1612:              }
1613:   
1614:              return recipientTupleList;
1615:          }
1616:   
1617:          ////////////////////////////////////////////////////////////////////////////
1618:          ////////////////////////////////////////////////////////////////////////////
1619:   
1620:          /// <summary>
1621:          ///
1622:          /// </summary>
1623:          public static bool ServiceRequestIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
1624:          {
1625:              // below: this skips processing some service requests due to misc problems
1626:              bool processingIsAllowed;
1627:   
1628:              if (serviceRequest.Id == 1719402 || serviceRequest.Id == 1875029) processingIsAllowed = false;
1629:              // 1719402    25232104    1    تم التنفيذ    2014-10-28 11:07    خط هاتف    هاتف    17    الادارة العامة للجمارك    جهات حكومية
1630:              // 1875029    25232104    1    تعذر التنفيذ    2016-02-24 00:00    رفع خط    هاتف    17    الادارة العامة للجمارك    جهات حكومية
1631:              else processingIsAllowed = true;
1632:   
1633:              return processingIsAllowed;
1634:          }
1635:   
1636:          ////////////////////////////////////////////////////////////////////////////
1637:   
1638:          /// <summary>
1639:          ///
1640:          /// </summary>
1641:          public static bool ServiceRequestHistoryIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory)
1642:          {
1643:              // below: this skips processing some service requests due to misc problems
1644:              bool processingIsAllowed;
1645:   
1646:              if (serviceRequestHistory.Id == "25429778:1:965:0:66:2005-11-27") processingIsAllowed = false;
1647:              // prevent the removal of service group
1648:              else processingIsAllowed = true;
1649:   
1650:              return processingIsAllowed;
1651:          }
1652:   
1653:          ////////////////////////////////////////////////////////////////////////////
1654:   
1655:          /// <summary>
1656:          ///
1657:          /// </summary>
1658:          public static bool ServiceProcessingIsAllowed(string service)
1659:          {
1660:              // below: this skips processing some services due to misc problems
1661:              bool processingIsAllowed;
1662:   
1663:              if (!string.IsNullOrEmpty(service))
1664:              {
1665:                  if (Ia.Ngn.Cl.Model.Data.ServiceExemption.ServiceList().Contains(service)) processingIsAllowed = false;
1666:                  else processingIsAllowed = true;
1667:              }
1668:              else processingIsAllowed = true;
1669:   
1670:              return processingIsAllowed;
1671:          }
1672:   
1673:          ////////////////////////////////////////////////////////////////////////////
1674:          ////////////////////////////////////////////////////////////////////////////
1675:   
1676:          /// <summary>
1677:          ///
1678:          /// </summary>
1679:          public static bool TelegramUserCanReadFind(string chatId, int userId)
1680:          {
1681:              bool isAllowed;
1682:   
1683:              if (userId != 0)
1684:              {
1685:                  isAllowed = true;
1686:              }
1687:              else isAllowed = false;
1688:   
1689:              return isAllowed;
1690:          }
1691:   
1692:          ////////////////////////////////////////////////////////////////////////////    
1693:   
1694:          /// <summary>
1695:          ///
1696:          /// </summary>
1697:          public static bool NumberIsWithinFrameworkSiteDomainList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string service)
1698:          {
1699:              bool isWithin;
1700:   
1701:              if (framework != null)
1702:              {
1703:                  if (framework.Sites != null && framework.Sites.Count > 0)
1704:                  {
1705:                      if (framework.Sites.Any(w => w.DomainList.Any(u => service.StartsWith(u.ToString())))) isWithin = true;
1706:                      else isWithin = true; // false; temp
1707:                  }
1708:                  else isWithin = true; // will allow number for framework.Site == null
1709:              }
1710:              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.
1711:   
1712:              return isWithin;
1713:          }
1714:   
1715:          ////////////////////////////////////////////////////////////////////////////    
1716:   
1717:          /// <summary>
1718:          ///
1719:          /// </summary>
1720:          public static bool AccessNameIsWithinFrameworkSiteAreaSymbolList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string accessName)
1721:          {
1722:              bool isWithin;
1723:   
1724:              if (framework != null)
1725:              {
1726:                  if (framework.Sites != null && framework.Sites.Count > 0)
1727:                  {
1728:                      if (framework.Sites.Any(u => u.AreaSymbolList.Any(v => accessName.StartsWith(v.ToString())))) isWithin = true;
1729:                      else isWithin = true; // false; temp
1730:                  }
1731:                  else isWithin = true; // will allow number for framework.Site == null
1732:              }
1733:              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.
1734:   
1735:              return isWithin;
1736:          }
1737:   
1738:          ////////////////////////////////////////////////////////////////////////////    
1739:   
1740:          /// <summary>
1741:          ///
1742:          /// </summary>
1743:          public static void UpdateAdministrativeFrameworkRolesOfStaff(Ia.Ngn.Cl.Model.Staff staff)
1744:          {
1745:              string userName;
1746:              MembershipUser membershipUser;
1747:   
1748:              membershipUser = Membership.GetUser(staff.UserId);
1749:   
1750:              if (membershipUser != null)
1751:              {
1752:                  userName = membershipUser.UserName;
1753:   
1754:                  // add user to IsHead role if he is head, and remove him otherwise
1755:                  if (staff.IsHead)
1756:                  {
1757:                      if (!Roles.IsUserInRole(userName, "IsHead")) Roles.AddUserToRole(userName, "IsHead");
1758:                  }
1759:                  else
1760:                  {
1761:                      if (Roles.IsUserInRole(userName, "IsHead")) Roles.RemoveUserFromRole(userName, "IsHead");
1762:                  }
1763:   
1764:                  // add user to its direct role
1765:                  if (!Roles.IsUserInRole(userName, staff.Framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, staff.Framework.FullyQualifiedArabicName);
1766:   
1767:                  // add user to its decendants roles
1768:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in staff.Framework.Descendants)
1769:                  {
1770:                      if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
1771:                  }
1772:   
1773:                  // add user to its ancestors roles
1774:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in staff.Framework.Ancestors)
1775:                  {
1776:                      if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
1777:                  }
1778:   
1779:                  // loop through all user roles and remove it from roles not in his description
1780:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList)
1781:                  {
1782:                      if (framework.Id != staff.Framework.Id
1783:                          && !staff.Framework.Descendants.Any(f => f.Id == framework.Id)
1784:                          && !staff.Framework.Ancestors.Any(f => f.Id == framework.Id)
1785:                          && Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName))
1786:                          Roles.RemoveUserFromRole(userName, framework.FullyQualifiedArabicName);
1787:                  }
1788:              }
1789:          }
1790:   
1791:          ////////////////////////////////////////////////////////////////////////////
1792:          ////////////////////////////////////////////////////////////////////////////    
1793:      }
1794:   
1795:      ////////////////////////////////////////////////////////////////////////////
1796:      ////////////////////////////////////////////////////////////////////////////   
1797:  }