)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Authority (Ia.Ftn.Cl.Models.Business)

Public general use code classes and xml files that we've compiled and used over the years:

Authority support class of Fixed Telecommunications Network (FTN) business model.

    1: using Microsoft.AspNetCore.Identity;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Data;
    5: using System.Linq;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Business
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Authority support class of Fixed Telecommunications Network (FTN) 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:     /// </remarks> 
   18:     public class Authority
   19:     {
   20:         public enum SchedularFunction
   21:         {
   22:             ListOfPreviouslyPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport = 1,
   23:             ListOfPreviouslyQrnPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   24:             ListOfPreviouslyJblPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   25:             ListOfPreviouslySsbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   26:             ListOfPreviouslySlmaPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   27:             ListOfPreviouslySlmbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   28:             ListOfPreviouslyMsfPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   29:             ListOfPreviouslyFhhPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport,
   30:             StatusReport,
   31:             StatisticsReport,
   32:             NokiaReport,
   33:             HuaweiReport,
   34:             Maintenance,
   35:             Heartbeat,
   36:         };
   37:  
   38:         public enum PersistentStorageFunction { Create = 1, Read, Update, Delete };
   39:  
   40:         /// <summary/>
   41:         public int Id { get; set; }
   42:  
   43:         /// <summary/>
   44:         public string Name { get; set; }
   45:  
   46:         /// <summary/>
   47:         public string ArabicName { get; set; }
   48:  
   49:         /// <summary/>
   50:         public string AllowedFrameworkArabicName { get; set; }
   51:  
   52:         /// <summary/>
   53:         public bool HeadOnly { get; set; }
   54:  
   55:         /// <summary/>
   56:         public string Medium { get; set; }
   57:  
   58:         /// <summary/>
   59:         public string System { get; set; }
   60:  
   61:         /// <summary/>
   62:         public string Process { get; set; }
   63:  
   64:         /// <summary/>
   65:         public string Function { get; set; }
   66:  
   67:         /// <summary/>
   68:         public string ParameterRegex { get; set; }
   69:  
   70:         /// <summary/>
   71:         public string ResponseRegex { get; set; }
   72:  
   73:         /// <summary/>
   74:         public string Help { get; set; }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         ///
   80:         /// </summary>
   81:         public Authority() { }
   82:  
   83:         ////////////////////////////////////////////////////////////////////////////    
   84:  
   85:         /// <summary>
   86:         ///
   87:         /// </summary>
   88:         public int AuthorityId(int parentId, int authorityId)
   89:         {
   90:             return parentId * 10 + authorityId;
   91:         }
   92:  
   93:         ////////////////////////////////////////////////////////////////////////////    
   94:  
   95:         /// <summary>
   96:         ///
   97:         /// </summary>
   98:         public int ParentId(long authorityId)
   99:         {
  100:             int i;
  101:             string s;
  102:  
  103:             s = authorityId.ToString();
  104:  
  105:             if (s.Length > 2)
  106:             {
  107:                 s = s.Substring(0, s.Length - 2);
  108:  
  109:                 i = (int.TryParse(s, out i)) ? i : 0;
  110:             }
  111:             else i = 0;
  112:  
  113:             return i;
  114:         }
  115:  
  116:         ////////////////////////////////////////////////////////////////////////////    
  117:  
  118:         /// <summary>
  119:         ///
  120:         /// </summary>
  121:         public static List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework> StaffFrameworkListOfAllowedReportAssignsByStaff(Ia.Ftn.Cl.Models.Report report, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  122:         {
  123:             List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework> frameworkList, specialList, special2List, special3List, special4List, list;
  124:  
  125:             Ia.Ftn.Cl.Models.Business.Administration.StaffFramework staffHead;
  126:  
  127:             var staffList = new List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework>();
  128:  
  129:             if (staff.Head != null)
  130:             {
  131:                 staffHead = new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  132:                 {
  133:                     Id = staff.Head.Id,
  134:                     IsStaff = true,
  135:                     Name = staff.Head.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
  136:                 };
  137:  
  138:                 staffList.Add(staffHead);
  139:             }
  140:  
  141:             var subordinatesList = (from s in staff.Subordinates
  142:                                     select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  143:                                     {
  144:                                         Id = s.Id,
  145:                                         IsStaff = true,
  146:                                         Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
  147:                                     }).ToList();
  148:  
  149:             var colleagueList = (from s in staff.Colleagues
  150:                                  select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  151:                                  {
  152:                                      Id = s.Id,
  153:                                      IsStaff = true,
  154:                                      Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
  155:                                  }).ToList();
  156:  
  157:  
  158:             staffList = staffList.Union(subordinatesList).Union(colleagueList).ToList();
  159:  
  160:             // framework list: framework descendants, siblings and uncles (for head staff only)
  161:             if (staff.Framework.Parent != null)
  162:             {
  163:                 if (staff.IsHead)
  164:                 {
  165:                     frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Union(staff.Framework.Parent.Siblings).Concat(new[] { staff.Framework.Parent })
  166:                                      select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  167:                                      {
  168:                                          Id = f.Id,
  169:                                          IsFramework = true,
  170:                                          Name = f.FullyQualifiedArabicName //.ArabicName
  171:                                      }).OrderBy(c => c.Id).ToList();
  172:                 }
  173:                 else
  174:                 {
  175:                     frameworkList = (from f in staff.Framework.Siblings.Union(staff.Framework.Descendants).Concat(new[] { staff.Framework.Parent })
  176:                                      select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  177:                                      {
  178:                                          Id = f.Id,
  179:                                          IsFramework = true,
  180:                                          Name = f.FullyQualifiedArabicName //.ArabicName
  181:                                      }).OrderBy(c => c.Id).ToList();
  182:                 }
  183:             }
  184:             else
  185:             {
  186:                 frameworkList = (from f in staff.Framework.Descendants
  187:                                  select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  188:                                  {
  189:                                      Id = f.Id,
  190:                                      IsFramework = true,
  191:                                      Name = f.FullyQualifiedArabicName //.ArabicName
  192:                                  }).OrderBy(c => c.Id).ToList();
  193:             }
  194:  
  195:             // special list: list of special administrative assignments to certain staff and frameworks
  196:             if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة" || staff.Framework.ArabicName == "قسم تشغيل الخدمات")
  197:             {
  198:                 specialList = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  199:                                where
  200:                                f.FullyQualifiedArabicName == "وزارة المواصلات | قطاع الاتصالات والخدمات المساندة | إدارة صيانة الشبكة الهاتفية | مراقبة الصيانة | قسم الصيانة"
  201:                                || f.FullyQualifiedArabicName == "نوكيا"
  202:                                || f.FullyQualifiedArabicName == "هواوي"
  203:                                || f.FullyQualifiedArabicName == "التطبيقات المتكاملة"
  204:                                || f.FullyQualifiedArabicName.Contains("وزارة المواصلات | قطاع الاتصالات والخدمات المساندة | إدارة شبكة الألياف الضوئية")
  205:                                || (f.FullyQualifiedArabicName.Contains("قسم الصيانة وتركيبات الهاتف") && f.FullyQualifiedArabicName.Contains("وزارة المواصلات | قطاع خدمات المشتركين"))
  206:                                || (f.FullyQualifiedArabicName.Contains("قسم الفحص والشكاوى") && f.FullyQualifiedArabicName.Contains("وزارة المواصلات | قطاع خدمات المشتركين"))
  207:                                select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  208:                                {
  209:                                    Id = f.Id,
  210:                                    IsFramework = true,
  211:                                    Name = f.FullyQualifiedArabicName //.ArabicName
  212:                                }).OrderBy(c => c.Id).ToList();
  213:             }
  214:             else if (staff.Framework.FullyQualifiedArabicName.Contains("وزارة المواصلات | قطاع خدمات المشتركين"))
  215:             {
  216:                 // قطاع خدمات المشتركين need to assign to قسم الدعم الفني للشبك
  217:                 specialList = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  218:                                where f.ArabicName == "قسم الدعم الفني للشبكة" || f.ArabicName == "قسم تشغيل الخدمات"
  219:                                select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  220:                                {
  221:                                    Id = f.Id,
  222:                                    IsFramework = true,
  223:                                    Name = f.FullyQualifiedArabicName //.ArabicName
  224:                                }).OrderBy(c => c.Id).ToList();
  225:             }
  226:             else
  227:             {
  228:                 specialList = new List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework>();
  229:             }
  230:  
  231:             // special: ability to assign to report creator
  232:             var list2 = (from f in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List() where f.Framework != null select f).ToList();
  233:  
  234:             special2List = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  235:                             join s in list2 on f.Id equals s.Framework.Id
  236:                             where s.Framework != null && report.StaffIdentityUser != null && s.Id == report.StaffIdentityUser.Id
  237:                             select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  238:                             {
  239:                                 Id = f.Id,
  240:                                 IsFramework = true,
  241:                                 Name = f.FullyQualifiedArabicName //.ArabicName
  242:                             }).OrderBy(c => c.Id).ToList();
  243:  
  244:             // list of all staff members already report history excluding self
  245:             if (report.ReportHistories != null && report.ReportHistories.Count > 0)
  246:             {
  247:                 special3List = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
  248:                                 where (report.ReportHistories.Any(u => u.StaffIdentityUser.Id == s.Id)) && staff.Id != s.Id
  249:                                 select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  250:                                 {
  251:                                     Id = s.Id,
  252:                                     IsStaff = true,
  253:                                     Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
  254:                                 }).OrderBy(c => c.Id).ToList();
  255:             }
  256:             else
  257:             {
  258:                 special3List = new List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework>();
  259:             }
  260:  
  261:             // list of staff member who created report excluding self
  262:             special4List = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
  263:                             where report.StaffIdentityUser != null && report.StaffIdentityUser.Id == s.Id && staff.Id != s.Id
  264:                             select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  265:                             {
  266:                                 Id = s.Id,
  267:                                 IsStaff = true,
  268:                                 Name = s.FirstAndMiddleNameBracketFrameworkArabicNameAndFrameworkParentArabicNameBracket
  269:                             }).OrderBy(c => c.Id).ToList();
  270:  
  271:             list = staffList.Union(frameworkList).Union(specialList).Union(special2List).Union(special3List).Union(special4List).ToList();
  272:  
  273:             list = list.GroupBy(u => u.Id).Select(u => u.FirstOrDefault()).ToList(); // returns distinct records
  274:  
  275:             list = list.Where(u => !string.IsNullOrEmpty(u.Id)).ToList();
  276:  
  277:             return list.OrderBy(c => c.IsFramework).ToList();
  278:         }
  279:  
  280:         ////////////////////////////////////////////////////////////////////////////    
  281:  
  282:         /// <summary>
  283:         ///
  284:         /// </summary>
  285:         public static bool StaffCanCreateReadUpdateDeleteReport(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ftn.Cl.Models.Report report, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  286:         {
  287:             bool isAllowed;
  288:  
  289:             if (staff != null)
  290:             {
  291:                 if (StaffIsSuperUser(staff)) isAllowed = true;
  292:                 else
  293:                 {
  294:                     if (persistentStorageFunction == PersistentStorageFunction.Delete)
  295:                     {
  296:                         /*
  297:                         // below: a report can only be deleted by:
  298:                         // - one of the heads of the reporter.
  299:                         // - the reporter if he is a head
  300: 
  301:                         if (report.LastReportHistory == null && staff.Id == report.StaffIdentityUser.Id && staff.IsHead) isAllowed = true;
  302:                         else if (report.LastReportHistory != null && staff.Id == report.LastReportHistory.StaffIdentityUser.Id && staff.IsHead) isAllowed = true;
  303:                         else if (report.LastReportHistory == null && staff.IsHead) isAllowed = true;
  304:                         else if (staff.Subordinates != null)
  305:                         {
  306:                             if (report.LastReportHistory != null) isAllowed = staff.Subordinates.Any(i => i.StaffIdentityUser.Id == report.LastReportHistory.StaffIdentityUser.Id);
  307:                             else isAllowed = staff.Subordinates.Any(i => i.StaffIdentityUser.Id == report.StaffIdentityUser.Id);
  308:                         }
  309:                         else isAllowed = false;
  310:                         */
  311:  
  312:                         isAllowed = false; // reports can't be deleted by staff other than super user
  313:                     }
  314:                     else
  315:                     {
  316:                         isAllowed = false; // undefined CRU
  317:                     }
  318:                 }
  319:             }
  320:             else isAllowed = false;
  321:  
  322:             return isAllowed;
  323:         }
  324:  
  325:         ////////////////////////////////////////////////////////////////////////////    
  326:  
  327:         /// <summary>
  328:         ///
  329:         /// </summary>
  330:         public static bool StaffCanSendFieldTnmdSupplierWorkorderEmail(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  331:         {
  332:             bool isAllowed;
  333:  
  334:             if (staff != null)
  335:             {
  336:                 if (staff.IsHead) isAllowed = true;
  337:                 else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
  338:                 else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
  339:                 else isAllowed = false;
  340:             }
  341:             else isAllowed = false;
  342:  
  343:             return isAllowed;
  344:         }
  345:  
  346:         ////////////////////////////////////////////////////////////////////////////    
  347:  
  348:         /// <summary>
  349:         ///
  350:         /// </summary>
  351:         public static bool StaffCanCreateReadUpdateDeleteReportHistory(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Report report, Ia.Ftn.Cl.Models.ReportHistory reportHistory, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  352:         {
  353:             // below: I have to pass both Report and ReportHistory objects separately
  354:  
  355:             bool isAllowed;
  356:  
  357:             if (staff != null)
  358:             {
  359:                 if (StaffIsSuperUser(staff)) isAllowed = true;
  360:                 else
  361:                 {
  362:                     if (function == PersistentStorageFunction.Delete)
  363:                     {
  364:                         // below: a report history can only be deleted by:
  365:                         // - one of the heads of the history user
  366:                         // - the history user if he is a head
  367:  
  368:                         /*
  369:                         if (reportHistory != null)
  370:                         {
  371:                             if (reportHistory.Report.ReportHistories.Max(r => r.Id) != reportHistory.Id) isAllowed = false;
  372:                             else
  373:                             {
  374:                                 if (staff.Id == reportHistory.StaffIdentityUser.Id && staff.IsHead) isAllowed = true;
  375:                                 else if (staff.Subordinates != null) isAllowed = staff.Subordinates.Any(i => i.StaffIdentityUser.Id == reportHistory.StaffIdentityUser.Id);
  376:                                 else isAllowed = false;
  377:                             }
  378:                         }
  379:                         else isAllowed = false;
  380:                         */
  381:  
  382:                         isAllowed = false; // report history can't be deleted by staff other than super user
  383:                     }
  384:                     else if (function == PersistentStorageFunction.Create)
  385:                     {
  386:                         // below: for create reportHistory must be null
  387:  
  388:                         // below: a report history can be created if:
  389:                         // - report userid is subordinate of staff
  390:                         // - report history userid framework is within staff frameworks
  391:  
  392:                         if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
  393:                         else if (staff.IsHead && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
  394:                         else if (report != null && reportHistory == null)
  395:                         {
  396:                             if (report.ReportHistories.Count == 0 && staff.Id == report.StaffIdentityUser.Id) isAllowed = true;
  397:                             else if (report.ReportHistories.Count == 0 && report.StatusIsOpen) isAllowed = true;
  398:  
  399:                             //else if (report.LastReportHistory != null && !staff.Colleagues.Any(r => r.StaffIdentityUser.Id == report.LastReportHistory.StaffIdentityUser.Id) && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;  // temp
  400:  
  401:                             else if (report.LastReportHistory != null && staff.SubordinatesOrSelf.Any(i => i.Id == report.LastReportHistory.StaffIdentityUser.Id)) isAllowed = true;
  402:                             else if (Ia.Ftn.Cl.Models.Business.Administration.IsFrameworkId(report.StaffIdentityUser.Id) && staff.Framework.DescendantsOrSelf.Any(u => u.Id == report.StaffIdentityUser.Id)) isAllowed = true;
  403:                             else if (Ia.Ftn.Cl.Models.Business.Administration.IsFrameworkId(report.LastReportHistory.StaffIdentityUser.Id) && report.LastReportHistory != null && (staff.Framework.DescendantsOrSelf.Any(u => u.Id == report.LastReportHistory.StaffIdentityUser.Id) || staff.Framework.Ancestors.Any(u => u.Id == report.LastReportHistory.StaffIdentityUser.Id))) isAllowed = true;
  404:                             else isAllowed = false;
  405:                         }
  406:                         else isAllowed = false;
  407:                     }
  408:                     else
  409:                     {
  410:                         // below: a report history can be read, and updated if:
  411:                         // - report history UserId is same as staff's
  412:                         // - report userid is subordinate of staff
  413:                         // - report history userid framework is within staff frameworks
  414:  
  415:                         if (staff.IsHead && staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
  416:                         else if (staff.IsHead && staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
  417:                         else if (reportHistory != null)
  418:                         {
  419:                             if (staff.Id == reportHistory.StaffIdentityUser.Id) isAllowed = true;
  420:                             else if (staff.Subordinates.Any(u => u.Id == reportHistory.StaffIdentityUser.Id)) isAllowed = true;
  421:                             else if (Ia.Ftn.Cl.Models.Business.Administration.IsFrameworkId(reportHistory.StaffIdentityUser.Id))
  422:                             {
  423:                                 if (staff.Framework.DescendantsOrSelf.Any(u => u.Id == reportHistory.StaffIdentityUser.Id)) isAllowed = true;
  424:                                 else isAllowed = false;
  425:                             }
  426:                             else isAllowed = false;
  427:                         }
  428:                         else isAllowed = false;
  429:                     }
  430:                 }
  431:             }
  432:             else isAllowed = false;
  433:  
  434:             return isAllowed;
  435:         }
  436:  
  437:         ////////////////////////////////////////////////////////////////////////////    
  438:  
  439:         /// <summary>
  440:         ///
  441:         /// </summary>
  442:         public static bool StaffCanCreateReadUpdateDeleteUsers(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  443:         {
  444:             bool isAllowed;
  445:  
  446:             if (staff != null)
  447:             {
  448:                 if (StaffIsSuperUser(staff)) isAllowed = true;
  449:                 else
  450:                 {
  451:                     if (staff.Framework.Name == "IsSecretary") isAllowed = true;
  452:                     else isAllowed = false;
  453:                 }
  454:             }
  455:             else isAllowed = false;
  456:  
  457:             return isAllowed;
  458:         }
  459:  
  460:         ////////////////////////////////////////////////////////////////////////////    
  461:  
  462:         /// <summary>
  463:         ///
  464:         /// </summary>
  465:         public static bool StaffCanReopenClosedReport(Ia.Ftn.Cl.Models.Report report, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  466:         {
  467:             return StaffCanCloseReport(report, staff);
  468:         }
  469:  
  470:         ////////////////////////////////////////////////////////////////////////////    
  471:  
  472:         /// <summary>
  473:         ///
  474:         /// </summary>
  475:         public static bool StaffCanCloseReport(Ia.Ftn.Cl.Models.Report report, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  476:         {
  477:             bool canClose;
  478:  
  479:             if (staff != null)
  480:             {
  481:                 if (StaffIsSuperUser(staff)) canClose = true;
  482:                 //else if (FrameworkCanCloseReport(staff.Framework)) canClose = true; // make dedicated users to check with subscribers if reports are resolved
  483:                 else
  484:                 {
  485:                     if (report.LastReportHistory != null)
  486:                     {
  487:                         if (staff.IsHead)
  488:                         {
  489:                             if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") canClose = true;
  490:                             else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") canClose = true;
  491:                             else if (staff.Id == report.StaffIdentityUser.Id) canClose = true; // the report closer staff is himself
  492:                             else if (
  493:                                 (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قسم الفحص والشكاوى") || staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قسم الصيانة وتركيبات الهاتف"))
  494:                                 && staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "قطاع خدمات المشتركين")
  495:                                 && (staff.SubordinatesOrSelf.Any(u => u.Id == report.StaffIdentityUser.Id)))
  496:                                 canClose = true;
  497:                             else if (staff.Subordinates.Any(u => u.Id == report.LastReportHistory.StaffIdentityUser.Id)) canClose = true; // the report history closer staff is himself or a head
  498:                             else canClose = false;
  499:                         }
  500:                         else canClose = false;
  501:                     }
  502:                     else canClose = false;
  503:                 }
  504:             }
  505:             else canClose = false;
  506:  
  507:             return canClose;
  508:         }
  509:  
  510:         ////////////////////////////////////////////////////////////////////////////    
  511:  
  512:         /// <summary>
  513:         ///
  514:         /// </summary>
  515:         public static bool StaffCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  516:         {
  517:             bool isAllowed;
  518:  
  519:             if (staff != null)
  520:             {
  521:                 if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read)
  522:                 {
  523:                     if (StaffIsSuperUser(staff)) isAllowed = true;
  524:                     else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
  525:                     else if (staff.Framework.ArabicName == "نوكيا") isAllowed = true;
  526:                     else if (staff.Framework.ArabicName == "هواوي") isAllowed = true;
  527:                     else isAllowed = false;
  528:                 }
  529:                 else if (function == PersistentStorageFunction.Update)
  530:                 {
  531:                     if (StaffIsSuperUser(staff)) isAllowed = true;
  532:                     else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
  533:                     else isAllowed = false;
  534:                 }
  535:                 else if (function == PersistentStorageFunction.Delete)
  536:                 {
  537:                     if (StaffIsSuperUser(staff)) isAllowed = true;
  538:                     else isAllowed = false;
  539:                 }
  540:                 else isAllowed = false;
  541:             }
  542:             else isAllowed = false;
  543:  
  544:             return isAllowed;
  545:         }
  546:  
  547:         ////////////////////////////////////////////////////////////////////////////    
  548:  
  549:         /// <summary>
  550:         ///
  551:         /// </summary>
  552:         public static bool StaffCanCreateDeleteLicList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Msan msan)
  553:         {
  554:             bool isAllowed;
  555:  
  556:             if (staff != null)
  557:             {
  558:                 if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Delete)
  559:                 {
  560:                     if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanExecuteTasks(staff, true))
  561:                     {
  562:                         if (StaffIsSuperUser(staff)) isAllowed = true;
  563:                         else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
  564:                         else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
  565:                         else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
  566:                         else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
  567:                         else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
  568:                         else if (staff.Framework.ArabicName == "قسم تقنية المعلومات" && staff.IsHead) isAllowed = true;
  569:                         else if (staff.Framework != null && staff.Framework.Sites.Count > 0)
  570:                         {
  571:                             isAllowed = false;// staff.Framework.Sites.Any(u => u.Id == msan.Site.Id);
  572:                         }
  573:                         else isAllowed = false;
  574:                     }
  575:                     else isAllowed = false;
  576:                 }
  577:                 else isAllowed = false;
  578:             }
  579:             else isAllowed = false;
  580:  
  581:             return isAllowed;
  582:         }
  583:  
  584:         ////////////////////////////////////////////////////////////////////////////    
  585:  
  586:         /// <summary>
  587:         ///
  588:         /// </summary>
  589:         public static bool StaffCanCreateBulkLicList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  590:         {
  591:             bool isAllowed;
  592:  
  593:             if (staff != null)
  594:             {
  595:                 if (function == PersistentStorageFunction.Create)
  596:                 {
  597:                     if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanExecuteTasks(staff, true))
  598:                     {
  599:                         if (StaffIsSuperUser(staff)) isAllowed = true;
  600:                         else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
  601:                         else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
  602:                         else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
  603:                         else isAllowed = false;
  604:                     }
  605:                     else isAllowed = false;
  606:                 }
  607:                 else isAllowed = false;
  608:             }
  609:             else isAllowed = false;
  610:  
  611:             return isAllowed;
  612:         }
  613:  
  614:         ////////////////////////////////////////////////////////////////////////////    
  615:  
  616:         /// <summary>
  617:         ///
  618:         /// </summary>
  619:         public static bool StaffCanCreateReadUpdateDeleteInventoryList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  620:         {
  621:             bool isAllowed;
  622:  
  623:             if (staff != null)
  624:             {
  625:                 if (function == PersistentStorageFunction.Create || function == PersistentStorageFunction.Read || function == PersistentStorageFunction.Update || function == PersistentStorageFunction.Delete)
  626:                 {
  627:                     if (StaffIsSuperUser(staff)) isAllowed = true;
  628:                     else if (staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
  629:                     else isAllowed = false;
  630:                 }
  631:                 else isAllowed = false;
  632:             }
  633:             else isAllowed = false;
  634:  
  635:             return isAllowed;
  636:         }
  637:  
  638:         ////////////////////////////////////////////////////////////////////////////
  639:  
  640:         /// <summary>
  641:         ///
  642:         /// </summary>
  643:         public static bool StaffContactCanCreateReadUpdateDeleteNetworkDesignDocument(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.StaffContact staffContact)
  644:         {
  645:             bool isAllowed;
  646:  
  647:             if (staffContact != null)
  648:             {
  649:                 if (function == PersistentStorageFunction.Create) isAllowed = false;
  650:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
  651:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
  652:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
  653:                 else isAllowed = false;
  654:             }
  655:             else isAllowed = false;
  656:  
  657:             return isAllowed;
  658:         }
  659:  
  660:         ////////////////////////////////////////////////////////////////////////////
  661:  
  662:         /// <summary>
  663:         ///
  664:         /// </summary>
  665:         public static bool StaffContactCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.StaffContact staffContact)
  666:         {
  667:             bool isAllowed;
  668:  
  669:             if (staffContact != null)
  670:             {
  671:                 if (function == PersistentStorageFunction.Create) isAllowed = false;
  672:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
  673:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
  674:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
  675:                 else isAllowed = false;
  676:             }
  677:             else isAllowed = false;
  678:  
  679:             return isAllowed;
  680:         }
  681:  
  682:         ////////////////////////////////////////////////////////////////////////////
  683:  
  684:         /// <summary>
  685:         ///
  686:         /// </summary>
  687:         public static bool FrameworkCanCreateReadUpdateDeleteMaintenanceFind(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  688:         {
  689:             bool isAllowed;
  690:  
  691:             if (framework != null)
  692:             {
  693:                 if (function == PersistentStorageFunction.Create) isAllowed = false;
  694:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
  695:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
  696:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
  697:                 else isAllowed = false;
  698:             }
  699:             else isAllowed = false;
  700:  
  701:             return isAllowed;
  702:         }
  703:  
  704:         ////////////////////////////////////////////////////////////////////////////
  705:  
  706:         /// <summary>
  707:         ///
  708:         /// </summary>
  709:         public static bool StaffContactCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.StaffContact staffContact)
  710:         {
  711:             bool isAllowed;
  712:  
  713:             if (staffContact != null)
  714:             {
  715:                 if (function == PersistentStorageFunction.Create) isAllowed = true;
  716:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
  717:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
  718:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
  719:                 else isAllowed = false;
  720:             }
  721:             else isAllowed = false;
  722:  
  723:             return isAllowed;
  724:         }
  725:  
  726:         ////////////////////////////////////////////////////////////////////////////
  727:  
  728:         /// <summary>
  729:         ///
  730:         /// </summary>
  731:         public static bool FrameworkCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  732:         {
  733:             bool isAllowed;
  734:  
  735:             if (framework != null)
  736:             {
  737:                 if (function == PersistentStorageFunction.Create) isAllowed = true;
  738:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
  739:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
  740:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
  741:                 else isAllowed = false;
  742:             }
  743:             else isAllowed = false;
  744:  
  745:             return isAllowed;
  746:         }
  747:  
  748:         ////////////////////////////////////////////////////////////////////////////
  749:         ////////////////////////////////////////////////////////////////////////////
  750:  
  751:         /// <summary>
  752:         ///
  753:         /// </summary>
  754:         public static bool StaffCanCreateReadUpdateDeleteServicePort(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  755:         {
  756:             bool isAllowed;
  757:  
  758:             if (staff != null)
  759:             {
  760:                 if (StaffIsSuperUser(staff)) isAllowed = true;
  761:                 else isAllowed = false;
  762:             }
  763:             else isAllowed = false;
  764:  
  765:             return isAllowed;
  766:         }
  767:  
  768:         ////////////////////////////////////////////////////////////////////////////
  769:         ////////////////////////////////////////////////////////////////////////////
  770:  
  771:         /// <summary>
  772:         ///
  773:         /// </summary>
  774:         public static bool StaffCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  775:         {
  776:             bool isAllowed;
  777:  
  778:             if (staff != null)
  779:             {
  780:                 if (function == PersistentStorageFunction.Read)
  781:                 {
  782:                     isAllowed = true;
  783:                 }
  784:                 else if (function == PersistentStorageFunction.Update)
  785:                 {
  786:                     if (StaffIsSuperUser(staff)) isAllowed = true;
  787:                     else isAllowed = false;
  788:                 }
  789:                 else
  790:                 {
  791:                     isAllowed = false;
  792:                 }
  793:             }
  794:             else isAllowed = false;
  795:  
  796:             return isAllowed;
  797:         }
  798:  
  799:         ////////////////////////////////////////////////////////////////////////////
  800:  
  801:         /// <summary>
  802:         ///
  803:         /// </summary>
  804:         public static bool StaffContactCanReadUpdateServiceRequestAdministrativeIssue(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction persistentStorageFunction, Ia.Ftn.Cl.Models.Business.Administration.StaffContact staffContact)
  805:         {
  806:             bool isAllowed;
  807:  
  808:             if (staffContact != null)
  809:             {
  810:                 if (persistentStorageFunction == PersistentStorageFunction.Read)
  811:                 {
  812:                     if (StaffIsSuperUser(staffContact.StaffIdentityUser)) isAllowed = true;
  813:                     else isAllowed = false;
  814:                 }
  815:                 else if (persistentStorageFunction == PersistentStorageFunction.Update)
  816:                 {
  817:                     if (StaffIsSuperUser(staffContact.StaffIdentityUser)) isAllowed = true;
  818:                     else isAllowed = false;
  819:                 }
  820:                 else
  821:                 {
  822:                     isAllowed = false;
  823:                 }
  824:             }
  825:             else isAllowed = false;
  826:  
  827:             return isAllowed;
  828:         }
  829:  
  830:         ////////////////////////////////////////////////////////////////////////////
  831:         ////////////////////////////////////////////////////////////////////////////
  832:  
  833:         /// <summary>
  834:         ///
  835:         /// </summary>
  836:         public static bool StaffUserNameCanLogFromAnyPcIp(string userName)
  837:         {
  838:             bool isAllowed;
  839:  
  840:             if (!string.IsNullOrEmpty(userName))
  841:             {
  842:                 if (userName == "jasem") isAllowed = true;
  843:                 else isAllowed = false;
  844:             }
  845:             else isAllowed = false;
  846:  
  847:             return isAllowed;
  848:         }
  849:  
  850:         ////////////////////////////////////////////////////////////////////////////
  851:         ////////////////////////////////////////////////////////////////////////////
  852:  
  853:         /// <summary>
  854:         ///
  855:         /// </summary>
  856:         public static Ia.Ftn.Cl.Models.Business.Administration.Framework FrameworkParentOfAllReportsThatWillBeHandledInReportSection
  857:         {
  858:             get
  859:             {
  860:                 Ia.Ftn.Cl.Models.Business.Administration.Framework framework;
  861:  
  862:                 framework = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList where f.ArabicName == "وزارة المواصلات" select f).FirstOrDefault(); //.SingleOrDefault();
  863:  
  864:                 return framework;
  865:             }
  866:         }
  867:  
  868:         ////////////////////////////////////////////////////////////////////////////
  869:  
  870:         /// <summary>
  871:         ///
  872:         /// </summary>
  873:         public static bool FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  874:         {
  875:             bool isResponsible;
  876:  
  877:             if (framework != null)
  878:             {
  879:                 if (framework.ArabicName == "قسم الدعم الفني للشبكة") isResponsible = true;
  880:                 else if (framework.ArabicName == "قسم تشغيل الخدمات") isResponsible = true;
  881:                 else if (framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isResponsible = true;
  882:                 else if (framework.ArabicName == "مراقبة تشغيل الشبكة") isResponsible = true;
  883:                 //else if (framework.ArabicName == "مراقبة تقنية المعلومات") isResponsible = true;
  884:                 else if (framework.ArabicName == "مراقبة خدمات الشبكة") isResponsible = true;
  885:                 else if (framework.ArabicName == "إدارة شبكة الألياف الضوئية") isResponsible = true;
  886:                 else isResponsible = false;
  887:             }
  888:             else isResponsible = false;
  889:  
  890:             return isResponsible;
  891:         }
  892:  
  893:         ////////////////////////////////////////////////////////////////////////////
  894:  
  895:         /// <summary>
  896:         ///
  897:         /// </summary>
  898:         public static bool FrameworkIsResponsibleForMissingLic(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  899:         {
  900:             bool isResponsible;
  901:  
  902:             if (framework.ArabicName == "قسم تشغيل الخدمات") isResponsible = true;
  903:             else if (framework.ArabicName == "قسم خدمات الشبكة") isResponsible = true;
  904:             else if (framework.ArabicName == "مراقبة خدمات الشبكة") isResponsible = true;
  905:             else if (framework.ArabicName == "إدارة شبكة الألياف الضوئية") isResponsible = true;
  906:             else isResponsible = false;
  907:  
  908:             return isResponsible;
  909:         }
  910:  
  911:         ////////////////////////////////////////////////////////////////////////////
  912:  
  913:         /// <summary>
  914:         ///
  915:         /// </summary>
  916:         public static bool FrameworkCanCloseReport(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  917:         {
  918:             bool canClose;
  919:  
  920:             canClose = framework.ArabicName == "قسم الدعم الفني للشبكة";
  921:  
  922:             return canClose;
  923:         }
  924:  
  925:         ////////////////////////////////////////////////////////////////////////////
  926:  
  927:         /// <summary>
  928:         ///
  929:         /// </summary>
  930:         public static bool StaffIsResponsibleForAllOpenReportWithNoReportHistory(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  931:         {
  932:             bool isResponsible;
  933:  
  934:             isResponsible = FrameworkIsResponsibleForAllOpenReportWithNoReportHistory(staff.Framework);
  935:  
  936:             return isResponsible;
  937:         }
  938:  
  939:         ////////////////////////////////////////////////////////////////////////////
  940:         ////////////////////////////////////////////////////////////////////////////
  941:  
  942:         /// <summary>
  943:         ///
  944:         /// </summary>
  945:         public static bool StaffIsSuperUser(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  946:         {
  947:             bool isSuperUser;
  948:  
  949:             if (staff != null)
  950:             {
  951:                 isSuperUser = (SuperStaff() != null && SuperStaff().Id == staff.Id || ApplicationStaff() != null && ApplicationStaff().Id == staff.Id);
  952:             }
  953:             else isSuperUser = false;
  954:  
  955:             return isSuperUser;
  956:         }
  957:  
  958:         ////////////////////////////////////////////////////////////////////////////
  959:  
  960:         /// <summary>
  961:         ///
  962:         /// </summary>
  963:         public static bool StaffIsSuperOrDeputyUser(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
  964:         {
  965:             bool isSuperOrDeputyUser;
  966:  
  967:             if (staff != null)
  968:             {
  969:                 isSuperOrDeputyUser = (SuperStaff() != null && SuperStaff().Id == staff.Id || DeputyStaff() != null && DeputyStaff().Id == staff.Id);
  970:             }
  971:             else isSuperOrDeputyUser = false;
  972:  
  973:             return isSuperOrDeputyUser;
  974:         }
  975:  
  976:         ////////////////////////////////////////////////////////////////////////////
  977:  
  978:         /// <summary>
  979:         ///
  980:         /// </summary>
  981:         public static bool FrameworkIsSuperFramework(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
  982:         {
  983:             bool isSuperFramework;
  984:  
  985:             if (framework != null)
  986:             {
  987:                 if (framework.ArabicName == "قسم دعم تشغيل الشبكة") isSuperFramework = true;
  988:                 else if (framework.ArabicName == "التطبيقات المتكاملة") isSuperFramework = true;
  989:                 else isSuperFramework = false;
  990:             }
  991:             else isSuperFramework = false;
  992:  
  993:             return isSuperFramework;
  994:         }
  995:  
  996:         ////////////////////////////////////////////////////////////////////////////
  997:  
  998:         /// <summary>
  999:         ///
 1000:         /// </summary>
 1001:         public static bool FrameworkIsApplication(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
 1002:         {
 1003:             bool isSuperFramework;
 1004:  
 1005:             if (framework != null)
 1006:             {
 1007:                 if (framework.ArabicName == "التطبيقات المتكاملة") isSuperFramework = true;
 1008:                 else isSuperFramework = false;
 1009:             }
 1010:             else isSuperFramework = false;
 1011:  
 1012:             return isSuperFramework;
 1013:         }
 1014:  
 1015:         ////////////////////////////////////////////////////////////////////////////
 1016:  
 1017:         /// <summary>
 1018:         ///
 1019:         /// </summary>
 1020:         public static string FrameworkApplicationId()
 1021:         {
 1022:             var id = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
 1023:                       where f.ArabicName == "التطبيقات المتكاملة"
 1024:                       select f.Id).Single();
 1025:  
 1026:             return id;
 1027:         }
 1028:  
 1029:         ////////////////////////////////////////////////////////////////////////////
 1030:  
 1031:         /// <summary>
 1032:         ///
 1033:         /// </summary>
 1034:         public static Ia.Ftn.Cl.Models.StaffIdentityUser SuperStaff()
 1035:         {
 1036:             var staff = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
 1037:                          where s.Framework != null && s.Framework.ArabicName == "قسم دعم تشغيل الشبكة" && s.IsHead
 1038:                          select s).SingleOrDefault();
 1039:  
 1040:             return staff;
 1041:         }
 1042:  
 1043:         ////////////////////////////////////////////////////////////////////////////
 1044:  
 1045:         /// <summary>
 1046:         ///
 1047:         /// </summary>
 1048:         public static Ia.Ftn.Cl.Models.StaffIdentityUser ApplicationStaff()
 1049:         {
 1050:             var staff = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
 1051:                          where s.Framework != null && s.Framework.ArabicName == "التطبيقات المتكاملة" && s.IsHead
 1052:                          select s).SingleOrDefault();  // me!
 1053:  
 1054:             return staff;
 1055:         }
 1056:  
 1057:         ////////////////////////////////////////////////////////////////////////////
 1058:  
 1059:         /// <summary>
 1060:         ///
 1061:         /// </summary>
 1062:         public static Ia.Ftn.Cl.Models.StaffIdentityUser DeputyStaff()
 1063:         {
 1064:             var staff = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
 1065:                          where s.Framework != null && s.Framework.ArabicName == "قسم تقنية المعلومات" && s.IsHead
 1066:                          select s).SingleOrDefault();
 1067:  
 1068:             return staff;
 1069:         }
 1070:  
 1071:         ////////////////////////////////////////////////////////////////////////////
 1072:  
 1073:         /// <summary>
 1074:         ///
 1075:         /// </summary>
 1076:         public static Ia.Ftn.Cl.Models.Business.Administration.Framework SuperFramework
 1077:         {
 1078:             get
 1079:             {
 1080:                 Ia.Ftn.Cl.Models.Business.Administration.Framework framework;
 1081:  
 1082:                 framework = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
 1083:                              where f.ArabicName == "قسم دعم تشغيل الشبكة" || f.ArabicName == "التطبيقات المتكاملة"
 1084:                              select f).Single();
 1085:  
 1086:                 return framework;
 1087:             }
 1088:         }
 1089:  
 1090:         ////////////////////////////////////////////////////////////////////////////
 1091:         ////////////////////////////////////////////////////////////////////////////
 1092:  
 1093:         /// <summary>
 1094:         ///
 1095:         /// </summary>
 1096:         public static bool StaffCanInsertUpdateDeleteServiceExemption(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1097:         {
 1098:             bool isAllowed;
 1099:  
 1100:             if (staff != null)
 1101:             {
 1102:                 if (function == PersistentStorageFunction.Read)
 1103:                 {
 1104:                     isAllowed = true;
 1105:                 }
 1106:                 else if (function == PersistentStorageFunction.Create)
 1107:                 {
 1108:                     if (StaffIsSuperUser(staff)) isAllowed = true;
 1109:                     else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
 1110:                     else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 1111:                     else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 1112:                     else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
 1113:                     else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1114:                     else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1115:                     else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1116:                     else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1117:                     else isAllowed = false;
 1118:                 }
 1119:                 else if (function == PersistentStorageFunction.Update)
 1120:                 {
 1121:                     if (StaffIsSuperUser(staff)) isAllowed = true;
 1122:                     else isAllowed = false;
 1123:                 }
 1124:                 else if (function == PersistentStorageFunction.Delete)
 1125:                 {
 1126:                     if (StaffIsSuperUser(staff)) isAllowed = true;
 1127:                     else isAllowed = false;
 1128:                 }
 1129:                 else
 1130:                 {
 1131:                     isAllowed = false;
 1132:                 }
 1133:             }
 1134:             else isAllowed = false;
 1135:  
 1136:             return isAllowed;
 1137:         }
 1138:  
 1139:         ////////////////////////////////////////////////////////////////////////////
 1140:  
 1141:         /// <summary>
 1142:         ///
 1143:         /// </summary>
 1144:         public static bool StaffCanCreateReadUpdateAccessMail(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1145:         {
 1146:             bool isAllowed;
 1147:  
 1148:             if (staff != null)
 1149:             {
 1150:                 if (function == PersistentStorageFunction.Read)
 1151:                 {
 1152:                     isAllowed = true;
 1153:                 }
 1154:                 else if (function == PersistentStorageFunction.Update)
 1155:                 {
 1156:                     if (StaffIsSuperUser(staff)) isAllowed = true;
 1157:                     else if (staff.IsHead && staff.Framework.ArabicName == "قسم الخطوط الطرفية") isAllowed = true;
 1158:                     else isAllowed = false;
 1159:                 }
 1160:                 else
 1161:                 {
 1162:                     isAllowed = false;
 1163:                 }
 1164:             }
 1165:             else isAllowed = false;
 1166:  
 1167:             return isAllowed;
 1168:         }
 1169:  
 1170:         ////////////////////////////////////////////////////////////////////////////
 1171:  
 1172:         /// <summary>
 1173:         ///
 1174:         /// </summary>
 1175:         public static bool StaffCanUploadAmsTransactionCsvFile(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1176:         {
 1177:             bool isAllowed;
 1178:  
 1179:             if (staff != null)
 1180:             {
 1181:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1182:                 else isAllowed = false;
 1183:             }
 1184:             else isAllowed = false;
 1185:  
 1186:             return isAllowed;
 1187:         }
 1188:  
 1189:         ////////////////////////////////////////////////////////////////////////////
 1190:  
 1191:         /// <summary>
 1192:         ///
 1193:         /// </summary>
 1194:         public static bool FrameworkCanReadStatistics(Ia.Ftn.Cl.Models.Business.Administration.Framework framework)
 1195:         {
 1196:             bool isAllowed;
 1197:  
 1198:             if (framework != null)
 1199:             {
 1200:                 if (FrameworkIsSuperFramework(framework)) isAllowed = true;
 1201:                 else isAllowed = false;
 1202:             }
 1203:             else isAllowed = true; // for now I will allow users with framework = null coming form telegram
 1204:  
 1205:             return isAllowed;
 1206:         }
 1207:  
 1208:         ////////////////////////////////////////////////////////////////////////////
 1209:  
 1210:         /// <summary>
 1211:         ///
 1212:         /// </summary>
 1213:         public static bool StaffContactCanInsertAmsTransactionCsvFile(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction function, Ia.Ftn.Cl.Models.Business.Administration.StaffContact staffContact)
 1214:         {
 1215:             bool isAllowed;
 1216:  
 1217:             if (staffContact != null)
 1218:             {
 1219:                 if (function == PersistentStorageFunction.Create) isAllowed = true;
 1220:                 else if (function == PersistentStorageFunction.Read) isAllowed = true;
 1221:                 else if (function == PersistentStorageFunction.Update) isAllowed = false;
 1222:                 else if (function == PersistentStorageFunction.Delete) isAllowed = false;
 1223:                 else isAllowed = false;
 1224:             }
 1225:             else isAllowed = false;
 1226:  
 1227:             return isAllowed;
 1228:         }
 1229:  
 1230:         ////////////////////////////////////////////////////////////////////////////
 1231:         ////////////////////////////////////////////////////////////////////////////
 1232:  
 1233:         /// <summary>
 1234:         ///
 1235:         /// </summary>
 1236:         public static bool StaffCanReadUpdateServiceRequestServiceAccess(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1237:         {
 1238:             bool isAllowed;
 1239:  
 1240:             if (staff != null)
 1241:             {
 1242:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1243:                 else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
 1244:                 else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 1245:                 else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 1246:                 else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
 1247:                 else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1248:                 else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1249:                 else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1250:                 else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1251:                 else isAllowed = false;
 1252:             }
 1253:             else isAllowed = false;
 1254:  
 1255:             return isAllowed;
 1256:         }
 1257:  
 1258:         ////////////////////////////////////////////////////////////////////////////
 1259:  
 1260:         /// <summary>
 1261:         ///
 1262:         /// </summary>
 1263:         public static bool StaffCanOverrideRouterDomainRestrictionInCreatingService(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1264:         {
 1265:             bool isAllowed;
 1266:  
 1267:             if (staff != null)
 1268:             {
 1269:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1270:                 else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
 1271:                 else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1272:                 else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1273:                 else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1274:                 else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1275:                 else isAllowed = false;
 1276:             }
 1277:             else isAllowed = false;
 1278:  
 1279:             return isAllowed;
 1280:         }
 1281:  
 1282:         ////////////////////////////////////////////////////////////////////////////
 1283:  
 1284:         /// <summary>
 1285:         ///
 1286:         /// </summary>
 1287:         public static bool StaffCanReadUpdateService2Access(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1288:         {
 1289:             bool isAllowed;
 1290:  
 1291:             if (staff != null)
 1292:             {
 1293:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1294:                 else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات" && staff.IsHead) isAllowed = true;
 1295:                 //else if (staff.Framework.ArabicName == "هواوي" && staff.IsHead) isAllowed = true;
 1296:                 else isAllowed = false;
 1297:             }
 1298:             else isAllowed = false;
 1299:  
 1300:             return isAllowed;
 1301:         }
 1302:  
 1303:         ////////////////////////////////////////////////////////////////////////////
 1304:  
 1305:         /// <summary>
 1306:         ///
 1307:         /// </summary>
 1308:         public static bool StaffCanMigratePremisesFromPstnToFiber(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1309:         {
 1310:             // see related sister function StaffCanMigratePremisesFromPstnToFiberForNddOnt()
 1311:             bool isAllowed;
 1312:  
 1313:             if (staff != null)
 1314:             {
 1315:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1316:                 else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 1317:                 else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1318:                 else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 1319:                 else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1320:                 else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1321:                 else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
 1322:                 else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1323:                 else
 1324:                 {
 1325:                     if (staff.Framework != null && staff.Framework.Sites.Count > 0)
 1326:                     {
 1327:                         var list = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
 1328:  
 1329:                         isAllowed = staff.Framework.Sites.Any(u => u.Routers.Any(v => v.Odfs.Any(w => w.Olts.Any(x => list.Contains(x.Id)))));
 1330:                     }
 1331:                     else isAllowed = false;
 1332:                 }
 1333:             }
 1334:             else isAllowed = false;
 1335:  
 1336:             return isAllowed;
 1337:         }
 1338:  
 1339:         ////////////////////////////////////////////////////////////////////////////
 1340:  
 1341:         /// <summary>
 1342:         ///
 1343:         /// </summary>
 1344:         public static bool StaffCanMigratePremisesFromPstnToFiberForNddOnt(Ia.Ftn.Cl.Models.StaffIdentityUser staff, Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Ont nddOnt)
 1345:         {
 1346:             // see related sister function StaffCanMigratePremisesFromPstnToFiber()
 1347:             bool isAllowed;
 1348:  
 1349:             if (staff != null)
 1350:             {
 1351:                 if (nddOnt != null)
 1352:                 {
 1353:                     var list = Ia.Ftn.Cl.Models.Data.Service.AllowedToBeMigratedOltIdList;
 1354:  
 1355:                     if (list.Contains(nddOnt.Pon.PonGroup.Olt.Id))
 1356:                     {
 1357:                         if (StaffIsSuperUser(staff)) isAllowed = true;
 1358:                         else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") 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.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1363:                         else if (staff.Framework.Ancestors.Any(u => u.ArabicName == "مراقبة تقنية المعلومات")) isAllowed = true;
 1364:                         else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1365:                         else
 1366:                         {
 1367:                             if (staff.Framework != null && staff.Framework.Sites.Count > 0)
 1368:                             {
 1369:                                 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))));
 1370:                             }
 1371:                             else isAllowed = false;
 1372:                         }
 1373:                     }
 1374:                     else isAllowed = false;
 1375:                 }
 1376:                 else isAllowed = false;
 1377:             }
 1378:             else isAllowed = false;
 1379:  
 1380:             return isAllowed;
 1381:         }
 1382:  
 1383:         ////////////////////////////////////////////////////////////////////////////
 1384:  
 1385:         /// <summary>
 1386:         ///
 1387:         /// </summary>
 1388:         public static bool StaffCanAccessAdministationFolder(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1389:         {
 1390:             bool isAllowed;
 1391:  
 1392:             /*
 1393:              * <allow roles="التطبيقات المتكاملة,إدارة شبكة الألياف الضوئية,مراقبة خدمات الشبكة,مراقبة الدعم الفنى للشبكة,مراقبة تقنية المعلومات,مراقبة تشغيل الشبكة,قسم دعم تشغيل الشبكة,إدارة مشاريع الشبكة الهاتفية"/>
 1394:              * <allow roles="نوكيا,هواوي,وزارة المواصلات" />
 1395:              * <deny users="*"/>
 1396:              * <allow users="mohammad"/>
 1397:              */
 1398:  
 1399:             if (staff != null)
 1400:             {
 1401:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1402:                 else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "وزارة المواصلات")) isAllowed = true;
 1403:                 else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "هواوي")) isAllowed = true;
 1404:                 else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "نوكيا")) isAllowed = true;
 1405:                 else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "التطبيقات المتكاملة")) isAllowed = true;
 1406:                 else isAllowed = false;
 1407:             }
 1408:             else isAllowed = false;
 1409:  
 1410:             return isAllowed;
 1411:         }
 1412:  
 1413:         ////////////////////////////////////////////////////////////////////////////
 1414:  
 1415:         /// <summary>
 1416:         ///
 1417:         /// </summary>
 1418:         public static bool StaffCanExecuteTasks(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1419:         {
 1420:             return StaffCanExecuteTasks(staff, false);
 1421:         }
 1422:  
 1423:         ////////////////////////////////////////////////////////////////////////////
 1424:  
 1425:         /// <summary>
 1426:         ///
 1427:         /// </summary>
 1428:         public static bool StaffCanExecuteTasks(Ia.Ftn.Cl.Models.StaffIdentityUser staff, bool overrideCondition)
 1429:         {
 1430:             bool isAllowed;
 1431:  
 1432:             if (staff != null)
 1433:             {
 1434:                 if (StaffIsSuperUser(staff)) isAllowed = true;
 1435:                 else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
 1436:                 else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 1437:                 else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 1438:                 else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
 1439:                 else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1440:                 else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1441:                 else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1442:                 else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1443:                 else if (overrideCondition) isAllowed = true;
 1444:                 else isAllowed = false;
 1445:             }
 1446:             else isAllowed = false;
 1447:  
 1448:             return isAllowed;
 1449:         }
 1450:  
 1451:         ////////////////////////////////////////////////////////////////////////////
 1452:  
 1453:         /// <summary>
 1454:         ///
 1455:         /// </summary>
 1456:         public static bool StaffCanExecuteAccessTasks(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1457:         {
 1458:             bool isAllowed;
 1459:  
 1460:             if (staff != null)
 1461:             {
 1462:                 if (staff.Framework != null)
 1463:                 {
 1464:                     if (StaffIsSuperUser(staff)) isAllowed = true;
 1465:                     else if (staff.Framework.ArabicName == "قسم تقنية المعلومات") isAllowed = true;
 1466:                     else if (staff.Framework.ArabicName == "قسم الدعم الفني للشبكة") isAllowed = true;
 1467:                     else if (staff.Framework.ArabicName == "قسم تشغيل الخدمات") isAllowed = true;
 1468:                     else if (staff.Framework.ArabicName == "مراقبة تقنية المعلومات") isAllowed = true;
 1469:                     else if (staff.Framework.ArabicName == "مراقبة الدعم الفنى للشبكة") isAllowed = true;
 1470:                     else if (staff.Framework.ArabicName == "مراقبة تشغيل الشبكة") isAllowed = true;
 1471:                     else if (staff.Framework.ArabicName == "مراقبة خدمات الشبكة") isAllowed = true;
 1472:                     else if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1473:                     else if (Ia.Ftn.Cl.Models.Business.Authority.StaffIsInCustomerServiceSector(staff)) isAllowed = true;
 1474:                     else isAllowed = false;
 1475:                 }
 1476:                 else isAllowed = false;
 1477:             }
 1478:             else isAllowed = false;
 1479:  
 1480:             return isAllowed;
 1481:         }
 1482:  
 1483:         ////////////////////////////////////////////////////////////////////////////
 1484:  
 1485:         /// <summary>
 1486:         ///
 1487:         /// </summary>
 1488:         public static bool StaffIsApplication(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1489:         {
 1490:             bool isAllowed;
 1491:  
 1492:             if (staff != null && staff.Framework != null)
 1493:             {
 1494:                 if (staff.Framework.ArabicName == "التطبيقات المتكاملة") isAllowed = true;
 1495:                 else isAllowed = false;
 1496:             }
 1497:             else isAllowed = false;
 1498:  
 1499:             return isAllowed;
 1500:         }
 1501:  
 1502:         ////////////////////////////////////////////////////////////////////////////
 1503:  
 1504:         /// <summary>
 1505:         ///
 1506:         /// </summary>
 1507:         public static bool StaffIsInCustomerServiceSector(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1508:         {
 1509:             bool isAllowed;
 1510:  
 1511:             if (staff != null)
 1512:             {
 1513:                 if (staff.Framework.Ancestors.Any(u => u.ArabicName == "قطاع خدمات المشتركين")) isAllowed = true;
 1514:                 else isAllowed = false;
 1515:             }
 1516:             else isAllowed = false;
 1517:  
 1518:             return isAllowed;
 1519:         }
 1520:  
 1521:         ////////////////////////////////////////////////////////////////////////////
 1522:  
 1523:         /// <summary>
 1524:         ///
 1525:         /// </summary>
 1526:         public static bool StaffIsInOpticalFiberNetworkDepartment(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1527:         {
 1528:             bool isAllowed;
 1529:  
 1530:             if (staff != null)
 1531:             {
 1532:                 if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "إدارة شبكة الألياف الضوئية")) isAllowed = true;
 1533:                 //else if (staff.Framework.AncestorsOrSelf.Any(u => u.ArabicName == "إدارة مشاريع الشبكة الهاتفية")) isAllowed = true;
 1534:                 else isAllowed = false;
 1535:             }
 1536:             else isAllowed = false;
 1537:  
 1538:             return isAllowed;
 1539:         }
 1540:  
 1541:         ////////////////////////////////////////////////////////////////////////////
 1542:  
 1543:         /// <summary>
 1544:         ///
 1545:         /// </summary>
 1546:         public static bool StaffIsSupplier(Ia.Ftn.Cl.Models.StaffIdentityUser staff)
 1547:         {
 1548:             bool isAllowed;
 1549:  
 1550:             if (staff != null)
 1551:             {
 1552:                 if (staff.Framework.ArabicName == "نوكيا" || staff.Framework.ArabicName == "هواوي") isAllowed = true;
 1553:                 else isAllowed = false;
 1554:             }
 1555:             else isAllowed = false;
 1556:  
 1557:             return isAllowed;
 1558:         }
 1559:  
 1560:         ////////////////////////////////////////////////////////////////////////////
 1561:  
 1562:         /// <summary>
 1563:         ///
 1564:         /// </summary>
 1565:         public static bool StaffIsInRole(Ia.Ftn.Cl.Models.StaffIdentityUser staff, string role)
 1566:         {
 1567:             bool isAllowed;
 1568:  
 1569:             if (staff != null)
 1570:             {
 1571:                 if (staff.Framework.Ancestors.Any(u => u.ArabicName == role)) isAllowed = true;
 1572:                 else isAllowed = false;
 1573:             }
 1574:             else isAllowed = false;
 1575:  
 1576:             return isAllowed;
 1577:         }
 1578:  
 1579:         ////////////////////////////////////////////////////////////////////////////
 1580:         ////////////////////////////////////////////////////////////////////////////
 1581:  
 1582:         /// <summary>
 1583:         ///
 1584:         /// </summary>
 1585:         public static List<Tuple<string, string>> EmailRecipientTupleList(Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction schedularFunction)
 1586:         {
 1587:             List<Tuple<string, string>> recipientTupleList;
 1588:  
 1589:             recipientTupleList = new List<Tuple<string, string>>();
 1590:  
 1591:             switch (schedularFunction)
 1592:             {
 1593:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslyPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1594:                     {
 1595:                         //recipientTupleList.Add(new Tuple<string, string>("E. Shatti", "emad@moc.gov.kw"));
 1596:                         //recipientTupleList.Add(new Tuple<string, string>("M. Qattan", "qattan04@hotmail.com"));
 1597:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1598:  
 1599:                         break;
 1600:                     }
 1601:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslyQrnPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1602:                     {
 1603:                         //recipientTupleList.Add(new Tuple<string, string>("QRN Exchange", "qrnexchange@gmail.com"));
 1604:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1605:  
 1606:                         break;
 1607:                     }
 1608:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslyJblPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1609:                     {
 1610:                         //recipientTupleList.Add(new Tuple<string, string>("JBL Exchange", "jbl.exch@gmail.com"));
 1611:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1612:  
 1613:                         break;
 1614:                     }
 1615:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslySsbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1616:                     {
 1617:                         //recipientTupleList.Add(new Tuple<string, string>("SSB Exchange", "ssb.exch@gmail.com"));
 1618:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1619:  
 1620:                         break;
 1621:                     }
 1622:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslySlmaPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1623:                     {
 1624:                         //recipientTupleList.Add(new Tuple<string, string>("SLMA Exchange", "slmakw158@gmail.com"));
 1625:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1626:  
 1627:                         break;
 1628:                     }
 1629:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslySlmbPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1630:                     {
 1631:                         //recipientTupleList.Add(new Tuple<string, string>("SLMB Exchange", "msfkw158@gmail.com"));
 1632:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1633:  
 1634:                         break;
 1635:                     }
 1636:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslyMsfPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1637:                     {
 1638:                         //recipientTupleList.Add(new Tuple<string, string>("MSF Exchange", "msfkw158@gmail.com"));
 1639:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1640:  
 1641:                         break;
 1642:                     }
 1643:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.ListOfPreviouslyFhhPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport:
 1644:                     {
 1645:                         //recipientTupleList.Add(new Tuple<string, string>("FHH Exchange", "fahaheel.2021@gmail.com"));
 1646:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1647:  
 1648:                         break;
 1649:                     }
 1650:  
 1651:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.StatusReport:
 1652:                     {
 1653:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1654:  
 1655:                         break;
 1656:                     }
 1657:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.StatisticsReport:
 1658:                     {
 1659:                         //recipientTupleList.Add(new Tuple<string, string>("Traffic", "traffic_section@yahoo.com"));
 1660:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1661:  
 1662:                         break;
 1663:                     }
 1664:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.NokiaReport:
 1665:                     {
 1666:                         //recipientTupleList.Add(new Tuple<string, string>("R. Vizcara", "rumello.vizcara@nokia.com"));
 1667:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1668:  
 1669:                         break;
 1670:                     }
 1671:                 case Ia.Ftn.Cl.Models.Business.Authority.SchedularFunction.HuaweiReport:
 1672:                     {
 1673:                         recipientTupleList.Add(new Tuple<string, string>("Info", "info@kftnc.com"));
 1674:  
 1675:                         break;
 1676:                     }
 1677:                 default: break;
 1678:             }
 1679:  
 1680:             return recipientTupleList;
 1681:         }
 1682:  
 1683:         ////////////////////////////////////////////////////////////////////////////
 1684:         ////////////////////////////////////////////////////////////////////////////
 1685:  
 1686:         /// <summary>
 1687:         ///
 1688:         /// </summary>
 1689:         public static bool ServiceRequestIsAllowedProcessing(Ia.Ftn.Cl.Models.ServiceRequest serviceRequest)
 1690:         {
 1691:             // below: this skips processing some service requests due to misc problems
 1692:             bool processingIsAllowed;
 1693:  
 1694:             // see ServiceRequestIdIsAllowedForProcessing in service-request.cs
 1695:  
 1696:             if (serviceRequest.Id == 1719402 || serviceRequest.Id == 1875029) processingIsAllowed = false;
 1697:             // 1719402    25232104    1    تم التنفيذ    2014-10-28 11:07    خط هاتف    هاتف    17    الادارة العامة للجمارك    جهات حكومية
 1698:             // 1875029    25232104    1    تعذر التنفيذ    2016-02-24 00:00    رفع خط    هاتف    17    الادارة العامة للجمارك    جهات حكومية
 1699:             else if (serviceRequest.Id == 1639637) processingIsAllowed = false;
 1700:             // 1639637    25430454    3    تم التنفيذ    2014-03-05 09:04    خط هاتف    هاتف    1619586    بدر ناصر غانم الارملي
 1701:             // above: wrong service record with serial 3, but later records reduce to 2
 1702:             else if (serviceRequest.Id == 361494) processingIsAllowed = false;
 1703:             // 361494    25518807    0    تم التنفيذ    2006-07-26 11:58    إيقاف كاشف    هاتف
 1704:             // above: causes call waiting to stop in the group service
 1705:             else processingIsAllowed = true;
 1706:  
 1707:             return processingIsAllowed;
 1708:         }
 1709:  
 1710:         ////////////////////////////////////////////////////////////////////////////
 1711:  
 1712:         /// <summary>
 1713:         ///
 1714:         /// </summary>
 1715:         public static bool ServiceRequestHistoryIsAllowedProcessing(Ia.Ftn.Cl.Models.ServiceRequestHistory serviceRequestHistory)
 1716:         {
 1717:             // below: this skips processing some service requests due to misc problems
 1718:             bool processingIsAllowed;
 1719:  
 1720:             if (serviceRequestHistory.Id == "25429778:1:965:0:66:2005-11-27") processingIsAllowed = false;
 1721:             // prevent the removal of service group
 1722:             else if (serviceRequestHistory.Id == "23900287:1:965:1:14:2005-07-06" || serviceRequestHistory.Id == "23900287:1:965:1:66:2008-12-25") processingIsAllowed = false;
 1723:             /*
 1724:             23900287    1    يعمل    2005-07-06        2005-07-06    كاشف رقم    هاتف    2019-03-29 22:01    2019-03-29 22:01
 1725:             23900287    1    يعمل    2005-07-06        2008-12-25    إيقاف كاشف    هاتف    2019-03-29 22:01    2019-03-29 22:01
 1726:             */
 1727:             else if (serviceRequestHistory.Id == "25518807:1:965:0:66:2002-10-27" || serviceRequestHistory.Id == "25518807:1:965:0:66:2006-07-26") processingIsAllowed = false;
 1728:             /*
 1729:             25518807:1:965:0:66:2002-10-27    25518807    0    7001    1986-05-29 00:00:00.000    1753-01-01 00:00:00.000    2002-10-27 00:00:00.000    66    3    2019-04-10 23:07:01.897    2019-04-10 23:07:01.897    NULL
 1730:             25518807:1:965:0:66:2006-07-26    25518807    0    7001    1986-05-29 00:00:00.000    1753-01-01 00:00:00.000    2006-07-26 00:00:00.000    66    3    2019-04-10 23:07:01.897    2019-04-10 23:07:01.897    NULL             
 1731:             */
 1732:             else if (serviceRequestHistory.Id == "25519290:1:965:1:66:2002-10-28") processingIsAllowed = false;
 1733:             /*
 1734:             25519290    1    يعمل    1998-03-28        2002-10-28    إيقاف كاشف    هاتف    2019-04-10 23:48    2019-04-10 23:48
 1735:             25519290:1:965:1:66:2002-10-28    25519290    1    7001    1998-03-28 00:00:00.000    1753-01-01 00:00:00.000    2002-10-28 00:00:00.000    66    3    2019-04-10 23:48:15.117    2019-04-10 23:48:15.117    NULL
 1736:             */
 1737:             else processingIsAllowed = true;
 1738:  
 1739:             return processingIsAllowed;
 1740:         }
 1741:  
 1742:         ////////////////////////////////////////////////////////////////////////////
 1743:  
 1744:         /// <summary>
 1745:         ///
 1746:         /// </summary>
 1747:         public static bool ServiceProcessingIsAllowed(string service)
 1748:         {
 1749:             // below: this skips processing some services due to misc problems
 1750:             bool processingIsAllowed;
 1751:  
 1752:             if (!string.IsNullOrEmpty(service))
 1753:             {
 1754:                 if (Ia.Ftn.Cl.Models.Data.ServiceExemption.ServiceList().Contains(service)) processingIsAllowed = false;
 1755:                 else processingIsAllowed = true;
 1756:             }
 1757:             else processingIsAllowed = true;
 1758:  
 1759:             return processingIsAllowed;
 1760:         }
 1761:  
 1762:         ////////////////////////////////////////////////////////////////////////////
 1763:         ////////////////////////////////////////////////////////////////////////////
 1764:  
 1765:         /// <summary>
 1766:         ///
 1767:         /// </summary>
 1768:         public static bool TelegramUserCanReadFind(string chatId, int userId)
 1769:         {
 1770:             bool isAllowed;
 1771:  
 1772:             if (userId != 0)
 1773:             {
 1774:                 isAllowed = true;
 1775:             }
 1776:             else isAllowed = false;
 1777:  
 1778:             return isAllowed;
 1779:         }
 1780:  
 1781:         ////////////////////////////////////////////////////////////////////////////    
 1782:  
 1783:         /// <summary>
 1784:         ///
 1785:         /// </summary>
 1786:         public static bool NumberIsWithinFrameworkSiteDomainList(Ia.Ftn.Cl.Models.Business.Administration.Framework framework, string service)
 1787:         {
 1788:             bool isWithin;
 1789:  
 1790:             if (framework != null)
 1791:             {
 1792:                 if (framework.Sites.Count > 0)
 1793:                 {
 1794:                     if (framework.Sites.Any(w => w.DomainList.Any(u => service.StartsWith(u.ToString())))) isWithin = true;
 1795:                     else isWithin = true; // false; temp
 1796:                 }
 1797:                 else isWithin = true; // will allow number for framework.Site == null
 1798:             }
 1799:             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.
 1800:  
 1801:             return isWithin;
 1802:         }
 1803:  
 1804:         ////////////////////////////////////////////////////////////////////////////    
 1805:  
 1806:         /// <summary>
 1807:         ///
 1808:         /// </summary>
 1809:         public static bool AccessNameIsWithinFrameworkSiteAreaSymbolList(Ia.Ftn.Cl.Models.Business.Administration.Framework framework, string accessName)
 1810:         {
 1811:             bool isWithin;
 1812:  
 1813:             if (framework != null)
 1814:             {
 1815:                 if (framework.Sites.Count > 0)
 1816:                 {
 1817:                     if (framework.Sites.Any(u => u.AreaSymbolList.Any(v => accessName.StartsWith(v.ToString())))) isWithin = true;
 1818:                     else isWithin = true; // false; temp
 1819:                 }
 1820:                 else isWithin = true; // will allow number for framework.Site == null
 1821:             }
 1822:             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.
 1823:  
 1824:             return isWithin;
 1825:         }
 1826:  
 1827:         ////////////////////////////////////////////////////////////////////////////    
 1828:  
 1829:         /// <summary>
 1830:         ///
 1831:         /// </summary>
 1832:         public static void UpdateFrameworkRolesOfStaffIdentityUser(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, RoleManager<IdentityRole> roleManager, Ia.Ftn.Cl.Models.StaffIdentityUser staffIdentityUser)
 1833:         {
 1834:             string userName;
 1835:  
 1836:             if (staffIdentityUser != null)
 1837:             {
 1838:                 userName = staffIdentityUser.UserName;
 1839:  
 1840:                 // add user to IsHead role if he is head, and remove him otherwise
 1841:                 if (staffIdentityUser.IsHead)
 1842:                 {
 1843:                     if (!Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, "IsHead")) Ia.Ftn.Cl.Models.Identity.AddUserToRole(userManager, userName, "IsHead");
 1844:                 }
 1845:                 else
 1846:                 {
 1847:                     if (Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, "IsHead")) Ia.Ftn.Cl.Models.Identity.RemoveUserFromRole(userManager, roleManager, userName, "IsHead");
 1848:                 }
 1849:  
 1850:                 if (staffIdentityUser.Framework != null)
 1851:                 {
 1852:                     // add user to its direct role
 1853:                     if (!Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, staffIdentityUser.Framework.FullyQualifiedArabicName)) Ia.Ftn.Cl.Models.Identity.AddUserToRole(userManager, userName, staffIdentityUser.Framework.FullyQualifiedArabicName);
 1854:  
 1855:                     // add user to its decendants roles
 1856:                     foreach (var framework in staffIdentityUser.Framework.Descendants)
 1857:                     {
 1858:                         if (!Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, framework.FullyQualifiedArabicName)) Ia.Ftn.Cl.Models.Identity.AddUserToRole(userManager, userName, framework.FullyQualifiedArabicName);
 1859:                     }
 1860:  
 1861:                     // add user to its ancestors roles
 1862:                     foreach (var framework in staffIdentityUser.Framework.Ancestors)
 1863:                     {
 1864:                         if (!Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, framework.FullyQualifiedArabicName)) Ia.Ftn.Cl.Models.Identity.AddUserToRole(userManager, userName, framework.FullyQualifiedArabicName);
 1865:                     }
 1866:  
 1867:                     // loop through all user roles and remove it from roles not in his description
 1868:                     foreach (var framework in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList)
 1869:                     {
 1870:                         if (framework.Id != staffIdentityUser.Framework.Id
 1871:                             && !staffIdentityUser.Framework.Descendants.Any(f => f.Id == framework.Id)
 1872:                             && !staffIdentityUser.Framework.Ancestors.Any(f => f.Id == framework.Id)
 1873:                             && Ia.Ftn.Cl.Models.Identity.IsUserInRole(userManager, userName, framework.FullyQualifiedArabicName))
 1874:                             Ia.Ftn.Cl.Models.Identity.RemoveUserFromRole(userManager, roleManager, userName, framework.FullyQualifiedArabicName);
 1875:                     }
 1876:                 }
 1877:             }
 1878:         }
 1879:  
 1880:         ////////////////////////////////////////////////////////////////////////////
 1881:         ////////////////////////////////////////////////////////////////////////////    
 1882:     }
 1883:  
 1884:     ////////////////////////////////////////////////////////////////////////////
 1885:     ////////////////////////////////////////////////////////////////////////////   
 1886: }