)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation LinksHome » Code Library » Authority

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

Authority support class of Optical Fiber Network (OFN) business model.

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