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