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

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(x => x.Guid).Select(x => x.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 StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 744:          {
 745:              bool isAllowed;
 746:   
 747:              if (staffContact != null)
 748:              {
 749:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 750:                  else if (function == PersistentStorageFunction.Read)
 751:                  {
 752:                      isAllowed = true;
 753:                  }
 754:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 755:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 756:                  else
 757:                  {
 758:                      isAllowed = false;
 759:                  }
 760:              }
 761:              else isAllowed = false;
 762:   
 763:              return isAllowed;
 764:          }
 765:   
 766:          ////////////////////////////////////////////////////////////////////////////
 767:   
 768:          /// <summary>
 769:          ///
 770:          /// </summary>
 771:          public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 772:          {
 773:              bool isAllowed;
 774:   
 775:              if (staffContact != null)
 776:              {
 777:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 778:                  else if (function == PersistentStorageFunction.Read)
 779:                  {
 780:                      isAllowed = true;
 781:                  }
 782:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 783:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 784:                  else
 785:                  {
 786:                      isAllowed = false;
 787:                  }
 788:              }
 789:              else isAllowed = false;
 790:   
 791:              return isAllowed;
 792:          }
 793:   
 794:          ////////////////////////////////////////////////////////////////////////////
 795:   
 796:          /// <summary>
 797:          ///
 798:          /// </summary>
 799:          public static bool FrameworkCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 800:          {
 801:              bool isAllowed;
 802:   
 803:              if (framework != null)
 804:              {
 805:                  if (function == PersistentStorageFunction.Create) isAllowed = false;
 806:                  else if (function == PersistentStorageFunction.Read)
 807:                  {
 808:                      isAllowed = true;
 809:                  }
 810:                  else if (function == PersistentStorageFunction.Update) isAllowed = false;
 811:                  else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 812:                  else
 813:                  {
 814:                      isAllowed = false;
 815:                  }
 816:              }
 817:              else isAllowed = false;
 818:   
 819:              return isAllowed;
 820:          }
 821:   
 822:          ////////////////////////////////////////////////////////////////////////////
 823:   
 824:          /// <summary>
 825:          ///
 826:          /// </summary>
 827:          public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
 828:          {
 829:              bool isAllowed;
 830:   
 831:              if (staffContact != null)
 832:              {
 833:                  if (function == PersistentStorageFunction.Create)
 834:                  {
 835:                      isAllowed = true;
 836:                  }
 837:                  else if (function == PersistentStorageFunction.Read)
 838:                  {
 839:                      isAllowed = true;
 840:                  }
 841:                  else if (function == PersistentStorageFunction.Update)
 842:                  {
 843:                      isAllowed = false;
 844:                  }
 845:                  else if (function == PersistentStorageFunction.Delete)
 846:                  {
 847:                      isAllowed = false;
 848:                  }
 849:                  else
 850:                  {
 851:                      isAllowed = false;
 852:                  }
 853:              }
 854:              else isAllowed = false;
 855:   
 856:              return isAllowed;
 857:          }
 858:   
 859:          ////////////////////////////////////////////////////////////////////////////
 860:   
 861:          /// <summary>
 862:          ///
 863:          /// </summary>
 864:          public static bool FrameworkCanCreateReadUpdateDeleteAccessList(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 865:          {
 866:              bool isAllowed;
 867:   
 868:              if (framework != null)
 869:              {
 870:                  if (function == PersistentStorageFunction.Create)
 871:                  {
 872:                      isAllowed = true;
 873:                  }
 874:                  else if (function == PersistentStorageFunction.Read)
 875:                  {
 876:                      isAllowed = true;
 877:                  }
 878:                  else if (function == PersistentStorageFunction.Update)
 879:                  {
 880:                      isAllowed = false;
 881:                  }
 882:                  else if (function == PersistentStorageFunction.Delete)
 883:                  {
 884:                      isAllowed = false;
 885:                  }
 886:                  else
 887:                  {
 888:                      isAllowed = false;
 889:                  }
 890:              }
 891:              else isAllowed = false;
 892:   
 893:              return isAllowed;
 894:          }
 895:   
 896:          ////////////////////////////////////////////////////////////////////////////
 897:          ////////////////////////////////////////////////////////////////////////////
 898:   
 899:          /// <summary>
 900:          ///
 901:          /// </summary>
 902:          public static bool StaffCanCreateReadUpdateDeleteServicePort(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 903:          {
 904:              bool isAllowed;
 905:   
 906:              if (staff != null)
 907:              {
 908:                  //if (StaffIsSuperUser(staff)) isAllowed = true;
 909:                  isAllowed = false;
 910:              }
 911:              else isAllowed = false;
 912:   
 913:              return isAllowed;
 914:          }
 915:   
 916:          ////////////////////////////////////////////////////////////////////////////
 917:          ////////////////////////////////////////////////////////////////////////////
 918:   
 919:          /// <summary>
 920:          ///
 921:          /// </summary>
 922:          public static bool StaffCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
 923:          {
 924:              bool isAllowed;
 925:   
 926:              if (staff != null)
 927:              {
 928:                  if (function == PersistentStorageFunction.Read)
 929:                  {
 930:                      isAllowed = true;
 931:                  }
 932:                  else if (function == PersistentStorageFunction.Update)
 933:                  {
 934:                      if (StaffIsSuperUser(staff)) isAllowed = true;
 935:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 936:                      else isAllowed = false;
 937:                  }
 938:                  else
 939:                  {
 940:                      isAllowed = false;
 941:                  }
 942:              }
 943:              else isAllowed = false;
 944:   
 945:              return isAllowed;
 946:          }
 947:   
 948:          ////////////////////////////////////////////////////////////////////////////
 949:          ////////////////////////////////////////////////////////////////////////////
 950:   
 951:          /// <summary>
 952:          ///
 953:          /// </summary>
 954:          public static bool StaffUserNameCanLogFromAnyPcIp(string userName)
 955:          {
 956:              bool isAllowed;
 957:   
 958:              if (!string.IsNullOrEmpty(userName))
 959:              {
 960:                  if (userName == "mohammad") isAllowed = true;
 961:                  else if (userName == "jaber") isAllowed = true;
 962:                  else isAllowed = false;
 963:              }
 964:              else isAllowed = false;
 965:   
 966:              return isAllowed;
 967:          }
 968:   
 969:          ////////////////////////////////////////////////////////////////////////////
 970:          ////////////////////////////////////////////////////////////////////////////
 971:   
 972:          /// <summary>
 973:          ///
 974:          /// </summary>
 975:          public static Ia.Ngn.Cl.Model.Business.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
 976:          {
 977:              get
 978:              {
 979:                  Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
 980:   
 981:                  //framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "إدارة شبكة الألياف الضوئية" select f).FirstOrDefault(); //.SingleOrDefault();
 982:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "وزارة شؤون الخدمات" select f).FirstOrDefault(); //.SingleOrDefault();
 983:   
 984:                  return framework;
 985:              }
 986:          }
 987:   
 988:          ////////////////////////////////////////////////////////////////////////////
 989:   
 990:          /// <summary>
 991:          ///
 992:          /// </summary>
 993:          public static bool FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
 994:          {
 995:              bool isResponsible;
 996:   
 997:              isResponsible = framework.ArabicName == "قسم الدعم الفني للشبكة";
 998:   
 999:              return isResponsible;
1000:          }
1001:   
1002:          ////////////////////////////////////////////////////////////////////////////
1003:   
1004:          /// <summary>
1005:          ///
1006:          /// </summary>
1007:          public static bool FrameworkCanCloseReport(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1008:          {
1009:              bool canClose;
1010:   
1011:              canClose = framework.ArabicName == "قسم الدعم الفني للشبكة";
1012:   
1013:              return canClose;
1014:          }
1015:   
1016:          ////////////////////////////////////////////////////////////////////////////
1017:   
1018:          /// <summary>
1019:          ///
1020:          /// </summary>
1021:          public static bool StaffIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ngn.Cl.Model.Staff staff)
1022:          {
1023:              bool isResponsible;
1024:   
1025:              isResponsible = FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(staff.Framework);
1026:   
1027:              return isResponsible;
1028:          }
1029:   
1030:          ////////////////////////////////////////////////////////////////////////////
1031:          ////////////////////////////////////////////////////////////////////////////
1032:   
1033:          /// <summary>
1034:          ///
1035:          /// </summary>
1036:          public static bool StaffIsSuperUser(Ia.Ngn.Cl.Model.Staff staff)
1037:          {
1038:              bool isSuperUser;
1039:   
1040:              if (staff != null) isSuperUser = staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة" && staff.IsHead; // me!
1041:              else isSuperUser = false;
1042:   
1043:              return isSuperUser;
1044:          }
1045:   
1046:          ////////////////////////////////////////////////////////////////////////////
1047:   
1048:          /// <summary>
1049:          ///
1050:          /// </summary>
1051:          public static bool FrameworkIsSuperFramework(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1052:          {
1053:              bool isSuperFramework;
1054:   
1055:              if (framework != null) isSuperFramework = framework.ArabicName == "قسم دعم تشغيل الشبكة";
1056:              else isSuperFramework = false;
1057:   
1058:              return isSuperFramework;
1059:          }
1060:   
1061:          ////////////////////////////////////////////////////////////////////////////
1062:   
1063:          /// <summary>
1064:          ///
1065:          /// </summary>
1066:          public static Ia.Ngn.Cl.Model.Business.Administration.Framework SuperFramework
1067:          {
1068:              get
1069:              {
1070:                  Ia.Ngn.Cl.Model.Business.Administration.Framework framework;
1071:   
1072:                  framework = (from f in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList where f.ArabicName == "قسم دعم تشغيل الشبكة" select f).Single();
1073:   
1074:                  return framework;
1075:              }
1076:          }
1077:   
1078:          ////////////////////////////////////////////////////////////////////////////
1079:          ////////////////////////////////////////////////////////////////////////////
1080:   
1081:          /// <summary>
1082:          ///
1083:          /// </summary>
1084:          public static bool StaffContactCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
1085:          {
1086:              bool isAllowed;
1087:   
1088:              if (staffContact != null)
1089:              {
1090:                  if (persistentStorageFunction == PersistentStorageFunction.Read)
1091:                  {
1092:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
1093:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
1094:                      else isAllowed = false;
1095:                  }
1096:                  else if (persistentStorageFunction == PersistentStorageFunction.Update)
1097:                  {
1098:                      if (StaffIsSuperUser(staffContact.Staff)) isAllowed = true;
1099:                      else if (staffContact.Contact != null && staffContact.Contact.FirstName == "Samih") isAllowed = true;
1100:                      else isAllowed = false;
1101:                  }
1102:                  else
1103:                  {
1104:                      isAllowed = false;
1105:                  }
1106:              }
1107:              else isAllowed = false;
1108:   
1109:              return isAllowed;
1110:          }
1111:   
1112:          ////////////////////////////////////////////////////////////////////////////
1113:   
1114:          /// <summary>
1115:          ///
1116:          /// </summary>
1117:          public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
1118:          {
1119:              bool isAllowed;
1120:   
1121:              if (staff != null)
1122:              {
1123:                  if (function == PersistentStorageFunction.Read)
1124:                  {
1125:                      isAllowed = true;
1126:                  }
1127:                  else if (function == PersistentStorageFunction.Update)
1128:                  {
1129:                      if (StaffIsSuperUser(staff)) isAllowed = true;
1130:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1131:                      else if (/*(staff.IsHead || staff.FirstName == "علي") && */staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
1132:                      else isAllowed = false;
1133:                  }
1134:                  else if (function == PersistentStorageFunction.Delete)
1135:                  {
1136:                      if (StaffIsSuperUser(staff)) 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 StaffCanCreateReadUpdateAccessMail(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Staff staff)
1155:          {
1156:              bool isAllowed;
1157:   
1158:              if (staff != null)
1159:              {
1160:                  if (function == PersistentStorageFunction.Read)
1161:                  {
1162:                      isAllowed = true;
1163:                  }
1164:                  else if (function == PersistentStorageFunction.Update)
1165:                  {
1166:                      if (StaffIsSuperUser(staff)) isAllowed = true;
1167:                      else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
1168:                      else isAllowed = false;
1169:                  }
1170:                  else
1171:                  {
1172:                      isAllowed = false;
1173:                  }
1174:              }
1175:              else isAllowed = false;
1176:   
1177:              return isAllowed;
1178:          }
1179:   
1180:          ////////////////////////////////////////////////////////////////////////////
1181:   
1182:          /// <summary>
1183:          ///
1184:          /// </summary>
1185:          public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Staff staff)
1186:          {
1187:              bool isAllowed;
1188:   
1189:              if (staff != null)
1190:              {
1191:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1192:                  else isAllowed = false;
1193:              }
1194:              else isAllowed = false;
1195:   
1196:              return isAllowed;
1197:          }
1198:   
1199:          ////////////////////////////////////////////////////////////////////////////
1200:   
1201:          /// <summary>
1202:          ///
1203:          /// </summary>
1204:          public static bool StaffCanUploadGponPhaseIiHomeConnectionAndMigrationCsvFile(Ia.Ngn.Cl.Model.Staff staff)
1205:          {
1206:              bool isAllowed;
1207:   
1208:              if (staff != null)
1209:              {
1210:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1211:                  else isAllowed = false;
1212:              }
1213:              else isAllowed = false;
1214:   
1215:              return isAllowed;
1216:          }
1217:   
1218:          ////////////////////////////////////////////////////////////////////////////
1219:   
1220:          /// <summary>
1221:          ///
1222:          /// </summary>
1223:          public static bool FrameworkCanReadStatistics(Ia.Ngn.Cl.Model.Business.Administration.Framework framework)
1224:          {
1225:              bool isAllowed;
1226:   
1227:              if (framework != null)
1228:              {
1229:                  if (FrameworkIsSuperFramework(framework)) isAllowed = true;
1230:                  else isAllowed = false;
1231:              }
1232:              else isAllowed = true; // for now I will allow users with framework = null coming form telegram
1233:   
1234:              return isAllowed;
1235:          }
1236:   
1237:          ////////////////////////////////////////////////////////////////////////////
1238:   
1239:          /// <summary>
1240:          ///
1241:          /// </summary>
1242:          public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction function, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact)
1243:          {
1244:              bool isAllowed;
1245:   
1246:              if (staffContact != null)
1247:              {
1248:                  if (function == PersistentStorageFunction.Create)
1249:                  {
1250:                      isAllowed = true;
1251:                  }
1252:                  else if (function == PersistentStorageFunction.Read)
1253:                  {
1254:                      isAllowed = true;
1255:                  }
1256:                  else if (function == PersistentStorageFunction.Update)
1257:                  {
1258:                      isAllowed = false;
1259:                  }
1260:                  else if (function == PersistentStorageFunction.Delete)
1261:                  {
1262:                      isAllowed = false;
1263:                  }
1264:                  else
1265:                  {
1266:                      isAllowed = false;
1267:                  }
1268:              }
1269:              else isAllowed = false;
1270:   
1271:              return isAllowed;
1272:          }
1273:   
1274:          ////////////////////////////////////////////////////////////////////////////
1275:          ////////////////////////////////////////////////////////////////////////////
1276:   
1277:          /// <summary>
1278:          ///
1279:          /// </summary>
1280:          public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ngn.Cl.Model.Staff staff)
1281:          {
1282:              bool isAllowed;
1283:   
1284:              if (staff != null)
1285:              {
1286:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1287:                  //else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
1288:                  else isAllowed = false;
1289:              }
1290:              else isAllowed = false;
1291:   
1292:              return isAllowed;
1293:          }
1294:   
1295:          ////////////////////////////////////////////////////////////////////////////
1296:   
1297:          /// <summary>
1298:          ///
1299:          /// </summary>
1300:          public static bool StaffCanReadUpdateService2Access(Ia.Ngn.Cl.Model.Staff staff)
1301:          {
1302:              bool isAllowed;
1303:   
1304:              if (staff != null)
1305:              {
1306:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1307:                  else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات" && staff.IsHead) isAllowed = true;
1308:                  else if (staff.Framework.ArabicName == "هواوي" && staff.IsHead) isAllowed = true;
1309:                  else isAllowed = false;
1310:              }
1311:              else isAllowed = false;
1312:   
1313:              return isAllowed;
1314:          }
1315:   
1316:          ////////////////////////////////////////////////////////////////////////////
1317:   
1318:          /// <summary>
1319:          ///
1320:          /// </summary>
1321:          public static bool StaffCanMigratePremisesFromPstnToGpon(Ia.Ngn.Cl.Model.Staff staff)
1322:          {
1323:              // see related sister function StaffCanMigratePremisesFromPstnToGponForNddOnt()
1324:              bool isAllowed;
1325:   
1326:              if (staff != null)
1327:              {
1328:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1329:                  else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1330:                  else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
1331:                  else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
1332:                  else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
1333:                  else
1334:                  {
1335:                      if (staff.Framework != null && staff.Framework.Sites != null && staff.Framework.Sites.Count > 0)
1336:                      {
1337:                          var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
1338:   
1339:                          isAllowed = staff.Framework.Sites.Any(u => u.Routers.Any(v => v.Odfs.Any(w => w.Olts.Any(x => list.Contains(x.Id)))));
1340:                      }
1341:                      else isAllowed = false;
1342:                  }
1343:              }
1344:              else isAllowed = false;
1345:   
1346:              return isAllowed;
1347:          }
1348:   
1349:          ////////////////////////////////////////////////////////////////////////////
1350:   
1351:          /// <summary>
1352:          ///
1353:          /// </summary>
1354:          public static bool StaffCanMigratePremisesFromPstnToGponForNddOnt(Ia.Ngn.Cl.Model.Staff staff, Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Ont nddOnt)
1355:          {
1356:              // see related sister function StaffCanMigratePremisesFromPstnToGpon()
1357:              bool isAllowed;
1358:   
1359:              if (staff != null)
1360:              {
1361:                  if (nddOnt != null)
1362:                  {
1363:                      var list = Ia.Ngn.Cl.Model.Data.Service.AllowedToBeMigratedOltIdList;
1364:   
1365:                      if (list.Contains(nddOnt.Pon.PonGroup.Olt.Id))
1366:                      {
1367:                          if (StaffIsSuperUser(staff)) isAllowed = true;
1368:                          else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
1369:                          else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
1370:                          else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
1371:                          else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
1372:                          else
1373:                          {
1374:                              if (staff.Framework != null && staff.Framework.Sites != null && staff.Framework.Sites.Count > 0)
1375:                              {
1376:                                  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))));
1377:                              }
1378:                              else isAllowed = false;
1379:                          }
1380:                      }
1381:                      else isAllowed = false;
1382:                  }
1383:                  else isAllowed = false;
1384:              }
1385:              else isAllowed = false;
1386:   
1387:              return isAllowed;
1388:          }
1389:   
1390:          ////////////////////////////////////////////////////////////////////////////
1391:   
1392:          /// <summary>
1393:          ///
1394:          /// </summary>
1395:          public static bool StaffCanAccessAdministationFolder(Ia.Ngn.Cl.Model.Staff staff)
1396:          {
1397:              bool isAllowed;
1398:   
1399:              /*
1400:               * <allow roles="Application,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة,إدارة مشاريع الشبكة الهاتفية"/>
1401:               * <deny users="*"/>
1402:               * <allow users="mohammad"/>
1403:               */
1404:   
1405:              string[] sp = { "Application", "إدارة شبكة الألياف الضوئية", "مراقبة خدمات الشبكة", "مراقبة الدعم الفنى للشبكة", "مراقبة تقنية المعلومات", "مراقبة تشغيل الشبكة", "قسم دعم تشغيل الشبكة", "إدارة مشاريع الشبكة الهاتفية" };
1406:   
1407:              if (staff != null)
1408:              {
1409:                  if (StaffIsSuperUser(staff)) isAllowed = true;
1410:                  else if (staff.IsHead && staff.User.UserName == "mohammad") isAllowed = true;
1411:                  else if (sp.Contains(staff.Framework.ArabicName)) isAllowed = true;
1412:                  else isAllowed = false;
1413:              }
1414:              else isAllowed = false;
1415:   
1416:              return isAllowed;
1417:          }
1418:   
1419:          ////////////////////////////////////////////////////////////////////////////
1420:   
1421:          /// <summary>
1422:          ///
1423:          /// </summary>
1424:          public static bool StaffIsApplication(Ia.Ngn.Cl.Model.Staff staff)
1425:          {
1426:              bool isAllowed;
1427:   
1428:              if (staff != null)
1429:              {
1430:                  if (staff.Framework.ArabicName == "قسم دعم تشغيل الشبكة") isAllowed = true;
1431:                  else isAllowed = false;
1432:              }
1433:              else isAllowed = false;
1434:   
1435:              return isAllowed;
1436:          }
1437:   
1438:          ////////////////////////////////////////////////////////////////////////////
1439:   
1440:          /// <summary>
1441:          ///
1442:          /// </summary>
1443:          public static bool StaffIsInCustomerServiceSector(Ia.Ngn.Cl.Model.Staff staff)
1444:          {
1445:              bool isAllowed;
1446:   
1447:              if (staff != null)
1448:              {
1449:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == "قطاع خدمات المشتركين")) isAllowed = true;
1450:                  else isAllowed = false;
1451:              }
1452:              else isAllowed = false;
1453:   
1454:              return isAllowed;
1455:          }
1456:   
1457:          ////////////////////////////////////////////////////////////////////////////
1458:   
1459:          /// <summary>
1460:          ///
1461:          /// </summary>
1462:          public static bool StaffIsInOpticalFiberNetworkDepartment(Ia.Ngn.Cl.Model.Staff staff)
1463:          {
1464:              bool isAllowed;
1465:   
1466:              if (staff != null)
1467:              {
1468:                  if (staff.Framework.ArabicName == "إدارة شبكة الألياف الضوئية" || staff.Framework.Ancestors.Any(u => u.ArabicName == "إدارة شبكة الألياف الضوئية")) isAllowed = true;
1469:                  else if (staff.Framework.ArabicName == "إدارة مشاريع الشبكة الهاتفية" || staff.Framework.Ancestors.Any(u => u.ArabicName == "إدارة مشاريع الشبكة الهاتفية")) isAllowed = true; // temp
1470:                  else isAllowed = false;
1471:              }
1472:              else isAllowed = false;
1473:   
1474:              return isAllowed;
1475:          }
1476:   
1477:          ////////////////////////////////////////////////////////////////////////////
1478:   
1479:          /// <summary>
1480:          ///
1481:          /// </summary>
1482:          public static bool StaffIsSupplier(Ia.Ngn.Cl.Model.Staff staff)
1483:          {
1484:              bool isAllowed;
1485:   
1486:              if (staff != null)
1487:              {
1488:                  if (staff.Framework.ArabicName == "نوكيا" || staff.Framework.ArabicName == "هواوي") isAllowed = true;
1489:                  else isAllowed = false;
1490:              }
1491:              else isAllowed = false;
1492:   
1493:              return isAllowed;
1494:          }
1495:   
1496:          ////////////////////////////////////////////////////////////////////////////
1497:   
1498:          /// <summary>
1499:          ///
1500:          /// </summary>
1501:          public static bool StaffIsInRole(Ia.Ngn.Cl.Model.Staff staff, string role)
1502:          {
1503:              bool isAllowed;
1504:   
1505:              if (staff != null)
1506:              {
1507:                  if (staff.Framework.Ancestors.Any(u => u.ArabicName == role)) isAllowed = true;
1508:                  else isAllowed = false;
1509:              }
1510:              else isAllowed = false;
1511:   
1512:              return isAllowed;
1513:          }
1514:   
1515:          ////////////////////////////////////////////////////////////////////////////
1516:          ////////////////////////////////////////////////////////////////////////////
1517:   
1518:          /// <summary>
1519:          ///
1520:          /// </summary>
1521:          public static List<Tuple<string, string>> EmailRecipientTupleList(string function)
1522:          {
1523:              List<Tuple<string, string>> recipientTupleList;
1524:   
1525:              recipientTupleList = new List<Tuple<string, string>>();
1526:   
1527:              switch (function)
1528:              {
1529:                  case "list-with-ont-list-provisioned-and-ready-but-do-not-exist-in-customer-department-database":
1530:                  case "list-of-pstn-to-gpon-migrated-and-provisioned-services-in-allowed-to-be-migrated-olts":
1531:                      {
1532:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1533:                          recipientTupleList.Add(new Tuple<string, string>("E. Shatti", "emad@moc.gov.kw"));
1534:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1535:   
1536:                          break;
1537:                      }
1538:                  case "ofn-status-report":
1539:                      {
1540:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1541:                          break;
1542:                      }
1543:                  case "ofn-statistics-report":
1544:                      {
1545:                          recipientTupleList.Add(new Tuple<string, string>("MOC Traffic Section", "traffic_section@yahoo.com"));
1546:                          //recipientTupleList.Add(new Tuple<string, string>("M. Zaid", "mshalzaid@hotmail.com"));
1547:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1548:                          break;
1549:                      }
1550:                  case "ofn-nokia-report":
1551:                      {
1552:                          recipientTupleList.Add(new Tuple<string, string>("O. Kandemir", "oguzhan.kandemir@nokia.com"));
1553:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1554:                          break;
1555:                      }
1556:                  case "ofn-huawei-report":
1557:                      {
1558:                          recipientTupleList.Add(new Tuple<string, string>("J. Shamlan", "j.alshamlan@gmail.com"));
1559:                          break;
1560:                      }
1561:                  default: break;
1562:              }
1563:   
1564:              return recipientTupleList;
1565:          }
1566:   
1567:          ////////////////////////////////////////////////////////////////////////////
1568:          ////////////////////////////////////////////////////////////////////////////
1569:   
1570:          /// <summary>
1571:          ///
1572:          /// </summary>
1573:          public static bool ServiceRequestIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest)
1574:          {
1575:              // below: this skips processing some service requests due to misc problems
1576:              bool processingIsAllowed;
1577:   
1578:              if (serviceRequest.Id == 1719402 || serviceRequest.Id == 1875029) processingIsAllowed = false;
1579:              // 1719402    25232104    1    تم التنفيذ    2014-10-28 11:07    خط هاتف    هاتف    17    الادارة العامة للجمارك    جهات حكومية
1580:              // 1875029    25232104    1    تعذر التنفيذ    2016-02-24 00:00    رفع خط    هاتف    17    الادارة العامة للجمارك    جهات حكومية
1581:              else processingIsAllowed = true;
1582:   
1583:              return processingIsAllowed;
1584:          }
1585:   
1586:          ////////////////////////////////////////////////////////////////////////////
1587:   
1588:          /// <summary>
1589:          ///
1590:          /// </summary>
1591:          public static bool ServiceRequestHistoryIsAllowedProcessing(Ia.Ngn.Cl.Model.ServiceRequestHistory serviceRequestHistory)
1592:          {
1593:              // below: this skips processing some service requests due to misc problems
1594:              bool processingIsAllowed;
1595:   
1596:              if (serviceRequestHistory.Id == "25429778:1:965:0:66:2005-11-27") processingIsAllowed = false;
1597:              // prevent the removal of service group
1598:              else processingIsAllowed = true;
1599:   
1600:              return processingIsAllowed;
1601:          }
1602:   
1603:          ////////////////////////////////////////////////////////////////////////////
1604:   
1605:          /// <summary>
1606:          ///
1607:          /// </summary>
1608:          public static bool ServiceProcessingIsAllowed(string service)
1609:          {
1610:              // below: this skips processing some services due to misc problems
1611:              bool processingIsAllowed;
1612:   
1613:              if (!string.IsNullOrEmpty(service))
1614:              {
1615:                  if (Ia.Ngn.Cl.Model.Data.ServiceExemption.ServiceList().Contains(service)) processingIsAllowed = false;
1616:                  else processingIsAllowed = true;
1617:              }
1618:              else processingIsAllowed = true;
1619:   
1620:              return processingIsAllowed;
1621:          }
1622:   
1623:          ////////////////////////////////////////////////////////////////////////////
1624:          ////////////////////////////////////////////////////////////////////////////
1625:   
1626:          /// <summary>
1627:          ///
1628:          /// </summary>
1629:          public static bool TelegramUserCanReadFind(string chatId, int userId)
1630:          {
1631:              bool isAllowed;
1632:   
1633:              if (userId != 0)
1634:              {
1635:                  isAllowed = true;
1636:              }
1637:              else isAllowed = false;
1638:   
1639:              return isAllowed;
1640:          }
1641:   
1642:          ////////////////////////////////////////////////////////////////////////////    
1643:   
1644:          /// <summary>
1645:          ///
1646:          /// </summary>
1647:          public static bool NumberIsWithinFrameworkSiteDomainList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string service)
1648:          {
1649:              bool isWithin;
1650:   
1651:              if (framework != null)
1652:              {
1653:                  if (framework.Sites != null && framework.Sites.Count > 0)
1654:                  {
1655:                      if (framework.Sites.Any(w => w.DomainList.Any(u => service.StartsWith(u.ToString())))) isWithin = true;
1656:                      else isWithin = true; // false; temp
1657:                  }
1658:                  else isWithin = true; // will allow number for framework.Site == null
1659:              }
1660:              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.
1661:   
1662:              return isWithin;
1663:          }
1664:   
1665:          ////////////////////////////////////////////////////////////////////////////    
1666:   
1667:          /// <summary>
1668:          ///
1669:          /// </summary>
1670:          public static bool AccessNameIsWithinFrameworkSiteAreaSymbolList(Ia.Ngn.Cl.Model.Business.Administration.Framework framework, string accessName)
1671:          {
1672:              bool isWithin;
1673:   
1674:              if (framework != null)
1675:              {
1676:                  if (framework.Sites != null && framework.Sites.Count > 0)
1677:                  {
1678:                      if (framework.Sites.Any(u => u.AreaSymbolList.Any(v => accessName.StartsWith(v.ToString())))) isWithin = true;
1679:                      else isWithin = true; // false; temp
1680:                  }
1681:                  else isWithin = true; // will allow number for framework.Site == null
1682:              }
1683:              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.
1684:   
1685:              return isWithin;
1686:          }
1687:   
1688:          ////////////////////////////////////////////////////////////////////////////    
1689:   
1690:          /// <summary>
1691:          ///
1692:          /// </summary>
1693:          public static void UpdateAdministrativeFrameworkRolesOfStaff(Ia.Ngn.Cl.Model.Staff staff)
1694:          {
1695:              string userName;
1696:              MembershipUser membershipUser;
1697:   
1698:              membershipUser = Membership.GetUser(staff.UserId);
1699:   
1700:              if (membershipUser != null)
1701:              {
1702:                  userName = membershipUser.UserName;
1703:   
1704:                  // add user to IsHead role if he is head, and remove him otherwise
1705:                  if (staff.IsHead)
1706:                  {
1707:                      if (!Roles.IsUserInRole(userName, "IsHead")) Roles.AddUserToRole(userName, "IsHead");
1708:                  }
1709:                  else
1710:                  {
1711:                      if (Roles.IsUserInRole(userName, "IsHead")) Roles.RemoveUserFromRole(userName, "IsHead");
1712:                  }
1713:   
1714:                  // add user to its direct role
1715:                  if (!Roles.IsUserInRole(userName, staff.Framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, staff.Framework.FullyQualifiedArabicName);
1716:   
1717:                  // add user to its decendants roles
1718:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in staff.Framework.Descendants)
1719:                  {
1720:                      if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
1721:                  }
1722:   
1723:                  // add user to its ancestors roles
1724:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in staff.Framework.Ancestors)
1725:                  {
1726:                      if (!Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName)) Roles.AddUserToRole(userName, framework.FullyQualifiedArabicName);
1727:                  }
1728:   
1729:                  // loop through all user roles and remove it from roles not in his description
1730:                  foreach (Ia.Ngn.Cl.Model.Business.Administration.Framework framework in Ia.Ngn.Cl.Model.Data.Administration.FrameworkList)
1731:                  {
1732:                      if (framework.Id != staff.Framework.Id
1733:                          && !staff.Framework.Descendants.Any(f => f.Id == framework.Id)
1734:                          && !staff.Framework.Ancestors.Any(f => f.Id == framework.Id)
1735:                          && Roles.IsUserInRole(userName, framework.FullyQualifiedArabicName))
1736:                          Roles.RemoveUserFromRole(userName, framework.FullyQualifiedArabicName);
1737:                  }
1738:              }
1739:          }
1740:   
1741:          ////////////////////////////////////////////////////////////////////////////
1742:          ////////////////////////////////////////////////////////////////////////////    
1743:      }
1744:   
1745:      ////////////////////////////////////////////////////////////////////////////
1746:      ////////////////////////////////////////////////////////////////////////////   
1747:  }