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

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

Administration support class for Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.AspNetCore.Identity;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Configuration;
    5: using System.Data;
    6: using System.Globalization;
    7: using System.IO;
    8: using System.Linq;
    9: using System.Reflection;
   10: using System.Xml.Linq;
   11:  
   12: namespace Ia.Ftn.Cl.Models.Data
   13: {
   14:     ////////////////////////////////////////////////////////////////////////////
   15:  
   16:     /// <summary publish="true">
   17:     /// Administration support class for Fixed Telecommunications Network (FTN) data model.
   18:     /// </summary>
   19:     /// 
   20:     /// <remarks> 
   21:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   22:     ///
   23:     /// 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
   24:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   25:     ///
   26:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   27:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   28:     /// 
   29:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   30:     /// 
   31:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   32:     /// </remarks> 
   33:     public class Administration
   34:     {
   35:         private static XDocument xDocument;
   36:         private static List<Ia.Ftn.Cl.Models.Business.Administration.Framework> frameworkList;
   37:         private static List<Ia.Ftn.Cl.Models.Business.Administration.Category> categoryList;
   38:         private static List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework> staffFrameworkList;
   39:         private static List<Ia.Ftn.Cl.Models.Business.Administration.StaffContact> staffContactList;
   40:         private static List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea> statisticList;
   41:  
   42:         private static readonly object objectLock = new object();
   43:  
   44:         /// <summary/>
   45:         public static string ApplicationRoleName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationRoleName"); } }
   46:  
   47:         /// <summary/>
   48:         public static string ApplicationUserName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationUserName"); } }
   49:  
   50:         /// <summary/>
   51:         public static string ApplicationUserPassword { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationUserPassword"); } }
   52:  
   53:         /// <summary/>
   54:         public static string ApplicationUserEmail { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationUserEmail"); } }
   55:  
   56:  
   57:         /// <summary/>
   58:         public static string ApplicationArabicFirstName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationArabicFirstName"); } }
   59:  
   60:         /// <summary/>
   61:         public static string ApplicationArabicMiddleName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationArabicMiddleName"); } }
   62:  
   63:         /// <summary/>
   64:         public static string ApplicationArabicLastName { get { return Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationArabicLastName"); } }
   65:  
   66:  
   67:         ////////////////////////////////////////////////////////////////////////////
   68:  
   69:         /// <summary>
   70:         ///
   71:         /// </summary>
   72:         public Administration() { }
   73:  
   74:         ////////////////////////////////////////////////////////////////////////////
   75:  
   76:         /// <summary>
   77:         ///
   78:         /// </summary>
   79:         public static List<Ia.Ftn.Cl.Models.Business.Administration.Framework> FrameworkList
   80:         {
   81:             get
   82:             {
   83:                 if (frameworkList == null || frameworkList.Count == 0)
   84:                 {
   85:                     lock (objectLock)
   86:                     {
   87:                         frameworkList = Ia.Ftn.Cl.Models.Data.Administration._FrameworkList();
   88:                     }
   89:                 }
   90:  
   91:                 return frameworkList;
   92:             }
   93:         }
   94:  
   95:         ////////////////////////////////////////////////////////////////////////////
   96:  
   97:         /// <summary>
   98:         ///
   99:         /// </summary>
  100:         private static List<Ia.Ftn.Cl.Models.Business.Administration.Framework> _FrameworkList()
  101:         {
  102:             int i;
  103:             string id, parentId;
  104:             string arabicName, coloredArabicName, siteNameList;
  105:             Ia.Ftn.Cl.Models.Business.Administration.Framework framework;
  106:  
  107:             var frameworkList = new List<Ia.Ftn.Cl.Models.Business.Administration.Framework>(Ia.Ftn.Cl.Models.Business.Administration.InitialFrameworkListLength); // needed to prevent errors
  108:  
  109:             var lightBackgroundColorList = Ia.Ftn.Cl.Models.Ui.Default.LightBackgroundColorList;
  110:  
  111:             foreach (XElement xe in XDocument.Element("administration").Element("frameworkList").Descendants("framework"))
  112:             {
  113:                 id = XmlBasedTwoDigitPerId(xe);
  114:                 parentId = Ia.Ftn.Cl.Models.Business.Administration.Framework.ParentId(id);
  115:                 arabicName = xe.Attribute("arabicName").Value;
  116:  
  117:                 i = int.Parse(id);
  118:  
  119:                 coloredArabicName = @"<span style=""color:" + lightBackgroundColorList[i % lightBackgroundColorList.Count] + @""">" + arabicName + "</span>";
  120:  
  121:                 framework = new Ia.Ftn.Cl.Models.Business.Administration.Framework();
  122:  
  123:                 framework.Id = id;
  124:                 framework.Level = xe.Ancestors().Count();
  125:                 framework.Type = xe.Attribute("type").Value;
  126:                 framework.Name = xe.Attribute("name").Value;
  127:                 framework.ArabicName = arabicName;
  128:  
  129:                 if (xe.Attribute("phone") != null && !string.IsNullOrEmpty(xe.Attribute("phone").Value)) framework.Phone = xe.Attribute("phone").Value;
  130:                 else framework.Phone = string.Empty;
  131:  
  132:                 framework.ColoredArabicName = coloredArabicName;
  133:  
  134:                 if (xe.Attribute("siteNameList") != null && !string.IsNullOrEmpty(xe.Attribute("siteNameList").Value))
  135:                 {
  136:                     siteNameList = xe.Attribute("siteNameList").Value;
  137:                     framework.Sites = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList where siteNameList.Contains(s.Name) select s).ToList();
  138:                 }
  139:                 else if (xe.Parent.Attribute("siteNameList") != null && !string.IsNullOrEmpty(xe.Parent.Attribute("siteNameList").Value))
  140:                 {
  141:                     siteNameList = xe.Parent.Attribute("siteNameList").Value;
  142:                     framework.Sites = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList where siteNameList.Contains(s.Name) select s).ToList();
  143:                 }
  144:                 else framework.Sites = new List<Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Site>();
  145:  
  146:                 frameworkList.Add(framework);
  147:             }
  148:  
  149:             // Parents, authorities and children
  150:             foreach (Ia.Ftn.Cl.Models.Business.Administration.Framework f in frameworkList)
  151:             {
  152:                 parentId = Ia.Ftn.Cl.Models.Business.Administration.Framework.ParentId(f.Id);
  153:  
  154:                 f.Parent = (from _f in frameworkList where _f.Id == parentId select _f).SingleOrDefault();
  155:  
  156:                 f.Children = new List<Ia.Ftn.Cl.Models.Business.Administration.Framework>();
  157:  
  158:                 if (f.Parent != null) f.Parent.Children.Add(f);
  159:             }
  160:  
  161:             // Children or self
  162:             foreach (var f in frameworkList)
  163:             {
  164:                 f.ChildrenOrSelf = (from _f in frameworkList where _f.Id == f.Id select _f).Union(f.Children).ToList();
  165:             }
  166:  
  167:             // Siblings
  168:             foreach (var f in frameworkList.ToList())
  169:             {
  170:                 //f.Siblings = new List<Ia.Ftn.Cl.Model.Business.Administration.Framework>();
  171:  
  172:                 f.Siblings = (from _f in frameworkList where _f.Parent == f.Parent && _f.Id != f.Id select _f).ToList();
  173:  
  174:                 f.SiblingsOrSelf = (from _f in frameworkList where _f.Id == f.Id select _f).Union(f.Siblings).ToList();
  175:             }
  176:  
  177:             // Descendants
  178:             foreach (var f in frameworkList.ToList())
  179:             {
  180:                 //f.Descendants = new List<Ia.Ftn.Cl.Model.Business.Administration.Framework>();
  181:  
  182:                 f.Descendants = (from _f in frameworkList
  183:                                  where _f.Id != f.Id && //_f.Id > f.Id &&
  184:                                      (_f.Parent != null && (_f.Parent == f
  185:                                      || _f.Parent.Parent != null && (_f.Parent.Parent == f
  186:                                      || _f.Parent.Parent.Parent != null && (_f.Parent.Parent.Parent == f
  187:                                      || _f.Parent.Parent.Parent.Parent != null && _f.Parent.Parent.Parent.Parent == f)))
  188:                                      )
  189:                                  select _f).ToList();
  190:  
  191:                 f.DescendantsOrSelf = (from _f in frameworkList where _f.Id == f.Id select _f).Union(f.Descendants).ToList();
  192:             }
  193:  
  194:             // Ancestors
  195:             foreach (var f in frameworkList.ToList())
  196:             {
  197:                 //f.Ancestors = new List<Ia.Ftn.Cl.Model.Business.Administration.Framework>();
  198:  
  199:                 f.Ancestors = (from _f in frameworkList
  200:                                where _f.Id != f.Id && //_f.Id < f.Id &&
  201:                                    (f.Parent != null && (f.Parent == _f
  202:                                    || f.Parent.Parent != null && (f.Parent.Parent == _f
  203:                                    || f.Parent.Parent.Parent != null && (f.Parent.Parent.Parent == _f
  204:                                    || f.Parent.Parent.Parent.Parent != null && f.Parent.Parent.Parent.Parent == _f)))
  205:                                    )
  206:                                select _f).ToList();
  207:  
  208:                 f.AncestorsOrSelf = (from _f in frameworkList where _f.Id == f.Id select _f).Union(f.Ancestors).ToList();
  209:             }
  210:  
  211:             return frameworkList.ToList();
  212:         }
  213:  
  214:         ////////////////////////////////////////////////////////////////////////////
  215:  
  216:         /// <summary>
  217:         ///
  218:         /// </summary>
  219:         private static string XmlBasedOneDigitPerId(XElement xeIn)
  220:         {
  221:             return XmlBasedId(xeIn, 1);
  222:         }
  223:  
  224:         ////////////////////////////////////////////////////////////////////////////
  225:  
  226:         /// <summary>
  227:         ///
  228:         /// </summary>
  229:         private static string XmlBasedTwoDigitPerId(XElement xeIn)
  230:         {
  231:             return XmlBasedId(xeIn, 2);
  232:         }
  233:  
  234:         ////////////////////////////////////////////////////////////////////////////
  235:  
  236:         /// <summary>
  237:         ///
  238:         /// </summary>
  239:         private static string XmlBasedId(XElement xe, int digit)
  240:         {
  241:             string id;
  242:  
  243:             id = string.Empty;
  244:  
  245:             while (xe.HasAttributes && xe.Attribute("id") != null)
  246:             {
  247:                 id = xe.Attribute("id").Value.PadLeft(digit, '0') + id;
  248:                 xe = xe.Parent;
  249:             }
  250:  
  251:             return id;
  252:         }
  253:  
  254:         ////////////////////////////////////////////////////////////////////////////
  255:  
  256:         /// <summary>
  257:         ///
  258:         /// </summary>
  259:         public static List<Ia.Ftn.Cl.Models.Business.Administration.Category> CategoryList
  260:         {
  261:             get
  262:             {
  263:                 if (categoryList == null || categoryList.Count == 0)
  264:                 {
  265:                     lock (objectLock)
  266:                     {
  267:                         categoryList = Ia.Ftn.Cl.Models.Data.Administration._CategoryList;
  268:                     }
  269:                 }
  270:  
  271:                 return categoryList;
  272:             }
  273:         }
  274:  
  275:         ////////////////////////////////////////////////////////////////////////////
  276:  
  277:         /// <summary>
  278:         ///
  279:         /// </summary>
  280:         private static List<Ia.Ftn.Cl.Models.Business.Administration.Category> _CategoryList
  281:         {
  282:             get
  283:             {
  284:                 Ia.Ftn.Cl.Models.Business.Administration.Category category;
  285:  
  286:                 var categoryList = new List<Ia.Ftn.Cl.Models.Business.Administration.Category>();
  287:  
  288:                 foreach (XElement xe in XDocument.Element("administration").Elements("category"))
  289:                 {
  290:                     category = new Ia.Ftn.Cl.Models.Business.Administration.Category()
  291:                     {
  292:                         Name = xe.Attribute("name").Value,
  293:                         Regex = xe.Attribute("regex").Value,
  294:                         Description = (xe.Attribute("description") != null) ? xe.Attribute("description").Value : string.Empty,
  295:                         Color = (xe.Attribute("color") != null) ? xe.Attribute("color").Value : string.Empty
  296:                     };
  297:  
  298:                     categoryList.Add(category);
  299:                 }
  300:  
  301:                 return categoryList.ToList();
  302:             }
  303:         }
  304:  
  305:         ////////////////////////////////////////////////////////////////////////////
  306:  
  307:         /// <summary>
  308:         ///
  309:         /// </summary>
  310:         public static List<Ia.Ftn.Cl.Models.Business.Administration.StaffContact> StaffContactList()
  311:         {
  312:             if (staffContactList == null || staffContactList.Count == 0)
  313:             {
  314:                 lock (objectLock)
  315:                 {
  316:                     staffContactList = Ia.Ftn.Cl.Models.Data.Administration._StaffContactList();
  317:                 }
  318:             }
  319:  
  320:             return staffContactList;
  321:         }
  322:  
  323:         ////////////////////////////////////////////////////////////////////////////
  324:  
  325:         /// <summary>
  326:         ///
  327:         /// </summary>
  328:         private static List<Ia.Ftn.Cl.Models.Business.Administration.StaffContact> _StaffContactList()
  329:         {
  330:             var staffContactList = new List<Ia.Ftn.Cl.Models.Business.Administration.StaffContact>();
  331:  
  332:             foreach (var staff in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List())
  333:             {
  334:                 if (staff.Email != null)
  335:                 {
  336:                     var staffContact = new Ia.Ftn.Cl.Models.Business.Administration.StaffContact() { StaffIdentityUser = staff };
  337:  
  338:                     staffContactList.Add(staffContact);
  339:                 }
  340:             }
  341:  
  342:             foreach (var contact in Ia.Ftn.Cl.Models.Data.Contact.List)
  343:             {
  344:                 if (contact.Email != null)
  345:                 {
  346:                     var staffContact = new Ia.Ftn.Cl.Models.Business.Administration.StaffContact() { Contact = contact };
  347:  
  348:                     staffContactList.Add(staffContact);
  349:                 }
  350:             }
  351:  
  352:             return staffContactList.ToList();
  353:         }
  354:  
  355:         ////////////////////////////////////////////////////////////////////////////
  356:  
  357:         /// <summary>
  358:         ///
  359:         /// </summary>
  360:         public static List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework> StaffFrameworkList()
  361:         {
  362:             if (staffFrameworkList == null || staffFrameworkList.Count == 0)
  363:             {
  364:                 lock (objectLock)
  365:                 {
  366:                     staffFrameworkList = Ia.Ftn.Cl.Models.Data.Administration._StaffFrameworkList();
  367:                 }
  368:             }
  369:  
  370:             return staffFrameworkList;
  371:         }
  372:  
  373:         ////////////////////////////////////////////////////////////////////////////
  374:  
  375:         /// <summary>
  376:         ///
  377:         /// </summary>
  378:         private static List<Ia.Ftn.Cl.Models.Business.Administration.StaffFramework> _StaffFrameworkList()
  379:         {
  380:             var staffList = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
  381:                              select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  382:                              {
  383:                                  Id = s.Id,
  384:                                  FrameworkId = s.Framework.Id,
  385:                                  IsStaff = true,
  386:                                  Name = s.FirstAndMiddleName
  387:                              }
  388:             ).ToList();
  389:  
  390:             var frameworkList = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  391:                                  select new Ia.Ftn.Cl.Models.Business.Administration.StaffFramework
  392:                                  {
  393:                                      Id = f.Id,
  394:                                      FrameworkId = f.Id,
  395:                                      IsFramework = true,
  396:                                      Name = f.FullyQualifiedArabicName //.ArabicName
  397:                                  }
  398:             ).ToList();
  399:  
  400:             staffFrameworkList = staffList.Union(frameworkList).ToList();
  401:  
  402:             return staffFrameworkList.ToList();
  403:         }
  404:  
  405:         ////////////////////////////////////////////////////////////////////////////
  406:  
  407:         /// <summary>
  408:         ///
  409:         /// </summary>
  410:         public static string FullyQualifiedFrameworkArabicNameFromFrameworkId(string frameworkId)
  411:         {
  412:             var fullyQualifiedArabicName = (from f in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList
  413:                                             where f.Id == frameworkId
  414:                                             select f.FullyQualifiedArabicName).SingleOrDefault();
  415:  
  416:             return fullyQualifiedArabicName;
  417:  
  418:         }
  419:  
  420:         ////////////////////////////////////////////////////////////////////////////
  421:         ////////////////////////////////////////////////////////////////////////////
  422:  
  423:         /// <summary>
  424:         ///
  425:         /// </summary>
  426:         public static int ServiceRequestServicesWithNullAccessCount()
  427:         {
  428:             using (var db = new Ia.Ftn.Cl.Db())
  429:             {
  430:                 return (from srs in db.ServiceRequestServices
  431:                         where srs.Access == null
  432:                         select srs.Id).Count();
  433:             }
  434:         }
  435:  
  436:         ////////////////////////////////////////////////////////////////////////////
  437:  
  438:         /// <summary>
  439:         ///
  440:         /// </summary>
  441:         public static int ServicesWithNullAccessCount()
  442:         {
  443:             using (var db = new Ia.Ftn.Cl.Db())
  444:             {
  445:                 return (from s in db.Service2
  446:                         where s.ServiceType == Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService && s.Access == null
  447:                         select s.Id).Count();
  448:             }
  449:         }
  450:  
  451:         ////////////////////////////////////////////////////////////////////////////
  452:  
  453:         /// <summary>
  454:         ///
  455:         /// </summary>
  456:         public static List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea> ServiceAccessStatisticWithinKuwaitFtnAreaCachedDaily
  457:         {
  458:             get
  459:             {
  460:                 if (statisticList == null || statisticList.Count == 0)
  461:                 {
  462:                     if (Ia.Cl.Models.Cache.Instance.TryGetValue("statisticList" + DateTime.Now.Day, out statisticList))
  463:                     {
  464:                     }
  465:                     else
  466:                     {
  467:                         lock (objectLock)
  468:                         {
  469:                             statisticList = Ia.Ftn.Cl.Models.Data.Administration.ServiceAccessStatisticWithinKuwaitFtnArea();
  470:  
  471:                             Ia.Cl.Models.Cache.Instance.Set("statisticList" + DateTime.Now.Day, statisticList);
  472:                         }
  473:                     }
  474:                 }
  475:  
  476:                 return statisticList;
  477:             }
  478:         }
  479:  
  480:         ////////////////////////////////////////////////////////////////////////////
  481:  
  482:         /// <summary>
  483:         ///
  484:         /// </summary>
  485:         public static List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea> ServiceAccessStatisticWithinKuwaitFtnArea()
  486:         {
  487:             if (statisticList == null || statisticList.Count == 0)
  488:             {
  489:                 int fourDigitDomain, fiveDigitDomain;
  490:                 int totalService, totalNokiaService, totalHuaweiService, totalServiceRequestService, totalAccessCapacity, totalNokiaOnt, totalHuaweiOnt, totalNokiaAccess, totalHuaweiAccess, totalAccessReady, totalAccessUsed;
  491:                 string accessId;
  492:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor vendor;
  493:                 Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea kuwaitAreaStatistic;
  494:                 Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Olt olt;
  495:  
  496:                 statisticList = new List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea>();
  497:                 statisticList.Clear();
  498:  
  499:                 totalService = totalNokiaService = totalHuaweiService = totalServiceRequestService = totalAccessCapacity = totalNokiaOnt = totalHuaweiOnt = totalNokiaAccess = totalHuaweiAccess = totalAccessReady = totalAccessUsed = totalService = totalServiceRequestService = 0;
  500:  
  501:                 //kuwaitFtnAreaList = new List<Ia.Ftn.Cl.Model.Business.Service.KuwaitFtnArea>(); // I need to clear it because I add an item in it below
  502:                 var kuwaitFtnAreaList = Ia.Ftn.Cl.Models.Data.Service.KuwaitFtnAreaList;
  503:  
  504:                 var ontAccessIdToSeviceListDictionary = Ia.Ftn.Cl.Models.Data.Service2.OntAccessIdToSeviceListDictionary();
  505:  
  506:                 var ontList = Ia.Ftn.Cl.Models.Data.Nokia.Ont.ListIncludeAccess();
  507:                 var emsOntList = Ia.Ftn.Cl.Models.Data.Huawei.Ont.ListIncludeAccess();
  508:                 var accessList = Ia.Ftn.Cl.Models.Data.Access.List();
  509:                 var accessIdToOltIdDictionary = Ia.Ftn.Cl.Models.Data.Access.IdToOltIdDictionary;
  510:  
  511:                 var accessIdToKuwaitFtnAreaIdDictionary = Ia.Ftn.Cl.Models.Data.Access.IdToKuwaitFtnAreaIdDictionary;
  512:  
  513:                 var serviceRequestServiceProvisionedServiceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.ServiceRequestService.ProvisionedServiceIdToAccessIdDictionary;
  514:                 var serviceIdToAccessIdDictionary = Ia.Ftn.Cl.Models.Data.Service2.ServiceIdToAccessIdDictionary;
  515:  
  516:                 var accessesWithProvisionedAndReadyOntsIdToKuwaitFtnAreaIdDictionary = Ia.Ftn.Cl.Models.Data.Access.AccessWithProvisionedAndReadyOntIdToKuwaitFtnAreaIdDictionary;
  517:  
  518:                 var domainToRouterVendorDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.DomainToRouterVendorDictionary;
  519:  
  520:                 var unknown = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea("Unknown", "غير معرف");
  521:  
  522:                 //ontIdToOltIdDictionary = Ia.Ftn.Cl.Model.Data.NetworkDesignDocument.OntIdToOltIdDictionary;
  523:  
  524:                 // - ONT capacity, usage, # of services in an ONT, type of ONT
  525:                 // - Graphics
  526:                 /*
  527:                 update statistics
  528:     Vendor,
  529:     number perfix,
  530:     4 in ONT,
  531:     0 in ONT,
  532:     Acces: ONT used by subscribers
  533:     */
  534:  
  535:                 foreach (var kna in kuwaitFtnAreaList)
  536:                 {
  537:                     kuwaitAreaStatistic = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea();
  538:  
  539:                     kuwaitAreaStatistic.Name = kna.NameArabicName;
  540:  
  541:                     kuwaitAreaStatistic.Symbol = kna.Symbol;
  542:  
  543:                     kuwaitAreaStatistic.ServiceRequestService = 0;
  544:  
  545:                     kuwaitAreaStatistic.NokiaService = 0;
  546:                     kuwaitAreaStatistic.HuaweiService = 0;
  547:                     kuwaitAreaStatistic.Service = 0;
  548:  
  549:                     foreach (KeyValuePair<string, string> kvp in serviceIdToAccessIdDictionary)
  550:                     {
  551:                         accessId = kvp.Value;
  552:  
  553:                         if (accessIdToKuwaitFtnAreaIdDictionary.ContainsKey(accessId))
  554:                         {
  555:                             if (accessIdToKuwaitFtnAreaIdDictionary[accessId] == kna.Id)
  556:                             {
  557:                                 kuwaitAreaStatistic.Service++;
  558:  
  559:                                 fiveDigitDomain = int.Parse(kvp.Key.Substring(0, 5));
  560:  
  561:                                 if (domainToRouterVendorDictionary.ContainsKey(fiveDigitDomain)) vendor = domainToRouterVendorDictionary[fiveDigitDomain];
  562:                                 else
  563:                                 {
  564:                                     fourDigitDomain = int.Parse(kvp.Key.Substring(0, 4));
  565:  
  566:                                     if (domainToRouterVendorDictionary.ContainsKey(fourDigitDomain))
  567:                                     {
  568:                                         vendor = domainToRouterVendorDictionary[fourDigitDomain];
  569:                                     }
  570:                                     else vendor = null;
  571:                                 }
  572:  
  573:                                 if (vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) kuwaitAreaStatistic.NokiaService++;
  574:                                 else if (vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei) kuwaitAreaStatistic.HuaweiService++;
  575:                                 else
  576:                                 {
  577:                                     unknown.Service++;
  578:  
  579:                                     //throw new Exception("Vendor is unknown");
  580:                                 }
  581:  
  582:                             }
  583:                         }
  584:                     }
  585:  
  586:                     kuwaitAreaStatistic.NokiaHuaweiService = (kuwaitAreaStatistic.NokiaService + kuwaitAreaStatistic.HuaweiService) + " (" + kuwaitAreaStatistic.NokiaService + "/" + kuwaitAreaStatistic.HuaweiService + ")";
  587:  
  588:  
  589:                     foreach (KeyValuePair<string, string> kvp in serviceRequestServiceProvisionedServiceIdToAccessIdDictionary)
  590:                     {
  591:                         if (accessIdToKuwaitFtnAreaIdDictionary.ContainsKey(kvp.Value))
  592:                         {
  593:                             if (accessIdToKuwaitFtnAreaIdDictionary[kvp.Value] == kna.Id)
  594:                             {
  595:                                 kuwaitAreaStatistic.ServiceRequestService++;
  596:                             }
  597:                         }
  598:                     }
  599:  
  600:                     //statistic.SiteAccessCapacity = kna.Site.Routers.SelectMany(u => u.Odfs.SelectMany(y => y.Olts)).Count() * 1024;
  601:                     //statistic.SiteAccessCapacity = f.Sum(u => kna.Site.Routers.Any(u => u.Odfs.Any(y => y.Olts.Any(z => z.Id == u.Value)))) * 1024;
  602:                     //kuwaitAreaStatistic.AccessProvisioned = accessIdToKuwaitFtnAreaIdDictionary.Count(u => u.Value == kna.Id);
  603:                     //kuwaitAreaStatistic.AccessUtilized = 0;
  604:  
  605:                     // below: this does not include SSR accesses for area
  606:                     kuwaitAreaStatistic.AccessCapacity = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  607:                                                           where o.Symbol == kna.Symbol
  608:                                                           select o).Sum(o => o.NumberOfPons * o.NumberOfOntsInPon);
  609:  
  610:                     kuwaitAreaStatistic.NokiaOnt = 0;
  611:                     kuwaitAreaStatistic.HuaweiOnt = 0;
  612:  
  613:                     foreach (var o in ontList)
  614:                     {
  615:                         if (o.Access != null)
  616:                         {
  617:                             if (accessIdToKuwaitFtnAreaIdDictionary.ContainsKey(o.Access.Id))
  618:                             {
  619:                                 if (accessIdToKuwaitFtnAreaIdDictionary[o.Access.Id] == kna.Id)
  620:                                 {
  621:                                     kuwaitAreaStatistic.NokiaOnt++;
  622:                                 }
  623:                             }
  624:                         }
  625:                         else
  626:                         {
  627:                         }
  628:                     }
  629:  
  630:                     foreach (var o in emsOntList)
  631:                     {
  632:                         if (o.Access != null)
  633:                         {
  634:                             if (accessIdToKuwaitFtnAreaIdDictionary.ContainsKey(o.Access.Id))
  635:                             {
  636:                                 if (accessIdToKuwaitFtnAreaIdDictionary[o.Access.Id] == kna.Id)
  637:                                 {
  638:                                     kuwaitAreaStatistic.HuaweiOnt++;
  639:                                 }
  640:                             }
  641:                         }
  642:                         else
  643:                         {
  644:                         }
  645:                     }
  646:  
  647:                     kuwaitAreaStatistic.NokiaHuaweiOnt = (kuwaitAreaStatistic.NokiaOnt + kuwaitAreaStatistic.HuaweiOnt) + " (" + kuwaitAreaStatistic.NokiaOnt + "/" + kuwaitAreaStatistic.HuaweiOnt + ")";
  648:  
  649:                     kuwaitAreaStatistic.NokiaAccess = 0;
  650:                     kuwaitAreaStatistic.HuaweiAccess = 0;
  651:  
  652:                     foreach (var a in accessList)
  653:                     {
  654:                         if (accessIdToKuwaitFtnAreaIdDictionary[a.Id] == kna.Id)
  655:                         {
  656:                             olt = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  657:                                    where o.Id == accessIdToOltIdDictionary[a.Id]
  658:                                    select o).SingleOrDefault();
  659:  
  660:                             if (olt != null)
  661:                             {
  662:                                 // <vendor id="1" name="Nokia" shortName="No" ... />
  663:                                 if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) kuwaitAreaStatistic.NokiaAccess++;
  664:  
  665:                                 // <vendor id="2" name="Huawei" shortName="Hu" ... />
  666:                                 else if (olt.Odf.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei) kuwaitAreaStatistic.HuaweiAccess++;
  667:                             }
  668:                             else
  669:                             {
  670:  
  671:                             }
  672:                         }
  673:                     }
  674:  
  675:                     kuwaitAreaStatistic.NokiaHuaweiAccess = (kuwaitAreaStatistic.NokiaAccess + kuwaitAreaStatistic.HuaweiAccess) + " (" + kuwaitAreaStatistic.NokiaAccess + "/" + kuwaitAreaStatistic.HuaweiAccess + ")";
  676:  
  677:  
  678:                     kuwaitAreaStatistic.AccessReady = 0;
  679:                     kuwaitAreaStatistic.AccessUsed = 0;
  680:  
  681:                     foreach (var a in accessList)
  682:                     {
  683:                         if (accessesWithProvisionedAndReadyOntsIdToKuwaitFtnAreaIdDictionary.ContainsKey(a.Id))
  684:                         {
  685:                             if (accessesWithProvisionedAndReadyOntsIdToKuwaitFtnAreaIdDictionary[a.Id] == kna.Id)
  686:                             {
  687:                                 kuwaitAreaStatistic.AccessReady++;
  688:  
  689:                                 if (ontAccessIdToSeviceListDictionary[a.Id].Count > 0) kuwaitAreaStatistic.AccessUsed++;
  690:                             }
  691:                         }
  692:                     }
  693:  
  694:                     kuwaitAreaStatistic.AccessReadyUsed = kuwaitAreaStatistic.AccessReady + "/" + kuwaitAreaStatistic.AccessUsed;
  695:  
  696:  
  697:                     // totals:
  698:                     totalService += kuwaitAreaStatistic.Service;
  699:  
  700:                     totalNokiaService += kuwaitAreaStatistic.NokiaService;
  701:                     totalHuaweiService += kuwaitAreaStatistic.HuaweiService;
  702:  
  703:                     totalServiceRequestService += kuwaitAreaStatistic.ServiceRequestService;
  704:  
  705:                     totalAccessCapacity += kuwaitAreaStatistic.AccessCapacity;
  706:  
  707:                     totalNokiaOnt += kuwaitAreaStatistic.NokiaOnt;
  708:                     totalHuaweiOnt += kuwaitAreaStatistic.HuaweiOnt;
  709:  
  710:                     totalNokiaAccess += kuwaitAreaStatistic.NokiaAccess;
  711:                     totalHuaweiAccess += kuwaitAreaStatistic.HuaweiAccess;
  712:  
  713:                     totalAccessReady += kuwaitAreaStatistic.AccessReady;
  714:                     totalAccessUsed += kuwaitAreaStatistic.AccessUsed;
  715:  
  716:                     statisticList.Add(kuwaitAreaStatistic);
  717:                 }
  718:  
  719:                 statisticList = statisticList.OrderBy(u => u.Name).ToList();
  720:  
  721:                 statisticList.Add(unknown);
  722:  
  723:                 // totals:
  724:                 kuwaitAreaStatistic = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.KuwaitArea();
  725:  
  726:                 kuwaitAreaStatistic.Name = "Total";
  727:  
  728:                 kuwaitAreaStatistic.Service = totalService;
  729:                 kuwaitAreaStatistic.NokiaService = totalNokiaService;
  730:                 kuwaitAreaStatistic.HuaweiService = totalHuaweiService;
  731:                 kuwaitAreaStatistic.NokiaHuaweiService = (kuwaitAreaStatistic.NokiaService + kuwaitAreaStatistic.HuaweiService) + " (" + kuwaitAreaStatistic.NokiaService + "/" + kuwaitAreaStatistic.HuaweiService + ")";
  732:  
  733:  
  734:                 kuwaitAreaStatistic.ServiceRequestService = totalServiceRequestService;
  735:  
  736:                 kuwaitAreaStatistic.AccessCapacity = totalAccessCapacity;
  737:  
  738:                 kuwaitAreaStatistic.NokiaOnt = totalNokiaOnt;
  739:                 kuwaitAreaStatistic.HuaweiOnt = totalHuaweiOnt;
  740:                 kuwaitAreaStatistic.NokiaHuaweiOnt = (totalNokiaOnt + totalHuaweiOnt) + " (" + totalNokiaOnt + "/" + totalHuaweiOnt + ")";
  741:  
  742:                 kuwaitAreaStatistic.NokiaAccess = totalNokiaAccess;
  743:                 kuwaitAreaStatistic.HuaweiAccess = totalHuaweiAccess;
  744:                 kuwaitAreaStatistic.NokiaHuaweiAccess = (totalNokiaAccess + totalHuaweiAccess) + " (" + totalNokiaAccess + "/" + totalHuaweiAccess + ")";
  745:  
  746:                 kuwaitAreaStatistic.AccessReady = totalAccessReady;
  747:                 kuwaitAreaStatistic.AccessUsed = totalAccessUsed;
  748:                 kuwaitAreaStatistic.AccessReadyUsed = totalAccessReady + "/" + totalAccessUsed;
  749:  
  750:                 statisticList.Add(kuwaitAreaStatistic);
  751:             }
  752:  
  753:             return statisticList;
  754:         }
  755:  
  756:         ////////////////////////////////////////////////////////////////////////////
  757:  
  758:         /// <summary>
  759:         ///
  760:         /// </summary>
  761:         public static List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site> SiteStatistics()
  762:         {
  763:             int siteId;
  764:             int totalFiberAccessCapacity, totalFiberServiceCapacity, totalMsanServiceCapacity, totalFiberService, totalNokiaService, totalHuaweiService, totalService;
  765:             int totalMsanService, totalPstnService, totalEricssonService, totalSiemensService;
  766:             Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site siteStatistic;
  767:             List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site> siteStatisticList;
  768:  
  769:             siteStatisticList = new List<Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site>();
  770:  
  771:             totalFiberService = totalNokiaService = totalHuaweiService = totalFiberAccessCapacity = totalFiberServiceCapacity = totalMsanServiceCapacity = 0;
  772:             totalMsanService = totalPstnService = totalEricssonService = totalSiemensService = 0;
  773:             totalService = 0;
  774:  
  775:             using (var db = new Ia.Ftn.Cl.Db())
  776:             {
  777:                 var oltIdToCountOfServiceDictionary = Ia.Ftn.Cl.Models.Data.Default.OltIdToCountOfServiceDictionary();
  778:                 var oltList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList;
  779:  
  780:                 var msanSiteIdToDidListDictionary = Ia.Ftn.Cl.Models.Data.Huawei.Dev.MsanSiteIdToDidListDictionary();
  781:                 var msanSiteIdToCapacityDictionary = Ia.Ftn.Cl.Models.Data.Huawei.Dev.MsanSiteIdToCapacityDictionary();
  782:                 var msanDidToServiceCountDictionary = Ia.Ftn.Cl.Models.Data.Default.MsanDidToMsanServiceCountDictionary();
  783:  
  784:                 var pstnFiveDigitDomainToCountOfServicesDictionary = Ia.Ftn.Cl.Models.Data.Service2.PstnFiveDigitDomainToCountOfServicesDictionary();
  785:                 var pstnToFiveDigitDomainListDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PstnToFiveDigitDomainListDictionary();
  786:  
  787:                 var unknown = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site(); // ("Unknown", );
  788:                 unknown.NameArabicName = "Unknown (غير معرف)";
  789:                 unknown.Name = "Unknown";
  790:  
  791:                 foreach (var site in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList)
  792:                 {
  793:                     siteStatistic = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site();
  794:  
  795:                     siteId = site.Id;
  796:                     siteStatistic.Id = site.Id.ToString();
  797:                     siteStatistic.NameArabicName = site.NameArabicName;
  798:                     siteStatistic.Name = site.Name;
  799:  
  800:                     siteStatistic.KuwaitAreaNameListString = string.Join(", ", site.KuwaitFtnAreas.Select(u => u.ArabicName));
  801:  
  802:                     siteStatistic.PstnDomainListString = string.Join(", ", site.Pstns.SelectMany(u => u.DomainList).ToList());
  803:  
  804:                     siteStatistic.MsanDomainListString = string.Join(", ", site.Msans.SelectMany(u => u.DomainList).ToList());
  805:  
  806:                     siteStatistic.DomainListString = string.Join(", ", site.Routers.SelectMany(u => u.DomainList).ToList());
  807:  
  808:                     siteStatistic.SymbolListString = string.Join(", ", site.AreaSymbolList.ToList());
  809:  
  810:                     siteStatistic.FiberAccessCapacity = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  811:                                                          where o.Odf.Router.Site.Id == siteId
  812:                                                          select o).Sum(o => o.NumberOfPons * o.NumberOfOntsInPon);
  813:  
  814:                     siteStatistic.FiberServiceCapacity = site.NumberOfPossibleServicesWithinDomainList;
  815:  
  816:  
  817:                     // Fiber
  818:                     foreach (var olt in site.Routers.SelectMany(u => u.Odfs.SelectMany(v => v.Olts)))
  819:                     {
  820:                         if (oltIdToCountOfServiceDictionary.ContainsKey(olt.Id))
  821:                         {
  822:                             if (olt.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Nokia) siteStatistic.NokiaService += oltIdToCountOfServiceDictionary[olt.Id];
  823:                             else if (olt.Odf.Router.Vendor == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Vendor.Huawei) siteStatistic.HuaweiService += oltIdToCountOfServiceDictionary[olt.Id];
  824:                             else
  825:                             {
  826:                                 unknown.FiberService++;
  827:                             }
  828:                         }
  829:                     }
  830:  
  831:                     siteStatistic.FiberService = siteStatistic.NokiaService + siteStatistic.HuaweiService;
  832:                     siteStatistic.FiberServiceText = siteStatistic.FiberService + " (" + siteStatistic.NokiaService + "/" + siteStatistic.HuaweiService + ")";
  833:  
  834:  
  835:                     // MSAN
  836:                     if (!string.IsNullOrEmpty(siteStatistic.MsanDomainListString))
  837:                     {
  838:                         if (msanSiteIdToDidListDictionary.ContainsKey(siteId))
  839:                         {
  840:                             siteStatistic.MsanServiceCapacity = msanSiteIdToCapacityDictionary[siteId];
  841:  
  842:                             foreach (var msanDid in msanSiteIdToDidListDictionary[siteId])
  843:                             {
  844:                                 if (msanDidToServiceCountDictionary.ContainsKey(msanDid))
  845:                                 {
  846:                                     siteStatistic.MsanService += msanDidToServiceCountDictionary[msanDid];
  847:                                 }
  848:                                 else
  849:                                 {
  850:                                     unknown.MsanService++;
  851:                                 }
  852:                             }
  853:                         }
  854:  
  855:                         siteStatistic.MsanServiceText = siteStatistic.MsanService.ToString();
  856:                     }
  857:  
  858:                     siteStatistic.Service = siteStatistic.FiberService + siteStatistic.MsanService;
  859:                     siteStatistic.ServiceText = siteStatistic.Service.ToString();
  860:  
  861:                     // PSTN
  862:                     if (!string.IsNullOrEmpty(siteStatistic.PstnDomainListString))
  863:                     {
  864:                         foreach (var pstn in site.Pstns)
  865:                         {
  866:                             var list = pstnToFiveDigitDomainListDictionary[pstn];
  867:  
  868:                             foreach (var l in list)
  869:                             {
  870:                                 if (pstnFiveDigitDomainToCountOfServicesDictionary.ContainsKey(l.ToString()))
  871:                                 {
  872:                                     if (pstn.PstnExchangeType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.EricssonAxe) siteStatistic.EricssonPstnService += pstnFiveDigitDomainToCountOfServicesDictionary[l.ToString()];
  873:                                     else if (pstn.PstnExchangeType == Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.PstnExchangeType.SiemensEwsd) siteStatistic.SiemensPstnService += pstnFiveDigitDomainToCountOfServicesDictionary[l.ToString()];
  874:                                     else
  875:                                     {
  876:                                         unknown.PstnService++;
  877:                                     }
  878:                                 }
  879:                                 else
  880:                                 {
  881:  
  882:                                 }
  883:                             }
  884:                         }
  885:  
  886:                         siteStatistic.PstnService = siteStatistic.EricssonPstnService + siteStatistic.SiemensPstnService;
  887:                         siteStatistic.EricssonSiemensPstnServiceText = siteStatistic.PstnService + " (" + siteStatistic.EricssonPstnService + "/" + siteStatistic.SiemensPstnService + ")";
  888:                     }
  889:  
  890:  
  891:                     // totals:
  892:                     totalFiberService += siteStatistic.FiberService;
  893:                     totalService += siteStatistic.Service;
  894:  
  895:                     totalNokiaService += siteStatistic.NokiaService;
  896:                     totalHuaweiService += siteStatistic.HuaweiService;
  897:  
  898:                     totalFiberAccessCapacity += siteStatistic.FiberAccessCapacity;
  899:                     totalFiberServiceCapacity += siteStatistic.FiberServiceCapacity;
  900:  
  901:                     totalMsanServiceCapacity += siteStatistic.MsanServiceCapacity;
  902:                     totalMsanService += siteStatistic.MsanService;
  903:  
  904:                     totalPstnService += siteStatistic.PstnService;
  905:  
  906:                     totalEricssonService += siteStatistic.EricssonPstnService;
  907:                     totalSiemensService += siteStatistic.SiemensPstnService;
  908:  
  909:                     siteStatisticList.Add(siteStatistic);
  910:                 }
  911:  
  912:                 // MSAN: collect count of numbers in DIDs *not* within site DIDs
  913:                 var didList = msanSiteIdToDidListDictionary.Values.SelectMany(x => x).ToList();
  914:  
  915:                 foreach (var d in msanDidToServiceCountDictionary)
  916:                 {
  917:                     if (!didList.Contains(d.Key)) unknown.MsanService += d.Value;
  918:                 }
  919:  
  920:                 siteStatisticList = siteStatisticList.OrderBy(u => u.Name).ToList();
  921:  
  922:                 siteStatisticList.Add(unknown);
  923:  
  924:                 // below: last totals row
  925:                 siteStatistic = new Ia.Ftn.Cl.Models.Business.Administration.Statistic.Site();
  926:  
  927:                 siteStatistic.NameArabicName = "Total (مجموع)";
  928:                 siteStatistic.Name = "Total";
  929:  
  930:                 siteStatistic.FiberService = totalFiberService;
  931:                 siteStatistic.NokiaService = totalNokiaService;
  932:                 siteStatistic.HuaweiService = totalHuaweiService;
  933:                 siteStatistic.FiberServiceText = (siteStatistic.NokiaService + siteStatistic.HuaweiService) + " (" + siteStatistic.NokiaService + "/" + siteStatistic.HuaweiService + ")";
  934:  
  935:                 siteStatistic.FiberAccessCapacity = totalFiberAccessCapacity;
  936:                 siteStatistic.FiberServiceCapacity = totalFiberServiceCapacity;
  937:  
  938:                 siteStatistic.MsanService = totalMsanService;
  939:                 siteStatistic.MsanServiceCapacity = totalMsanServiceCapacity;
  940:                 siteStatistic.MsanServiceText = totalMsanService.ToString();
  941:  
  942:                 siteStatistic.PstnService = totalPstnService;
  943:                 siteStatistic.EricssonPstnService = totalEricssonService;
  944:                 siteStatistic.SiemensPstnService = totalSiemensService;
  945:                 siteStatistic.EricssonSiemensPstnServiceText = (siteStatistic.EricssonPstnService + siteStatistic.SiemensPstnService) + " (" + siteStatistic.EricssonPstnService + "/" + siteStatistic.SiemensPstnService + ")";
  946:  
  947:                 siteStatistic.Service = totalService;
  948:                 siteStatistic.ServiceText = siteStatistic.Service.ToString();
  949:  
  950:                 siteStatisticList.Add(siteStatistic);
  951:             }
  952:  
  953:             return siteStatisticList;
  954:         }
  955:  
  956:         ////////////////////////////////////////////////////////////////////////////
  957:  
  958:         /// <summary>
  959:         ///
  960:         /// </summary>
  961:         public class YearMonthProvisionedDeprovisionServiceProvisioningStatistic
  962:         {
  963:             public int Year { get; set; }
  964:  
  965:             public int Month { get; set; }
  966:  
  967:             public string MonthName
  968:             {
  969:                 get
  970:                 {
  971:                     return CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(this.Month);
  972:                 }
  973:             }
  974:  
  975:             public string YearMonth { get { return Year + "-" + Month.ToString().PadLeft(2, '0'); } }
  976:  
  977:             public int Provisioned { get; set; }
  978:  
  979:             public int Deprovisioned { get; set; }
  980:  
  981:             public int Total { get; set; }
  982:         }
  983:  
  984:         ////////////////////////////////////////////////////////////////////////////
  985:  
  986:         /// <summary>
  987:         ///
  988:         /// </summary>
  989:         public static List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic> ServiceProvisioningInImsSwitchAndAccessNetworkStatistic()
  990:         {
  991:             List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic> list;
  992:  
  993:             using (var db = new Ia.Ftn.Cl.Db())
  994:             {
  995:                 var sqlServer = new Ia.Cl.Models.Db.SqlServer();
  996:  
  997:                 var dbtable = sqlServer.Select(@"
  998: select
  999: YEAR(sr.RequestDateTime) Year, MONTH(sr.RequestDateTime) Month,
 1000: SUM(case WHEN sr.ServiceId = 1 or sr.ServiceId = 129 or sr.ServiceId = 54 then 1 else 0 end) Provisioned,
 1001: SUM(case WHEN sr.ServiceId = 40 then 1 else 0 end) Deprovisioned 
 1002: --count(srs.Provisioned)
 1003: from ServiceRequestServices srs
 1004: left outer join ServiceRequests sr on srs.Id = sr.ServiceRequestService_Id
 1005: where (sr.ServiceId = 1 or sr.ServiceId = 129 or sr.ServiceId = 54 or sr.ServiceId = 40) 
 1006: group by YEAR(sr.RequestDateTime), MONTH(sr.RequestDateTime)
 1007: order by YEAR(sr.RequestDateTime), MONTH(sr.RequestDateTime)
 1008: ");
 1009:  
 1010:                 /*
 1011: -- <service id="1" arabicName="خط هاتف" />
 1012: -- <service id="129" arabicName="خط هاتف مع نداء آلي"/>
 1013: -- <service id="54" arabicName="اعادة تركيب" />
 1014: -- <service id="40" arabicName="رفع خط" />
 1015:                 *
 1016:                  */
 1017:  
 1018:                 // I tried every possible way to use LINQ but failed. As a last resort I used SqlServer directly
 1019:  
 1020:                 var total = 0;
 1021:                 list = new List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic>();
 1022:  
 1023:                 foreach (DataRow row in dbtable.Rows)
 1024:                 {
 1025:                     var item = new YearMonthProvisionedDeprovisionServiceProvisioningStatistic();
 1026:  
 1027:                     item.Year = int.Parse(row["Year"].ToString());
 1028:                     item.Month = int.Parse(row["Month"].ToString());
 1029:                     item.Provisioned = int.Parse(row["Provisioned"].ToString());
 1030:                     item.Deprovisioned = int.Parse(row["Deprovisioned"].ToString());
 1031:  
 1032:                     total += item.Provisioned - item.Deprovisioned;
 1033:                     item.Total = total;
 1034:  
 1035:                     list.Add(item);
 1036:                 }
 1037:             }
 1038:  
 1039:             return list;
 1040:         }
 1041:  
 1042:         ////////////////////////////////////////////////////////////////////////////
 1043:  
 1044:         /// <summary>
 1045:         ///
 1046:         /// </summary>
 1047:         public static List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic> ServiceProvisioningInFtnSwitchNetworkStatistic()
 1048:         {
 1049:             List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic> list;
 1050:  
 1051:             using (var db = new Ia.Ftn.Cl.Db())
 1052:             {
 1053:                 var sqlServer = new Ia.Cl.Models.Db.SqlServer();
 1054:  
 1055:                 var dbtable = sqlServer.Select(@"
 1056: select
 1057: YEAR(sr.RequestDateTime) Year, MONTH(sr.RequestDateTime) Month,
 1058: SUM(case WHEN sr.ServiceId = 1 or sr.ServiceId = 129 or sr.ServiceId = 54 then 1 else 0 end) Provisioned,
 1059: SUM(case WHEN sr.ServiceId = 40 then 1 else 0 end) Deprovisioned 
 1060: --count(srs.Provisioned)
 1061: from ServiceRequests sr
 1062: where (sr.ServiceId = 1 or sr.ServiceId = 129 or sr.ServiceId = 54 or sr.ServiceId = 40) 
 1063: group by YEAR(sr.RequestDateTime), MONTH(sr.RequestDateTime)
 1064: order by YEAR(sr.RequestDateTime), MONTH(sr.RequestDateTime)
 1065: ");
 1066:  
 1067:                 /*
 1068: -- <service id="1" arabicName="خط هاتف" />
 1069: -- <service id="129" arabicName="خط هاتف مع نداء آلي"/>
 1070: -- <service id="54" arabicName="اعادة تركيب" />
 1071: -- <service id="40" arabicName="رفع خط" />
 1072:                 *
 1073:                  */
 1074:  
 1075:                 // I tried every possible way to use LINQ but failed. As a last resort I used SqlServer directly
 1076:  
 1077:                 var total = 0;
 1078:                 list = new List<YearMonthProvisionedDeprovisionServiceProvisioningStatistic>();
 1079:  
 1080:                 foreach (DataRow row in dbtable.Rows)
 1081:                 {
 1082:                     var item = new YearMonthProvisionedDeprovisionServiceProvisioningStatistic();
 1083:  
 1084:                     item.Year = int.Parse(row["Year"].ToString());
 1085:                     item.Month = int.Parse(row["Month"].ToString());
 1086:                     item.Provisioned = int.Parse(row["Provisioned"].ToString());
 1087:                     item.Deprovisioned = int.Parse(row["Deprovisioned"].ToString());
 1088:  
 1089:                     total += item.Provisioned - item.Deprovisioned;
 1090:                     item.Total = total;
 1091:  
 1092:                     list.Add(item);
 1093:                 }
 1094:             }
 1095:  
 1096:             return list;
 1097:         }
 1098:  
 1099:         /*
 1100:         ////////////////////////////////////////////////////////////////////////////
 1101: 
 1102:         /// <summary>
 1103:         ///
 1104:         /// </summary>
 1105:         public static List<Ia.Ftn.Cl.Model.Business.Administration.Statistic> PhoneStatistic(string timePeriod)
 1106:         {
 1107:             List<Ia.Ftn.Cl.Model.Business.Administration.Statistic> phoneStatisticList;
 1108: 
 1109:             /*
 1110:             string s, where;
 1111:             DateTime from, to;
 1112:             DataTable dt;
 1113: 
 1114:             if (timePeriod != null)
 1115:             {
 1116:                 from = DateTime.Parse(timePeriod);
 1117:                 to = DateTime.Parse(timePeriod);
 1118:                 to = to.AddMonths(1);
 1119: 
 1120:                 where = " AND (sr.request_time >= '" + sqlserver.SmallDateTime(from) + "' AND sr.request_time < '" + sqlserver.SmallDateTime(to) + "') ";
 1121:             }
 1122:             else where = string.Empty;
 1123:              * /
 1124: 
 1125:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
 1126:             {
 1127:                 phoneStatisticList = (from a in Ia.Ftn.Cl.Model.Data.Service.KuwaitFtnAreaList
 1128:                      group a by a.Id into grp
 1129:                      orderby grp.Key
 1130:                      select new Ia.Ftn.Cl.Model.Business.Administration.Statistic()
 1131:                      {
 1132:                          Id = grp.Key.ToString(),
 1133:                          Name = grp.SingleOrDefault().NameArabicName,
 1134:                          //ServiceRequests = (from sr in db.ServiceRequests where sr.AreaId == grp.Key && sr.ServiceRequestService != null select sr.Id).Count().ToString(),
 1135:                          ServiceRequestServices = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key select srs.Id).Count(),
 1136:                          Services = (from s in db.Service2s where s.ServiceType == Ia.Ftn.Cl.Model.Business.Service.ServiceType.ImsService && s.Access != null && s.Access.AreaId == grp.Key select s.Id).Count(),
 1137:                          InternationalCalling = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.InternationalCalling == true select srs.Id).Count(),
 1138:                          InternationalCallingUserControlled = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.InternationalCallingUserControlled == true select srs.Id).Count(),
 1139:                          CallWaiting = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallWaiting == true select srs.Id).Count(),
 1140: 
 1141:                          AlarmCall = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.AlarmCall == true select srs.Id).Count(),
 1142: 
 1143:                          CallBarring = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallBarring == true select srs.Id).Count(),
 1144:                          CallerId = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallerId == true select srs.Id).Count(),
 1145:                          CallForwarding = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.CallForwarding == true select srs.Id).Count(),
 1146:                          ConferenceCall = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.ConferenceCall == true select srs.Id).Count(),
 1147:                          ServiceSuspension = (from srs in db.ServiceRequestServices where srs.Access != null && srs.Access.AreaId == grp.Key && srs.ServiceSuspension == true select srs.Id).Count()
 1148:                      }).ToList();
 1149: 
 1150:                 /*
 1151:                 if (dt != null)
 1152:                 {
 1153:                     // below: the totals rows
 1154:                     dr = dt.NewRow();
 1155: 
 1156:                     dr["SRS_AccessIdNotNull"] = dt.Compute("SUM (SRS_AccessIdNotNull)", "").ToString();
 1157:                     dr["IMS_AccessIdNotNull"] = dt.Compute("SUM (IMS_AccessIdNotNull)", "").ToString();
 1158:                     dr["SRS_AccordingToAreaIdFromDomain"] = dt.Compute("SUM (SRS_AccordingToAreaIdFromDomain)", "").ToString();
 1159: 
 1160:                     dr["InternationalCalling"] = dt.Compute("SUM (InternationalCalling)", "").ToString();
 1161:                     dr["InternationalCallingUserControlled"] = dt.Compute("SUM (InternationalCallingUserControlled)", "").ToString();
 1162:                     dr["CallWaiting"] = dt.Compute("SUM (CallWaiting)", "").ToString();
 1163:                     dr["AlarmCall"] = dt.Compute("SUM (AlarmCall)", "").ToString();
 1164:                     dr["CallBarring"] = dt.Compute("SUM (CallBarring)", "").ToString();
 1165:                     dr["CallerId"] = dt.Compute("SUM (CallerId)", "").ToString();
 1166:                     dr["CallForwarding"] = dt.Compute("SUM (CallForwarding)", "").ToString();
 1167:                     dr["ConferenceCall"] = dt.Compute("SUM (ConferenceCall)", "").ToString();
 1168:                     dr["ServiceSuspension"] = dt.Compute("SUM (ServiceSuspension)", "").ToString();
 1169: 
 1170:                     dt.Rows.Add(dr);
 1171:                 }
 1172:                  * /
 1173:             }
 1174: 
 1175:             return phoneStatisticList;
 1176:         }
 1177:         */
 1178:  
 1179:         ////////////////////////////////////////////////////////////////////////////
 1180:  
 1181:         /// <summary>
 1182:         ///
 1183:         /// </summary>
 1184:         public static List<Ia.Ftn.Cl.Models.Ui.Performance> StaffAndFrameworkPerformanceReport(int daysAgo)
 1185:         {
 1186:             DateTime startDateTime;
 1187:             List<Ia.Ftn.Cl.Models.Ui.Performance> performanceList;
 1188:  
 1189:             // after 2015-06-01 user report closer inserts a last historic report
 1190:             // I should designate last report as CLOSED and add it to resolution list to be accessed by HEAD only.
 1191:  
 1192:             // if daysAgo is 0 will make it 9999 days to cover all times
 1193:             startDateTime = DateTime.UtcNow.AddDays(daysAgo == 0 ? -9999 : -daysAgo);
 1194:  
 1195:             using (var db = new Ia.Ftn.Cl.Db())
 1196:             {
 1197:                 var staffList = (from s in db.StaffIdentityUsers select s).ToList();
 1198:  
 1199:                 var resolvedList = (from r in db.ReportHistories
 1200:                                     where r.Resolution == 1020 && r.Created > startDateTime
 1201:                                     group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g
 1202:                                     select new { StaffIdentityUserId = g.Key, Count = g.Count() }).ToDictionary(u => u.StaffIdentityUserId, u => u.Count);
 1203:  
 1204:                 var attemptedList = (from r in db.ReportHistories where r.Resolution != 1020 && r.Created > startDateTime group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() }).ToDictionary(u => u.StaffIdentityUserId, u => u.Count);
 1205:  
 1206:                 var insertedList = (from r in db.Reports where r.Created > startDateTime group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() }).ToDictionary(u => u.StaffIdentityUserId, u => u.Count);
 1207:  
 1208:                 var openList = (from r in db.Reports where r.Created > startDateTime group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() }).ToDictionary(u => u.StaffIdentityUserId, u => u.Count);
 1209:  
 1210:  
 1211:                 var allowedToBeMigratedDomainList = Ia.Ftn.Cl.Models.Business.Service.AllowedToBeMigratedDomainList;
 1212:  
 1213:                 var serviceRequestServiceList = (from srs in db.ServiceRequestServices
 1214:                                                  where srs.Updated > startDateTime
 1215:                                                  select new { srs.Service, StaffIdentityUserId = srs.StaffIdentityUser.Id }).ToList();
 1216:  
 1217:                 var migratedList = (from srs in serviceRequestServiceList
 1218:                                     where allowedToBeMigratedDomainList.Any(u => srs.Service.StartsWith(u.ToString()))
 1219:                                     group srs.StaffIdentityUserId by srs.StaffIdentityUserId into g
 1220:                                     select new { StaffIdentityUserId = g.Key, Count = g.Count() }).ToDictionary(u => u.StaffIdentityUserId, u => u.Count);
 1221:  
 1222:  
 1223:                 performanceList = new List<Ia.Ftn.Cl.Models.Ui.Performance>();
 1224:  
 1225:                 foreach (var staff in staffList)
 1226:                 {
 1227:                     var p = new Ia.Ftn.Cl.Models.Ui.Performance
 1228:                     {
 1229:                         StaffIdentityUserId = staff.Id,
 1230:                         FirstAndMiddleName = staff.FirstAndMiddleName,
 1231:                         Resolved = (resolvedList.ContainsKey(staff.Id) ? resolvedList[staff.Id] : 0),
 1232:                         Attempted = (attemptedList.ContainsKey(staff.Id) ? attemptedList[staff.Id] : 0),
 1233:                         Inserted = (insertedList.ContainsKey(staff.Id) ? insertedList[staff.Id] : 0),
 1234:                         Open = (openList.ContainsKey(staff.Id) ? openList[staff.Id] : 0),
 1235:                         AverageReportsPerDay = 0,
 1236:                         Migrated = (migratedList.ContainsKey(staff.Id) ? migratedList[staff.Id] : 0),
 1237:                     };
 1238:  
 1239:                     performanceList.Add(p);
 1240:                 }
 1241:             }
 1242:  
 1243:             // below: exclude staff who did absolutly nothing: Resolved = Attempted = Inserted = 0
 1244:  
 1245:             performanceList = (from p in performanceList where (p.Inserted != 0 || p.Attempted != 0 || p.Resolved != 0) select p).ToList();
 1246:  
 1247:             foreach (var p in performanceList)
 1248:             {
 1249:                 if (string.IsNullOrEmpty(p.StaffIdentityUserId)) p.FirstAndMiddleName = "غير معرف";
 1250:                 else { }
 1251:             }
 1252:  
 1253:             return performanceList;
 1254:         }
 1255:  
 1256:         ////////////////////////////////////////////////////////////////////////////
 1257:  
 1258:         /// <summary>
 1259:         ///
 1260:         /// </summary>
 1261:         public static List<Ia.Ftn.Cl.Models.Ui.Performance> StatisticsOfResolvedAndAttemptedAndInsertedStaffReport2(string userId)
 1262:         {
 1263:             List<Ia.Ftn.Cl.Models.Ui.Performance> performanceList;
 1264:  
 1265:             // after 2015-06-01 user report closer inserts a last historic report
 1266:             // I should designate last report as CLOSED and add it to resolution list to be accessed by HEAD only.
 1267:  
 1268:             using (var db = new Ia.Ftn.Cl.Db())
 1269:             {
 1270:                 performanceList =
 1271:                     (
 1272:                     from staff in
 1273:                         (from s in db.StaffIdentityUsers group s.Id by s.Id into g select new { Id = g.Key, Count = g.Count() })
 1274:                     join resolved in
 1275:                         (from r in db.ReportHistories where r.Resolution == 1020 group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() })
 1276:                     on staff.Id equals resolved.StaffIdentityUserId into resolved_gj
 1277:                     from re in resolved_gj.DefaultIfEmpty()
 1278:  
 1279:                     join attempted in
 1280:                         (from r in db.ReportHistories where r.Resolution != 1020 group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() })
 1281:                     on staff.Id equals attempted.StaffIdentityUserId into attempted_gj
 1282:                     from at in attempted_gj.DefaultIfEmpty()
 1283:  
 1284:                     join inserted in
 1285:                         (from r in db.Reports group r.StaffIdentityUser.Id by r.StaffIdentityUser.Id into g select new { StaffIdentityUserId = g.Key, Count = g.Count() })
 1286:                     on staff.Id equals inserted.StaffIdentityUserId into inserted_gj
 1287:                     from ins in inserted_gj.DefaultIfEmpty()
 1288:                         // below: the 20, 10, 1 give weight to the field
 1289:                     orderby re.Count descending, at.Count descending, ins.Count descending
 1290:                     select new Ia.Ftn.Cl.Models.Ui.Performance
 1291:                     {
 1292:                         StaffIdentityUserId = staff.Id,
 1293:                         FirstAndMiddleName = (from s in Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List()
 1294:                                               where s.Id == staff.Id
 1295:                                               select s.FirstAndMiddleName).SingleOrDefault(),
 1296:                         Resolved = (re == null ? 0 : re.Count),
 1297:                         Attempted = (at == null ? 0 : at.Count),
 1298:                         Inserted = (ins == null ? 0 : ins.Count),
 1299:                         AverageReportsPerDay = 0
 1300:                     }).ToList();
 1301:  
 1302:                 /*
 1303:         select users.StaffIdentityUser.Id, resolved.count,attempted.count,inserted.count from
 1304:         (
 1305:         (select count(*) as count, UserId from Users group by UserId) as users
 1306:         left outer join
 1307:         (select count(*) as count, rh.StaffIdentityUser.Id from ReportHistories as rh where rh.Resolution = 1020 group by rh.StaffIdentityUser.Id) as resolved
 1308:         on users.StaffIdentityUser.Id = resolved.StaffIdentityUser.Id
 1309:         left outer join
 1310:         (select count(*) as count, rh.StaffIdentityUser.Id from ReportHistories as rh where rh.Resolution <> 1020 group by rh.StaffIdentityUser.Id) as attempted
 1311:         on users.StaffIdentityUser.Id = attempted.StaffIdentityUser.Id
 1312:         left outer join
 1313:         (select count(*) as count, UserId from Reports group by UserId) as inserted
 1314:         on users.StaffIdentityUser.Id = inserted.StaffIdentityUser.Id
 1315:         )
 1316:         order by resolved.count*20+attempted.count*10+inserted.count desc
 1317:             */
 1318:             }
 1319:  
 1320:             return performanceList.ToList();
 1321:         }
 1322:  
 1323:         ////////////////////////////////////////////////////////////////////////////    
 1324:  
 1325:         /// <summary>
 1326:         ///
 1327:         /// </summary>
 1328:         public static Dictionary<string, int> DateTimesWithAvailableData()
 1329:         {
 1330:             Dictionary<string, int> dic;
 1331:  
 1332:  
 1333:             dic = new Dictionary<string, int>(100);
 1334:  
 1335:  
 1336:             using (var db = new Ia.Ftn.Cl.Db())
 1337:             {
 1338:                 //dic = (from q in db.ServiceRequests orderby q.RequestDateTime select q.RequestDateTime).Distinct().ToDictionary(r => r.CustomerName, r => r.Id);
 1339:  
 1340:                 // dictionary = (from q in ReportXDocument.Elements("report").Elements("category") select new { Id = int.Parse(q.Attribute("id").Value), Name = q.Attribute("name").Value }).ToDictionary(r => r.Id, r => r.Name);
 1341:  
 1342:             }
 1343:  
 1344:             /*
 1345:         SELECT DISTINCT CONVERT(varchar(7), RequestDateTime, 102) AS date, COUNT(1) AS count
 1346:         FROM [Ia_Ftn].[dbo].[ServiceRequests]
 1347:         GROUP BY CONVERT(varchar(7), RequestDateTime, 102)
 1348:         ORDER BY date
 1349:              */
 1350:  
 1351:             return dic;
 1352:         }
 1353:  
 1354:         ////////////////////////////////////////////////////////////////////////////    
 1355:  
 1356:         /// <summary>
 1357:         ///
 1358:         /// </summary>
 1359:         public static void CreateFrameworkIdentityRolesIfTheyDoNotExist(RoleManager<IdentityRole> roleManager)
 1360:         {
 1361:             IdentityResult identityResult;
 1362:  
 1363:             foreach (var framework in Ia.Ftn.Cl.Models.Data.Administration.FrameworkList)
 1364:             {
 1365:                 if (!roleManager.RoleExistsAsync(framework.FullyQualifiedArabicName).Result)
 1366:                 {
 1367:                     identityResult = roleManager.CreateAsync(new IdentityRole(framework.FullyQualifiedArabicName)).Result;
 1368:                 }
 1369:  
 1370:                 // create IsHead and IsSecretary role if they did not exists
 1371:                 if (!Ia.Ftn.Cl.Models.Identity.RoleExists(roleManager, "IsHead")) Ia.Ftn.Cl.Models.Identity.CreateRole(roleManager, "IsHead");
 1372:                 if (!Ia.Ftn.Cl.Models.Identity.RoleExists(roleManager, "IsSecretary")) Ia.Ftn.Cl.Models.Identity.CreateRole(roleManager, "IsSecretary");
 1373:             }
 1374:         }
 1375:  
 1376:         ////////////////////////////////////////////////////////////////////////////    
 1377:  
 1378:         /// <summary>
 1379:         ///
 1380:         /// </summary>
 1381:         public static void CreateApplicationUserAndStaffIfDoesNotExist(RoleManager<IdentityRole> roleManager, UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager)
 1382:         {
 1383:             var staffIdentityUser = Ia.Ftn.Cl.Models.Data.StaffIdentityUser.CreateApplicationStaff(userManager, roleManager,
 1384:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationArabicFirstName,
 1385:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationArabicMiddleName,
 1386:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationArabicLastName,
 1387:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationUserEmail,
 1388:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationUserName,
 1389:                 string.Empty,
 1390:                 Ia.Ftn.Cl.Models.Data.Administration.ApplicationUserPassword,
 1391:                 out IdentityResult identityResult);
 1392:  
 1393:             if (identityResult.Succeeded)
 1394:             {
 1395:                 Ia.Ftn.Cl.Models.Business.Authority.UpdateFrameworkRolesOfStaffIdentityUser(userManager, roleManager, staffIdentityUser);
 1396:             }
 1397:             else
 1398:             {
 1399:             }
 1400:         }
 1401:  
 1402:         ////////////////////////////////////////////////////////////////////////////
 1403:         ////////////////////////////////////////////////////////////////////////////
 1404:  
 1405:         /// <summary>
 1406:         /// 
 1407:         /// How to embed and access resources by using Visual C# http://support.microsoft.com/kb/319292/en-us
 1408:         /// 
 1409:         /// 1. Change the "Build Action" property of your XML file from "Content" to "Embedded Resource".
 1410:         /// 2. Add "using System.Reflection".
 1411:         /// 3. Manifest resource stream will start with the project namespace, the location of XML file.
 1412:         /// 
 1413:         /// </summary>
 1414:  
 1415:         private static XDocument XDocument
 1416:         {
 1417:             get
 1418:             {
 1419:                 if (xDocument == null)
 1420:                 {
 1421:                     lock (objectLock)
 1422:                     {
 1423:                         Assembly assembly;
 1424:                         StreamReader streamReader;
 1425:  
 1426:                         assembly = Assembly.GetExecutingAssembly();
 1427:                         streamReader = new StreamReader(assembly.GetManifestResourceStream("Ia.Ftn.Cl.Models.Data.administration.xml"));
 1428:  
 1429:                         try
 1430:                         {
 1431:                             if (streamReader.Peek() != -1) xDocument = System.Xml.Linq.XDocument.Load(streamReader);
 1432:                         }
 1433:                         catch (Exception)
 1434:                         {
 1435:                         }
 1436:                         finally
 1437:                         {
 1438:                         }
 1439:                     }
 1440:                 }
 1441:  
 1442:                 return xDocument;
 1443:             }
 1444:         }
 1445:  
 1446:         ////////////////////////////////////////////////////////////////////////////
 1447:         ////////////////////////////////////////////////////////////////////////////    
 1448:     }
 1449:  
 1450:     ////////////////////////////////////////////////////////////////////////////
 1451:     ////////////////////////////////////////////////////////////////////////////   
 1452: }