شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Access

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

Access support class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Linq;
   5:  using System.Data.Entity;
   6:  using System.Text;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Access support class for Next Generation Network (NGN) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class Access
  30:      {
  31:          /// <summary/>
  32:          public Access() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static void Create(Ia.Ngn.Cl.Model.Access newAccess, out Ia.Cl.Model.Result result)
  40:          {
  41:              Ia.Ngn.Cl.Model.Access access;
  42:   
  43:              result = new Ia.Cl.Model.Result();
  44:   
  45:              try
  46:              {
  47:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  48:                  {
  49:                      // check if it exists already
  50:                      access = (from a in db.Accesses where a.Id == newAccess.Id select a).SingleOrDefault();
  51:   
  52:                      if (access == null)
  53:                      {
  54:                          newAccess.Created = newAccess.Updated = DateTime.UtcNow.AddHours(3);
  55:   
  56:                          db.Accesses.Add(newAccess);
  57:                          db.SaveChanges();
  58:   
  59:                          result.AddSuccess("Access record " + newAccess.Name + " created. ");
  60:                      }
  61:                      else
  62:                      {
  63:                          result.AddError("Access record " + newAccess.Name + " already exists. ");
  64:                      }
  65:                  }
  66:              }
  67:              catch (Exception ex)
  68:              {
  69:                  result.AddError("Exception: Access record was not created: " + ex.Message);
  70:              }
  71:          }
  72:   
  73:          ////////////////////////////////////////////////////////////////////////////
  74:   
  75:          /// <summary>
  76:          ///
  77:          /// </summary>
  78:          public static Ia.Ngn.Cl.Model.Access Read(Ia.Ngn.Cl.Model.Ngn db, string id)
  79:          {
  80:              Ia.Ngn.Cl.Model.Access access;
  81:   
  82:              access = (from a in db.Accesses where a.Id == id select a).SingleOrDefault();
  83:   
  84:              return access;
  85:          }
  86:   
  87:          ////////////////////////////////////////////////////////////////////////////
  88:   
  89:          /// <summary>
  90:          ///
  91:          /// </summary>
  92:          public static Ia.Ngn.Cl.Model.Access Read(string id)
  93:          {
  94:              Ia.Ngn.Cl.Model.Access item;
  95:   
  96:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  97:              {
  98:                  item = (from a in db.Accesses where a.Id == id select a).SingleOrDefault();
  99:              }
 100:   
 101:              return item;
 102:          }
 103:   
 104:          ////////////////////////////////////////////////////////////////////////////
 105:   
 106:          /// <summary>
 107:          ///
 108:          /// </summary>
 109:          public static Ia.Ngn.Cl.Model.Access Read(int oltId, int ponNumber, int ontNumber)
 110:          {
 111:              Ia.Ngn.Cl.Model.Access item;
 112:   
 113:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 114:              {
 115:                  item = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber && a.Ont == ontNumber select a).SingleOrDefault();
 116:              }
 117:   
 118:              return item;
 119:          }
 120:   
 121:          ////////////////////////////////////////////////////////////////////////////
 122:   
 123:          /// <summary>
 124:          ///
 125:          /// </summary>
 126:          public static Ia.Ngn.Cl.Model.Access Read(Ia.Ngn.Cl.Model.Ngn db, int oltId, int ponNumber, int ontNumber)
 127:          {
 128:              return (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber && a.Ont == ontNumber select a).SingleOrDefault();
 129:          }
 130:   
 131:          ////////////////////////////////////////////////////////////////////////////
 132:   
 133:          /// <summary>
 134:          ///
 135:          /// </summary>
 136:          public static List<Ia.Ngn.Cl.Model.Access> List()
 137:          {
 138:              List<Ia.Ngn.Cl.Model.Access> list;
 139:   
 140:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 141:              {
 142:                  list = (from a in db.Accesses select a).ToList();
 143:              }
 144:   
 145:              return list;
 146:          }
 147:   
 148:          ////////////////////////////////////////////////////////////////////////////
 149:   
 150:          /// <summary>
 151:          ///
 152:          /// </summary>
 153:          public static Ia.Ngn.Cl.Model.Access BySerialInNote(string serial)
 154:          {
 155:              List<Ia.Ngn.Cl.Model.Access> list;
 156:   
 157:              if (!string.IsNullOrEmpty(serial))
 158:              {
 159:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 160:                  {
 161:                      list = (from a in db.Accesses where a.Note.Contains(serial) select a).ToList();
 162:                  }
 163:              }
 164:              else list = null;
 165:   
 166:              return list.FirstOrDefault();
 167:          }
 168:   
 169:          ////////////////////////////////////////////////////////////////////////////
 170:   
 171:          /// <summary>
 172:          ///
 173:          /// </summary>
 174:          public static List<Ia.Ngn.Cl.Model.Access> ReadListOfAreaId(int areaId)
 175:          {
 176:              List<Ia.Ngn.Cl.Model.Access> itemList;
 177:   
 178:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 179:              {
 180:                  itemList = (from a in db.Accesses where a.AreaId == areaId select a).ToList();
 181:              }
 182:   
 183:              return itemList;
 184:          }
 185:   
 186:          ////////////////////////////////////////////////////////////////////////////
 187:   
 188:          /// <summary>
 189:          ///
 190:          /// </summary>
 191:          public static int AreaIdFromOltIdAndPon(int oltId, int ponNumber)
 192:          {
 193:              int areaId;
 194:   
 195:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 196:              {
 197:                  areaId = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber select a.AreaId).FirstOrDefault();
 198:   
 199:                  if (areaId == 0)
 200:                  {
 201:                      areaId = (from a in db.Accesses where a.Olt == oltId select a.AreaId).FirstOrDefault();
 202:                  }
 203:              }
 204:   
 205:              return areaId;
 206:          }
 207:   
 208:          ////////////////////////////////////////////////////////////////////////////
 209:   
 210:          /// <summary>
 211:          ///
 212:          /// </summary>
 213:          public static List<Ia.Ngn.Cl.Model.Access> List(int oltId, int ponNumber)
 214:          {
 215:              List<Ia.Ngn.Cl.Model.Access> itemList;
 216:   
 217:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 218:              {
 219:                  itemList = (from a in db.Accesses where a.Olt == oltId && a.Pon == ponNumber select a).ToList();
 220:              }
 221:   
 222:              return itemList;
 223:          }
 224:   
 225:          ////////////////////////////////////////////////////////////////////////////
 226:   
 227:          /// <summary>
 228:          ///
 229:          /// </summary>
 230:          public static bool Update(Ia.Ngn.Cl.Model.Access updatedAccess, out string result)
 231:          {
 232:              bool b;
 233:              Ia.Ngn.Cl.Model.Access access;
 234:   
 235:              b = false;
 236:              result = "";
 237:   
 238:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 239:              {
 240:                  access = (from a in db.Accesses where a.Id == updatedAccess.Id select a).SingleOrDefault();
 241:   
 242:                  if (access.Update(updatedAccess))
 243:                  {
 244:                      db.Accesses.Attach(access);
 245:                      db.Entry(access).State = System.Data.Entity.EntityState.Modified;
 246:                  }
 247:   
 248:                  db.SaveChanges();
 249:   
 250:                  b = true;
 251:              }
 252:   
 253:              return b;
 254:          }
 255:   
 256:          ////////////////////////////////////////////////////////////////////////////
 257:   
 258:          /// <summary>
 259:          ///
 260:          /// </summary>
 261:          public static void Delete(string id, out Ia.Cl.Model.Result result)
 262:          {
 263:              result = new Ia.Cl.Model.Result();
 264:   
 265:              try
 266:              {
 267:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 268:                  {
 269:                      var v = (from a in db.Accesses where a.Id == id select a).FirstOrDefault();
 270:   
 271:                      if (v != null)
 272:                      {
 273:                          db.Accesses.Remove(v);
 274:                          db.SaveChanges();
 275:   
 276:                          result.AddSuccess("Access record deleted. ");
 277:                      }
 278:                      else
 279:                      {
 280:                          result.AddWarning("Access record does not exist. ");
 281:                      }
 282:   
 283:                  }
 284:              }
 285:              catch (Exception ex)
 286:              {
 287:                  result.AddError("Exception: Access record was not deleted: " + ex.Message);
 288:              }
 289:          }
 290:   
 291:          ////////////////////////////////////////////////////////////////////////////
 292:          ////////////////////////////////////////////////////////////////////////////
 293:   
 294:          /// <summary>
 295:          ///
 296:          /// </summary>
 297:          public static List<int> OntsNotInAccessList(List<Ia.Ngn.Cl.Model.Access> accessList)
 298:          {
 299:              // below: produce a list of ONTs between 1 and 32 that are not in ontList
 300:              List<int> ontNotInListArrayList = new List<int>(32);
 301:   
 302:              for (int i = 1; i <= 32; i++)
 303:              {
 304:                  if (accessList != null)
 305:                  {
 306:                      if ((from a in accessList where a.Ont == i select a).SingleOrDefault() == null)
 307:                      {
 308:                          ontNotInListArrayList.Add(i);
 309:                      }
 310:                      else
 311:                      {
 312:                      }
 313:                  }
 314:                  else
 315:                  {
 316:                      ontNotInListArrayList.Add(i);
 317:                  }
 318:              }
 319:   
 320:              return ontNotInListArrayList;
 321:          }
 322:   
 323:          ////////////////////////////////////////////////////////////////////////////
 324:   
 325:          /// <summary>
 326:          ///
 327:          /// </summary>
 328:          public static List<int> OltIdDistinctList
 329:          {
 330:              get
 331:              {
 332:                  List<int> list;
 333:   
 334:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 335:                  {
 336:                      list = (from o in db.Accesses select o.Olt).Distinct().OrderBy(u => u).ToList();
 337:                  }
 338:   
 339:                  return list;
 340:              }
 341:          }
 342:   
 343:          ////////////////////////////////////////////////////////////////////////////
 344:   
 345:          /// <summary>
 346:          ///
 347:          /// </summary>
 348:          public static Ia.Ngn.Cl.Model.Access ReadByAccessName(string accessName)
 349:          {
 350:              int oltId, pon, ont;
 351:              Ia.Ngn.Cl.Model.Access access;
 352:   
 353:              // below: this expects accessName in exact format like SUR.12.3
 354:   
 355:              Ia.Ngn.Cl.Model.Business.Access.ExtractOltIdAndPonNumberAndOntNumberFromOntName(accessName, out oltId, out pon, out ont);
 356:   
 357:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 358:              {
 359:                  access = (from a in db.Accesses where a.Olt == oltId && a.Pon == pon && a.Ont == ont select a).SingleOrDefault();
 360:              }
 361:   
 362:              return access;
 363:          }
 364:   
 365:          ////////////////////////////////////////////////////////////////////////////
 366:   
 367:          /// <summary>
 368:          ///
 369:          /// </summary>
 370:          public static List<Ia.Ngn.Cl.Model.Access> ListUsingOntFamilyType(int familyTypeId)
 371:          {
 372:              // below: return access list for family type
 373:              List<Ia.Ngn.Cl.Model.Access> noList, huList, list;
 374:              List<string> equipmentTypeStringList;
 375:   
 376:              list = new List<Ia.Ngn.Cl.Model.Access>();
 377:   
 378:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 379:              {
 380:                  noList = (from a in db.Accesses join o in db.Onts on a equals o.Access where o.FamilyTypeId == familyTypeId select a).ToList();
 381:   
 382:                  equipmentTypeStringList = Ia.Ngn.Cl.Model.Business.Huawei.Ont.EquipmentTypeStringListFromFamilyType((Ia.Ngn.Cl.Model.Business.Huawei.Ont.FamilyType)familyTypeId);
 383:   
 384:                  huList = (from a in db.Accesses join o in db.EmsOnts on a equals o.Access where equipmentTypeStringList.Contains(o.EQUIPMENTID) select a).ToList();
 385:              }
 386:   
 387:              list.AddRange(noList);
 388:              list.AddRange(huList);
 389:   
 390:              return list.ToList();
 391:          }
 392:   
 393:          ////////////////////////////////////////////////////////////////////////////
 394:   
 395:          /// <summary>
 396:          ///
 397:          /// </summary>
 398:          public static List<string> ReadAccessNameListUsingKuwaitNgnAreaIdAndBlock(int kuwaitAreaId, string block)
 399:          {
 400:              Dictionary<string, string> di;
 401:              List<string> accessIdList, accessNameList;
 402:   
 403:              if (kuwaitAreaId > 0 && !string.IsNullOrEmpty(block))
 404:              {
 405:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 406:                  {
 407:                      accessIdList = (from a in db.Accesses where a.AreaId == kuwaitAreaId && a.Block == block select a.Id).ToList();
 408:                      di = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
 409:   
 410:                      if (accessIdList != null && accessIdList.Count > 0)
 411:                      {
 412:                          accessNameList = new List<string>(accessIdList.Count);
 413:   
 414:                          foreach (string accessId in accessIdList)
 415:                          {
 416:                              if (di.ContainsKey(accessId)) accessNameList.Add(di[accessId]);
 417:                          }
 418:                      }
 419:                      else
 420:                      {
 421:                          accessNameList = null;
 422:                      }
 423:                  }
 424:              }
 425:              else
 426:              {
 427:                  accessNameList = null;
 428:              }
 429:   
 430:              return accessNameList;
 431:          }
 432:   
 433:          ////////////////////////////////////////////////////////////////////////////
 434:   
 435:          /// <summary>
 436:          ///
 437:          /// </summary>
 438:          public static List<Ia.Ngn.Cl.Model.Access> ListByKuwaitNgnAreaId(int kuwaitAreaId)
 439:          {
 440:              List<Ia.Ngn.Cl.Model.Access> list;
 441:   
 442:              if (kuwaitAreaId > 0)
 443:              {
 444:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 445:                  {
 446:                      list = (from a in db.Accesses where a.AreaId == kuwaitAreaId select a).ToList();
 447:                  }
 448:              }
 449:              else
 450:              {
 451:                  list = null;
 452:              }
 453:   
 454:              return list;
 455:          }
 456:   
 457:          ////////////////////////////////////////////////////////////////////////////
 458:   
 459:          /// <summary>
 460:          ///
 461:          /// </summary>
 462:          public static Dictionary<string, string> DistinctAccessKuwaitNgnAreaIdAndBlockDictionary
 463:          {
 464:              get
 465:              {
 466:                  int kuwaitNgnAreaId, block;
 467:                  string kuwaitNgnAreaIdString, blockString, kuwaitNgnAreaBlockValue, kuwaitNgnAreaNameArabicName;
 468:                  Dictionary<string, string> tempDictionary;
 469:                  Dictionary<string, string> dictionary;
 470:   
 471:                  dictionary = new Dictionary<string, string>();
 472:                  tempDictionary = new Dictionary<string, string>();
 473:   
 474:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 475:                  {
 476:                      tempDictionary = (from a in db.Accesses select new { a.AreaId, a.Block }).Distinct().OrderBy(u => u.AreaId).ThenBy(u => u.Block).ToDictionary(m => m.AreaId + "," + m.Block, m => m.AreaId + "," + m.Block);
 477:   
 478:                      if (tempDictionary != null && tempDictionary.Count > 0)
 479:                      {
 480:                          foreach (KeyValuePair<string, string> kvp in tempDictionary)
 481:                          {
 482:                              kuwaitNgnAreaIdString = kvp.Key.Split(',')[0].ToString();
 483:                              blockString = kvp.Key.Split(',')[1].ToString();
 484:   
 485:                              if (int.TryParse(kuwaitNgnAreaIdString, out kuwaitNgnAreaId) && int.TryParse(blockString, out block))
 486:                              {
 487:                                  kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == kuwaitNgnAreaId select kna.NameArabicName).SingleOrDefault();
 488:   
 489:                                  kuwaitNgnAreaBlockValue = kuwaitNgnAreaNameArabicName + ", block " + block;
 490:   
 491:                                  dictionary.Add(kvp.Key, kuwaitNgnAreaBlockValue);
 492:                              }
 493:                              else
 494:                              {
 495:                              }
 496:                          }
 497:                      }
 498:                      else
 499:                      {
 500:                      }
 501:                  }
 502:   
 503:                  return dictionary;
 504:              }
 505:          }
 506:   
 507:          ////////////////////////////////////////////////////////////////////////////
 508:   
 509:          /// <summary>
 510:          ///
 511:          /// </summary>
 512:          public static Dictionary<int, string> DistinctAccessKuwaitNgnAreaIdToNameArabicNameDictionary
 513:          {
 514:              get
 515:              {
 516:                  string kuwaitNgnAreaNameArabicName;
 517:                  List<int> list;
 518:                  Dictionary<int, string> dictionary;
 519:   
 520:                  dictionary = new Dictionary<int, string>();
 521:                  list = new List<int>();
 522:   
 523:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 524:                  {
 525:                      list = (from a in db.Accesses select a.AreaId).Distinct().ToList();
 526:   
 527:                      if (list.Count > 0)
 528:                      {
 529:                          foreach (int i in list)
 530:                          {
 531:                              kuwaitNgnAreaNameArabicName = (from kna in Ia.Ngn.Cl.Model.Data.Service.KuwaitNgnAreaList where kna.Id == i select kna.NameArabicName).SingleOrDefault();
 532:   
 533:                              dictionary.Add(i, kuwaitNgnAreaNameArabicName);
 534:                          }
 535:                      }
 536:                      else
 537:                      {
 538:                      }
 539:                  }
 540:   
 541:                  return dictionary;
 542:              }
 543:          }
 544:   
 545:          ////////////////////////////////////////////////////////////////////////////
 546:   
 547:          /// <summary>
 548:          ///
 549:          /// </summary>
 550:          public static Dictionary<string, int> IdToKuwaitNgnAreaIdDictionary
 551:          {
 552:              get
 553:              {
 554:                  Dictionary<string, int> dictionary;
 555:   
 556:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 557:                  {
 558:                      dictionary = (from a in db.Accesses select new { a.Id, a.AreaId }).ToDictionary(u => u.Id, u => u.AreaId);
 559:                  }
 560:   
 561:                  return dictionary;
 562:              }
 563:          }
 564:   
 565:          ////////////////////////////////////////////////////////////////////////////
 566:   
 567:          /// <summary>
 568:          ///
 569:          /// </summary>
 570:          public static Dictionary<string, string> IdToKuwaitNgnAreaSymbolDictionary
 571:          {
 572:              get
 573:              {
 574:                  Dictionary<string, int> accessIdToKuwaitNgnAreaIdDictionary;
 575:                  Dictionary<int, string> areaIdToSymbolDictionary;
 576:                  Dictionary<string, string> dictionary;
 577:   
 578:                  accessIdToKuwaitNgnAreaIdDictionary = Ia.Ngn.Cl.Model.Data.Access.IdToKuwaitNgnAreaIdDictionary;
 579:                  areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 580:   
 581:                  dictionary = new Dictionary<string, string>(accessIdToKuwaitNgnAreaIdDictionary.Count);
 582:   
 583:                  foreach (KeyValuePair<string, int> kvp in accessIdToKuwaitNgnAreaIdDictionary)
 584:                  {
 585:                      if (areaIdToSymbolDictionary.ContainsKey(kvp.Value)) dictionary[kvp.Key] = areaIdToSymbolDictionary[kvp.Value];
 586:                  }
 587:   
 588:                  return dictionary;
 589:              }
 590:          }
 591:   
 592:          ////////////////////////////////////////////////////////////////////////////
 593:   
 594:          /// <summary>
 595:          ///
 596:          /// </summary>
 597:          public static Dictionary<string, int> IdToOltIdDictionary
 598:          {
 599:              get
 600:              {
 601:                  Dictionary<string, int> dictionary;
 602:   
 603:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 604:                  {
 605:                      dictionary = (from a in db.Accesses select new { a.Id, a.Olt }).ToDictionary(u => u.Id, u => u.Olt);
 606:                  }
 607:   
 608:                  return dictionary;
 609:              }
 610:          }
 611:   
 612:          ////////////////////////////////////////////////////////////////////////////
 613:   
 614:          /// <summary>
 615:          ///
 616:          /// </summary>
 617:          public static Dictionary<string, Ia.Ngn.Cl.Model.Access> IdToAccessDictionary
 618:          {
 619:              get
 620:              {
 621:                  Dictionary<string, Ia.Ngn.Cl.Model.Access> dictionary;
 622:   
 623:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 624:                  {
 625:                      dictionary = (from a in db.Accesses select new { AccessId = a.Id, Access = a }).ToDictionary(u => u.AccessId, u => u.Access);
 626:                  }
 627:   
 628:                  return dictionary;
 629:              }
 630:          }
 631:   
 632:          ////////////////////////////////////////////////////////////////////////////
 633:   
 634:          /// <summary>
 635:          ///
 636:          /// </summary>
 637:          public static List<string> IdList
 638:          {
 639:              get
 640:              {
 641:                  List<string> list;
 642:   
 643:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 644:                  {
 645:                      list = (from a in db.Accesses select a.Id).ToList();
 646:                  }
 647:   
 648:                  return list;
 649:              }
 650:          }
 651:   
 652:          ////////////////////////////////////////////////////////////////////////////
 653:   
 654:          /// <summary>
 655:          ///
 656:          /// </summary>
 657:          public static List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> FamilyStatisticInKuwaitNgnAreaAndBlockTable
 658:          {
 659:              // FamilyType { Undefined = 0, Sfu = 1, Soho = 2, Mdu = 3 };
 660:   
 661:              get
 662:              {
 663:                  Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock item;
 664:                  List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock> list, sfu, soho, mdu;
 665:   
 666:                  list = new List<Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock>();
 667:   
 668:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 669:                  {
 670:                      sfu = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 1 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Sfu = g.Count() }).ToList();
 671:                      soho = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 2 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Soho = g.Count() }).ToList();
 672:                      mdu = (from a in db.Accesses join o in db.Onts on a.Id equals o.Access.Id where o.FamilyTypeId == 3 group a by new { a.AreaId, a.Block } into g select new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock() { AreaId = g.Key.AreaId, Block = g.Key.Block, Mdu = g.Count() }).ToList();
 673:   
 674:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in sfu) list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Sfu = a.Sfu });
 675:   
 676:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in soho)
 677:                      {
 678:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 679:   
 680:                          if (item != null) item.Soho = a.Soho;
 681:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Soho = a.Soho });
 682:                      }
 683:   
 684:                      foreach (Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock a in mdu)
 685:                      {
 686:                          item = (from b in list where b.AreaId == a.AreaId && b.Block == a.Block select b).SingleOrDefault();
 687:   
 688:                          if (item != null) item.Mdu = a.Mdu;
 689:                          else list.Add(new Ia.Ngn.Cl.Model.Ui.Maintenance.AccessFamilyTypeAreaBlock { AreaId = a.AreaId, Block = a.Block, Mdu = a.Mdu });
 690:                      }
 691:   
 692:                      list = list.OrderBy(u => u.AreaId).ThenBy(u => u.Block).ToList();
 693:   
 694:                      return list;
 695:                  }
 696:              }
 697:          }
 698:   
 699:          ////////////////////////////////////////////////////////////////////////////
 700:   
 701:          /// <summary>
 702:          ///
 703:          /// </summary>
 704:          public static List<Ia.Ngn.Cl.Model.Access> ListOfAccessesWithProvisionedAndReadyOntsAndEmsOntsButDoNotExistInCustomerDepartmentDatabase()
 705:          {
 706:              return ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(0);
 707:          }
 708:   
 709:          ////////////////////////////////////////////////////////////////////////////
 710:   
 711:          /// <summary>
 712:          ///
 713:          /// </summary>
 714:          public static List<Ia.Ngn.Cl.Model.Access> ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId(int siteId)
 715:          {
 716:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Site site;
 717:              List<int> nokiaOltIdList, huaweiOltIdList;
 718:              List<Ia.Ngn.Cl.Model.Access> list, nokiaList, huaweiOntList;
 719:   
 720:              // this is related to AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 721:   
 722:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 723:              {
 724:                  if (siteId == 0)
 725:                  {
 726:                      // if siteId is 0 we will return results for all sites
 727:   
 728:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 729:   
 730:                      // Nokia
 731:                      nokiaList = (from a in db.Accesses
 732:                                       //join oid in nokiaOltIdList on a.Olt equals oid
 733:                                   join o in db.Onts on a equals o.Access
 734:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 735:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 736:                                   from subsro in gj.DefaultIfEmpty()
 737:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 738:                                   && o.Serial != null
 739:                                   && o.Serial != "ALCL00000000"
 740:                                   && o.FamilyTypeId != 0
 741:                                   && o.ActiveSoftware != null
 742:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 743:                                   && osv.Ip != null
 744:                                   && subsro.Access.Id == null
 745:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 746:   
 747:                      // Huawei
 748:   
 749:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 750:   
 751:                      huaweiOntList = (from a in db.Accesses
 752:                                       join o in db.EmsOnts on a equals o.Access
 753:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 754:                                       from subsro in gj.DefaultIfEmpty()
 755:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 756:                                       && huaweiOltIdList.Contains(a.Olt)
 757:                                       && subsro.Access.Id == null
 758:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 759:   
 760:                      list = nokiaList.Union(huaweiOntList).ToList();
 761:                  }
 762:                  else
 763:                  {
 764:                      site = (from a in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where a.Id == siteId select a).SingleOrDefault();
 765:   
 766:                      nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList(siteId);
 767:   
 768:                      // Nokia
 769:                      nokiaList = (from a in db.Accesses
 770:                                   join oid in nokiaOltIdList on a.Olt equals oid
 771:                                   join o in db.Onts on a equals o.Access
 772:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 773:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 774:                                   from subsro in gj.DefaultIfEmpty()
 775:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 776:                                   && o.Serial != null
 777:                                   && o.Serial != "ALCL00000000"
 778:                                   && o.FamilyTypeId != 0
 779:                                   && o.ActiveSoftware != null
 780:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 781:                                   && osv.Ip != null
 782:                                   && subsro.Access.Id == null
 783:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 784:   
 785:                      // Huawei
 786:   
 787:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList(siteId);
 788:   
 789:                      huaweiOntList = (from a in db.Accesses
 790:                                       join o in db.EmsOnts on a equals o.Access
 791:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 792:                                       from subsro in gj.DefaultIfEmpty()
 793:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 794:                                       && huaweiOltIdList.Contains(a.Olt)
 795:                                       && subsro.Access.Id == null
 796:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 797:   
 798:                      list = nokiaList.Union(huaweiOntList).ToList();
 799:                  }
 800:              }
 801:   
 802:              return list.OrderBy(u => u.Id).ToList();
 803:          }
 804:   
 805:          ////////////////////////////////////////////////////////////////////////////
 806:   
 807:          /// <summary>
 808:          ///
 809:          /// </summary>
 810:          public static List<Ia.Ngn.Cl.Model.Access> AccessesWithMismatchedInfomationInServiceRequestOntList()
 811:          {
 812:              List<Ia.Ngn.Cl.Model.Access> list;
 813:              //Dictionary<int, string> areaIdToSymbolDictionary;
 814:   
 815:              //areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 816:   
 817:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 818:              {
 819:                  // I will ignore area because its fixed with access id, which is shared by both Access and ServiceRequestOnt
 820:   
 821:                  list = (from a in db.Accesses
 822:                          join o in db.Onts on a equals o.Access
 823:                          join osv in db.OntServiceVoips on o equals osv.Ont
 824:                          join sro in db.ServiceRequestOnts on a equals sro.Access
 825:                          //join areaSymbol in areaIdToSymbolDictionary on a.AreaId equals areaSymbol.Key
 826:                          //where sro.AreaSymbol != areaSymbol.Value
 827:                          where (sro.Block != a.Block && !string.IsNullOrEmpty(a.Block))
 828:                          || (sro.Street != a.Street && !string.IsNullOrEmpty(a.Street))
 829:                          || (sro.PremisesOld != a.PremisesOld && !string.IsNullOrEmpty(a.PremisesOld))
 830:                          || (sro.PremisesNew != a.PremisesNew && !string.IsNullOrEmpty(a.PremisesNew))
 831:                          || (sro.Paci != a.Paci && !string.IsNullOrEmpty(a.Paci))
 832:                          //|| (sro.PossibleNumberOfTd != a.PossibleNumberOfTd)
 833:                          //|| (sro.PossibleNumberOfEthernet != a.PossibleNumberOfEthernet)
 834:                          select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 835:              }
 836:   
 837:              return list.OrderBy(u => u.Id).ToList();
 838:          }
 839:   
 840:          ////////////////////////////////////////////////////////////////////////////
 841:   
 842:          /// <summary>
 843:          ///
 844:          /// </summary>
 845:          public static Dictionary<string, int> AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 846:          {
 847:              get
 848:              {
 849:                  Dictionary<string, int> dictionary, nokiaDictionary, huaweiDictionary;
 850:                  List<int> nokiaOltIdList, huaweiOltIdList;
 851:   
 852:                  // this is related to ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId()
 853:   
 854:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 855:                  {
 856:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 857:   
 858:                      // Nokia
 859:                      nokiaDictionary = (from a in db.Accesses
 860:                                         join o in db.Onts on a equals o.Access
 861:                                         join osv in db.OntServiceVoips on o equals osv.Ont
 862:                                         join sro in db.ServiceRequestOnts on a equals sro.Access
 863:                                         where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr // ?
 864:                                         && o.Serial != null
 865:                                         && o.Serial != "ALCL00000000"
 866:                                         && o.FamilyTypeId != 0 // ?
 867:                                         && o.ActiveSoftware != null
 868:                                         //&& o.ActiveSoftware == o.PlannedSoftware
 869:                                         && osv.Ip != null
 870:                                         select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 871:   
 872:                      // Huawei
 873:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 874:   
 875:                      huaweiDictionary = (from a in db.Accesses
 876:                                          join o in db.EmsOnts on a equals o.Access
 877:                                          join sro in db.ServiceRequestOnts on a equals sro.Access
 878:                                          //where o.FamilyTypeId != 0
 879:                                          where o.EQUIPMENTID != "--"
 880:                                          && huaweiOltIdList.Contains(a.Olt)
 881:                                          select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 882:   
 883:                      dictionary = nokiaDictionary.Union(huaweiDictionary).ToDictionary(k => k.Key, v => v.Value);
 884:                  }
 885:   
 886:                  return dictionary;
 887:              }
 888:          }
 889:   
 890:          ////////////////////////////////////////////////////////////////////////////
 891:   
 892:          /// <summary>
 893:          ///
 894:          /// </summary>
 895:          public static List<Ia.Ngn.Cl.Model.Access> NokiaAccessList
 896:          {
 897:              get
 898:              {
 899:                  List<int> oltIdList;
 900:                  List<Ia.Ngn.Cl.Model.Access> list;
 901:   
 902:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 903:   
 904:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 905:                  {
 906:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 907:                  }
 908:   
 909:                  return list;
 910:              }
 911:          }
 912:   
 913:          ////////////////////////////////////////////////////////////////////////////
 914:   
 915:          /// <summary>
 916:          ///
 917:          /// </summary>
 918:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessList
 919:          {
 920:              get
 921:              {
 922:                  List<int> oltIdList;
 923:                  List<Ia.Ngn.Cl.Model.Access> list;
 924:   
 925:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 926:   
 927:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 928:                  {
 929:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 930:                  }
 931:   
 932:                  return list;
 933:              }
 934:          }
 935:   
 936:          ////////////////////////////////////////////////////////////////////////////
 937:   
 938:          /// <summary>
 939:          ///
 940:          /// </summary>
 941:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessesWithNoEmsOntList
 942:          {
 943:              get
 944:              {
 945:                  List<int> huaweiOltIdList;
 946:                  List<Ia.Ngn.Cl.Model.Access> list;
 947:   
 948:                  huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 949:   
 950:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 951:                  {
 952:                      list = (from a in db.Accesses
 953:                              join o in db.EmsOnts on a equals o.Access into gj
 954:                              from subsro in gj.DefaultIfEmpty()
 955:                              where huaweiOltIdList.Contains(a.Olt) && subsro.Access.Id == null
 956:                              select a).Distinct().ToList();
 957:                  }
 958:   
 959:                  return list;
 960:              }
 961:          }
 962:   
 963:          ////////////////////////////////////////////////////////////////////////////
 964:   
 965:          /// <summary>
 966:          ///
 967:          /// </summary>
 968:          public static Ia.Ngn.Cl.Model.Access ReadByIp(string ip)
 969:          {
 970:              // below: return the Access object of this ip
 971:   
 972:              Ia.Ngn.Cl.Model.Access item;
 973:   
 974:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 975:              {
 976:                  item = (from a in db.Accesses join o in db.Onts on a equals o.Access join ov in db.OntServiceVoips on o equals ov.Ont where ov.Ip == ip select a).SingleOrDefault();
 977:              }
 978:   
 979:              return item;
 980:          }
 981:   
 982:          ////////////////////////////////////////////////////////////////////////////
 983:   
 984:          /// <summary>
 985:          ///
 986:          /// </summary>
 987:          public static Ia.Ngn.Cl.Model.Access ReadByIp(Ia.Ngn.Cl.Model.Ngn db, string ip)
 988:          {
 989:              // below: return the Access object of this ip
 990:   
 991:              return (from a in db.Accesses join o in db.Onts on a equals o.Access join ov in db.OntServiceVoips on o equals ov.Ont where ov.Ip == ip select a).SingleOrDefault();
 992:          }
 993:   
 994:          ////////////////////////////////////////////////////////////////////////////
 995:   
 996:          /// <summary>
 997:          ///
 998:          /// </summary>
 999:          public static Ia.Ngn.Cl.Model.Access StatisticalAccess(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, ref List<Ia.Ngn.Cl.Model.Access> accessList)
1000:          {
1001:              // below:
1002:   
1003:              Ia.Ngn.Cl.Model.Access statisticalAccess;
1004:   
1005:              statisticalAccess = (from a in accessList
1006:                                   where a.AreaId == serviceAddress.AreaId
1007:                                       && a.Block == serviceAddress.Block
1008:                                       && a.Street == serviceAddress.Street
1009:                                       && a.PremisesOld == serviceAddress.PremisesOld
1010:                                       && a.PremisesNew == serviceAddress.PremisesNew
1011:                                   select a).FirstOrDefault();
1012:   
1013:              if (statisticalAccess == null)
1014:              {
1015:                  statisticalAccess = (from a in accessList
1016:                                       where a.AreaId == serviceAddress.AreaId
1017:                                           && a.Block == serviceAddress.Block
1018:                                           && a.Street == serviceAddress.Street
1019:                                           && a.PremisesOld == serviceAddress.PremisesOld
1020:                                       select a).FirstOrDefault();
1021:   
1022:                  if (statisticalAccess == null)
1023:                  {
1024:                      statisticalAccess = (from a in accessList
1025:                                           where a.AreaId == serviceAddress.AreaId
1026:                                               && a.Block == serviceAddress.Block
1027:                                               && a.Street == serviceAddress.Street
1028:                                               && a.PremisesNew == serviceAddress.PremisesNew
1029:                                           select a).FirstOrDefault();
1030:   
1031:                      if (statisticalAccess == null)
1032:                      {
1033:                          statisticalAccess = (from a in accessList
1034:                                               where a.AreaId == serviceAddress.AreaId
1035:                                                   && a.Block == serviceAddress.Block
1036:                                                   && a.Street == serviceAddress.Street
1037:                                                   && a.PremisesOld == serviceAddress.PremisesNew
1038:                                               select a).FirstOrDefault();
1039:   
1040:                          if (statisticalAccess == null)
1041:                          {
1042:                              statisticalAccess = (from a in accessList
1043:                                                   where a.AreaId == serviceAddress.AreaId
1044:                                                       && a.Block == serviceAddress.Block
1045:                                                       && a.Street == serviceAddress.Street
1046:                                                       && a.PremisesNew == serviceAddress.PremisesOld
1047:                                                   select a).FirstOrDefault();
1048:   
1049:                              if (statisticalAccess == null)
1050:                              {
1051:                                  statisticalAccess = (from a in accessList
1052:                                                       where a.AreaId == serviceAddress.AreaId
1053:                                                           && a.Block == serviceAddress.Block
1054:                                                           && a.Street == serviceAddress.Street
1055:                                                           && a.PremisesNew == serviceAddress.Boulevard
1056:                                                       select a).FirstOrDefault();
1057:   
1058:                                  if (statisticalAccess == null)
1059:                                  {
1060:                                      statisticalAccess = (from a in accessList
1061:                                                           where a.AreaId == serviceAddress.AreaId
1062:                                                               && a.Block == serviceAddress.Block
1063:                                                               && a.Street == serviceAddress.Street
1064:                                                               && a.PremisesOld == serviceAddress.Boulevard
1065:                                                           select a).FirstOrDefault();
1066:   
1067:                                      if (statisticalAccess == null)
1068:                                      {
1069:                                          statisticalAccess = (from a in accessList
1070:                                                               where a.AreaId == serviceAddress.AreaId
1071:                                                                   && a.Block == serviceAddress.Block
1072:                                                                   && a.PremisesOld == serviceAddress.PremisesOld
1073:                                                               select a).FirstOrDefault();
1074:   
1075:                                          if (statisticalAccess == null)
1076:                                          {
1077:                                              statisticalAccess = (from a in accessList
1078:                                                                   where a.AreaId == serviceAddress.AreaId
1079:                                                                       && a.Block == serviceAddress.Block
1080:                                                                       && a.PremisesNew == serviceAddress.PremisesNew
1081:                                                                   select a).FirstOrDefault();
1082:   
1083:                                              if (statisticalAccess == null)
1084:                                              {
1085:                                                  statisticalAccess = (from a in accessList
1086:                                                                       where a.AreaId == serviceAddress.AreaId
1087:                                                                           && a.Block == serviceAddress.Block
1088:                                                                           && a.PremisesOld == serviceAddress.PremisesNew
1089:                                                                       select a).FirstOrDefault();
1090:   
1091:                                                  if (statisticalAccess == null)
1092:                                                  {
1093:                                                      statisticalAccess = (from a in accessList
1094:                                                                           where a.AreaId == serviceAddress.AreaId
1095:                                                                               && a.Block == serviceAddress.Block
1096:                                                                               && a.PremisesNew == serviceAddress.PremisesOld
1097:                                                                           select a).FirstOrDefault();
1098:   
1099:                                                      if (statisticalAccess == null)
1100:                                                      {
1101:                                                          statisticalAccess = (from a in accessList
1102:                                                                               where a.AreaId == serviceAddress.AreaId
1103:                                                                                   && a.Block == serviceAddress.Block
1104:                                                                                   && a.Street == serviceAddress.Street
1105:                                                                                   && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1106:                                                                                   && a.PremisesNew == serviceAddress.PremisesNew
1107:                                                                               select a).FirstOrDefault();
1108:   
1109:                                                          if (statisticalAccess == null)
1110:                                                          {
1111:                                                              statisticalAccess = (from a in accessList
1112:                                                                                   where a.AreaId == serviceAddress.AreaId
1113:                                                                                       && a.Block == serviceAddress.Block
1114:                                                                                       && a.Street == serviceAddress.Street
1115:                                                                                       && a.PremisesOld == serviceAddress.PremisesOld
1116:                                                                                       && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1117:                                                                                   select a).FirstOrDefault();
1118:   
1119:                                                              if (statisticalAccess == null)
1120:                                                              {
1121:                                                                  statisticalAccess = (from a in accessList
1122:                                                                                       where a.AreaId == serviceAddress.AreaId
1123:                                                                                           && a.Block == serviceAddress.Block
1124:                                                                                           && a.Street == serviceAddress.Street
1125:                                                                                           && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1126:                                                                                       select a).FirstOrDefault();
1127:   
1128:                                                                  if (statisticalAccess == null)
1129:                                                                  {
1130:                                                                      statisticalAccess = (from a in accessList
1131:                                                                                           where a.AreaId == serviceAddress.AreaId
1132:                                                                                               && a.Block == serviceAddress.Block
1133:                                                                                               && a.Street == serviceAddress.Street
1134:                                                                                               && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1135:                                                                                           select a).FirstOrDefault();
1136:   
1137:                                                                      if (statisticalAccess == null)
1138:                                                                      {
1139:                                                                          statisticalAccess = (from a in accessList
1140:                                                                                               where a.AreaId == serviceAddress.AreaId
1141:                                                                                                   && a.Block == serviceAddress.Block
1142:                                                                                                   && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1143:                                                                                                   && a.PremisesNew == serviceAddress.PremisesNew
1144:                                                                                               select a).FirstOrDefault();
1145:   
1146:                                                                          if (statisticalAccess == null)
1147:                                                                          {
1148:                                                                              statisticalAccess = (from a in accessList
1149:                                                                                                   where a.AreaId == serviceAddress.AreaId
1150:                                                                                                       && a.Block == serviceAddress.Block
1151:                                                                                                       && a.PremisesOld == serviceAddress.PremisesOld
1152:                                                                                                       && serviceAddress.PremisesNew != null && serviceAddress.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1153:                                                                                                   select a).FirstOrDefault();
1154:   
1155:                                                                              if (statisticalAccess == null)
1156:                                                                              {
1157:                                                                                  statisticalAccess = (from a in accessList
1158:                                                                                                       where a.AreaId == serviceAddress.AreaId
1159:                                                                                                           && a.Block == serviceAddress.Block
1160:                                                                                                           && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1161:                                                                                                       select a).FirstOrDefault();
1162:   
1163:                                                                                  if (statisticalAccess == null)
1164:                                                                                  {
1165:                                                                                      statisticalAccess = (from a in accessList
1166:                                                                                                           where a.AreaId == serviceAddress.AreaId
1167:                                                                                                               && a.Block == serviceAddress.Block
1168:                                                                                                               && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1169:                                                                                                           select a).FirstOrDefault();
1170:                                                                                  }
1171:                                                                              }
1172:                                                                          }
1173:                                                                      }
1174:                                                                  }
1175:                                                              }
1176:                                                          }
1177:                                                      }
1178:                                                  }
1179:                                              }
1180:                                          }
1181:                                      }
1182:                                  }
1183:                              }
1184:                          }
1185:                      }
1186:                  }
1187:              }
1188:   
1189:              return statisticalAccess;
1190:          }
1191:   
1192:          ////////////////////////////////////////////////////////////////////////////
1193:          ////////////////////////////////////////////////////////////////////////////
1194:   
1195:          /// <summary>
1196:          ///
1197:          /// </summary>
1198:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Access access)
1199:          {
1200:              StringBuilder sb;
1201:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
1202:   
1203:              sb = new StringBuilder();
1204:   
1205:              vendor = (from o in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.OntList where o.Access.Id == access.Id select o.Pon.PonGroup.Olt.Odf.Vendor).SingleOrDefault();
1206:   
1207:              sb.AppendLine("Vendor: " + vendor.Name);
1208:              sb.AppendLine("Name: " + access.Name);
1209:              sb.AppendLine("Address: " + access.Address);
1210:   
1211:              if (!string.IsNullOrEmpty(access.Paci)) sb.AppendLine("Paci: " + access.Paci);
1212:              if (!string.IsNullOrEmpty(access.Note)) sb.AppendLine("Note: " + access.Note);
1213:   
1214:              return sb.ToString();
1215:          }
1216:   
1217:          ////////////////////////////////////////////////////////////////////////////
1218:          ////////////////////////////////////////////////////////////////////////////
1219:      }
1220:   
1221:      ////////////////////////////////////////////////////////////////////////////
1222:      ////////////////////////////////////////////////////////////////////////////
1223:  }