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