Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
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:                      // debugging
 748:                      //nokiaList = (from n in nokiaList where n.Name == "SHD.33.2" select n).ToList();
 749:   
 750:                      // Huawei
 751:   
 752:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 753:   
 754:                      huaweiOntList = (from a in db.Accesses
 755:                                       join o in db.EmsOnts on a equals o.Access
 756:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 757:                                       from subsro in gj.DefaultIfEmpty()
 758:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 759:                                       && huaweiOltIdList.Contains(a.Olt)
 760:                                       && subsro.Access.Id == null
 761:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 762:   
 763:                      list = nokiaList.Union(huaweiOntList).ToList();
 764:                  }
 765:                  else
 766:                  {
 767:                      site = (from a in Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.SiteList where a.Id == siteId select a).SingleOrDefault();
 768:   
 769:                      nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList(siteId);
 770:   
 771:                      // Nokia
 772:                      nokiaList = (from a in db.Accesses
 773:                                   join oid in nokiaOltIdList on a.Olt equals oid
 774:                                   join o in db.Onts on a equals o.Access
 775:                                   join osv in db.OntServiceVoips on o equals osv.Ont
 776:                                   join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 777:                                   from subsro in gj.DefaultIfEmpty()
 778:                                   where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr
 779:                                   && o.Serial != null
 780:                                   && o.Serial != "ALCL00000000"
 781:                                   && o.FamilyTypeId != 0
 782:                                   && o.ActiveSoftware != null
 783:                                   //&& o.ActiveSoftware == o.PlannedSoftware
 784:                                   && osv.Ip != null
 785:                                   && subsro.Access.Id == null
 786:                                   select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 787:   
 788:                      // Huawei
 789:   
 790:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList(siteId);
 791:   
 792:                      huaweiOntList = (from a in db.Accesses
 793:                                       join o in db.EmsOnts on a equals o.Access
 794:                                       join sro in db.ServiceRequestOnts on a equals sro.Access into gj
 795:                                       from subsro in gj.DefaultIfEmpty()
 796:                                       where o.EQUIPMENTID != string.Empty //.FamilyTypeId != 0
 797:                                       && huaweiOltIdList.Contains(a.Olt)
 798:                                       && subsro.Access.Id == null
 799:                                       select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 800:   
 801:                      list = nokiaList.Union(huaweiOntList).ToList();
 802:                  }
 803:              }
 804:   
 805:              return list.OrderBy(u => u.Id).ToList();
 806:          }
 807:   
 808:          ////////////////////////////////////////////////////////////////////////////
 809:   
 810:          /// <summary>
 811:          ///
 812:          /// </summary>
 813:          public static List<Ia.Ngn.Cl.Model.Access> AccessesWithMismatchedInfomationInServiceRequestOntList()
 814:          {
 815:              List<Ia.Ngn.Cl.Model.Access> list;
 816:              //Dictionary<int, string> areaIdToSymbolDictionary;
 817:   
 818:              //areaIdToSymbolDictionary = Ia.Ngn.Cl.Model.Data.Service.AreaIdToSymbolDictionary;
 819:   
 820:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 821:              {
 822:                  // I will ignore area because its fixed with access id, which is shared by both Access and ServiceRequestOnt
 823:   
 824:                  list = (from a in db.Accesses
 825:                          join o in db.Onts on a equals o.Access
 826:                          join osv in db.OntServiceVoips on o equals osv.Ont
 827:                          join sro in db.ServiceRequestOnts on a equals sro.Access
 828:                          //join areaSymbol in areaIdToSymbolDictionary on a.AreaId equals areaSymbol.Key
 829:                          //where sro.AreaSymbol != areaSymbol.Value
 830:                          where (sro.Block != a.Block && !string.IsNullOrEmpty(a.Block))
 831:                          || (sro.Street != a.Street && !string.IsNullOrEmpty(a.Street))
 832:                          || (sro.PremisesOld != a.PremisesOld && !string.IsNullOrEmpty(a.PremisesOld))
 833:                          || (sro.PremisesNew != a.PremisesNew && !string.IsNullOrEmpty(a.PremisesNew))
 834:                          || (sro.Paci != a.Paci && !string.IsNullOrEmpty(a.Paci))
 835:                          //|| (sro.PossibleNumberOfTd != a.PossibleNumberOfTd)
 836:                          //|| (sro.PossibleNumberOfEthernet != a.PossibleNumberOfEthernet)
 837:                          select a).Distinct().Include(c => c.Onts).Include(c => c.EmsOnts).ToList();
 838:              }
 839:   
 840:              return list.OrderBy(u => u.Id).ToList();
 841:          }
 842:   
 843:          ////////////////////////////////////////////////////////////////////////////
 844:   
 845:          /// <summary>
 846:          ///
 847:          /// </summary>
 848:          public static Dictionary<string, int> AccessesWithProvisionedAndReadyOntsIdToKuwaitNgnAreaIdDictionary
 849:          {
 850:              get
 851:              {
 852:                  Dictionary<string, int> dictionary, nokiaDictionary, huaweiDictionary;
 853:                  List<int> nokiaOltIdList, huaweiOltIdList;
 854:   
 855:                  // this is related to ListOfAccessesWithProvisionedAndReadyOntsButDoNotExistInCustomerDepartmentDatabaseBySiteId()
 856:   
 857:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 858:                  {
 859:                      //nokiaOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 860:   
 861:                      // Nokia
 862:                      nokiaDictionary = (from a in db.Accesses
 863:                                         join o in db.Onts on a equals o.Access
 864:                                         join osv in db.OntServiceVoips on o equals osv.Ont
 865:                                         join sro in db.ServiceRequestOnts on a equals sro.Access
 866:                                         where o.StateId == (int)Ia.Ngn.Cl.Model.Business.Nokia.Ams.BellcoreState.IsNr // ?
 867:                                         && o.Serial != null
 868:                                         && o.Serial != "ALCL00000000"
 869:                                         && o.FamilyTypeId != 0 // ?
 870:                                         && o.ActiveSoftware != null
 871:                                         //&& o.ActiveSoftware == o.PlannedSoftware
 872:                                         && osv.Ip != null
 873:                                         select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 874:   
 875:                      // Huawei
 876:                      huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 877:   
 878:                      huaweiDictionary = (from a in db.Accesses
 879:                                          join o in db.EmsOnts on a equals o.Access
 880:                                          join sro in db.ServiceRequestOnts on a equals sro.Access
 881:                                          //where o.FamilyTypeId != 0
 882:                                          where o.EQUIPMENTID != "--"
 883:                                          && huaweiOltIdList.Contains(a.Olt)
 884:                                          select new { a.Id, a.AreaId }).Distinct().ToDictionary(u => u.Id, u => u.AreaId);
 885:   
 886:                      dictionary = nokiaDictionary.Union(huaweiDictionary).ToDictionary(k => k.Key, v => v.Value);
 887:                  }
 888:   
 889:                  return dictionary;
 890:              }
 891:          }
 892:   
 893:          ////////////////////////////////////////////////////////////////////////////
 894:   
 895:          /// <summary>
 896:          ///
 897:          /// </summary>
 898:          public static List<Ia.Ngn.Cl.Model.Access> NokiaAccessList
 899:          {
 900:              get
 901:              {
 902:                  List<int> oltIdList;
 903:                  List<Ia.Ngn.Cl.Model.Access> list;
 904:   
 905:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.NokiaOltIdList();
 906:   
 907:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 908:                  {
 909:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 910:                  }
 911:   
 912:                  return list;
 913:              }
 914:          }
 915:   
 916:          ////////////////////////////////////////////////////////////////////////////
 917:   
 918:          /// <summary>
 919:          ///
 920:          /// </summary>
 921:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessList
 922:          {
 923:              get
 924:              {
 925:                  List<int> oltIdList;
 926:                  List<Ia.Ngn.Cl.Model.Access> list;
 927:   
 928:                  oltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 929:   
 930:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 931:                  {
 932:                      list = (from a in db.Accesses where oltIdList.Contains(a.Olt) select a).ToList();
 933:                  }
 934:   
 935:                  return list;
 936:              }
 937:          }
 938:   
 939:          ////////////////////////////////////////////////////////////////////////////
 940:   
 941:          /// <summary>
 942:          ///
 943:          /// </summary>
 944:          public static List<Ia.Ngn.Cl.Model.Access> HuaweiAccessesWithNoEmsOntList
 945:          {
 946:              get
 947:              {
 948:                  List<int> huaweiOltIdList;
 949:                  List<Ia.Ngn.Cl.Model.Access> list;
 950:   
 951:                  huaweiOltIdList = Ia.Ngn.Cl.Model.Data.NetworkDesignDocument.HuaweiOltIdList();
 952:   
 953:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
 954:                  {
 955:                      list = (from a in db.Accesses
 956:                              join o in db.EmsOnts on a equals o.Access into gj
 957:                              from subsro in gj.DefaultIfEmpty()
 958:                              where huaweiOltIdList.Contains(a.Olt) && subsro.Access.Id == null
 959:                              select a).Distinct().ToList();
 960:                  }
 961:   
 962:                  return list;
 963:              }
 964:          }
 965:   
 966:          ////////////////////////////////////////////////////////////////////////////
 967:   
 968:          /// <summary>
 969:          ///
 970:          /// </summary>
 971:          public static Ia.Ngn.Cl.Model.Access ReadByIp(string ip)
 972:          {
 973:              // below: return the Access object of this ip
 974:   
 975:              Ia.Ngn.Cl.Model.Access item;
 976:   
 977:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 978:              {
 979:                  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();
 980:              }
 981:   
 982:              return item;
 983:          }
 984:   
 985:          ////////////////////////////////////////////////////////////////////////////
 986:   
 987:          /// <summary>
 988:          ///
 989:          /// </summary>
 990:          public static Ia.Ngn.Cl.Model.Access ReadByIp(Ia.Ngn.Cl.Model.Ngn db, string ip)
 991:          {
 992:              // below: return the Access object of this ip
 993:   
 994:              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();
 995:          }
 996:   
 997:          ////////////////////////////////////////////////////////////////////////////
 998:   
 999:          /// <summary>
1000:          ///
1001:          /// </summary>
1002:          public static Ia.Ngn.Cl.Model.Access StatisticalAccess(Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress, ref List<Ia.Ngn.Cl.Model.Access> accessList)
1003:          {
1004:              // below:
1005:   
1006:              Ia.Ngn.Cl.Model.Access statisticalAccess;
1007:   
1008:              statisticalAccess = (from a in accessList
1009:                                   where a.AreaId == serviceAddress.AreaId
1010:                                       && a.Block == serviceAddress.Block
1011:                                       && a.Street == serviceAddress.Street
1012:                                       && a.PremisesOld == serviceAddress.PremisesOld
1013:                                       && a.PremisesNew == serviceAddress.PremisesNew
1014:                                   select a).FirstOrDefault();
1015:   
1016:              if (statisticalAccess == null)
1017:              {
1018:                  statisticalAccess = (from a in accessList
1019:                                       where a.AreaId == serviceAddress.AreaId
1020:                                           && a.Block == serviceAddress.Block
1021:                                           && a.Street == serviceAddress.Street
1022:                                           && a.PremisesOld == serviceAddress.PremisesOld
1023:                                       select a).FirstOrDefault();
1024:   
1025:                  if (statisticalAccess == null)
1026:                  {
1027:                      statisticalAccess = (from a in accessList
1028:                                           where a.AreaId == serviceAddress.AreaId
1029:                                               && a.Block == serviceAddress.Block
1030:                                               && a.Street == serviceAddress.Street
1031:                                               && a.PremisesNew == serviceAddress.PremisesNew
1032:                                           select a).FirstOrDefault();
1033:   
1034:                      if (statisticalAccess == null)
1035:                      {
1036:                          statisticalAccess = (from a in accessList
1037:                                               where a.AreaId == serviceAddress.AreaId
1038:                                                   && a.Block == serviceAddress.Block
1039:                                                   && a.Street == serviceAddress.Street
1040:                                                   && a.PremisesOld == serviceAddress.PremisesNew
1041:                                               select a).FirstOrDefault();
1042:   
1043:                          if (statisticalAccess == null)
1044:                          {
1045:                              statisticalAccess = (from a in accessList
1046:                                                   where a.AreaId == serviceAddress.AreaId
1047:                                                       && a.Block == serviceAddress.Block
1048:                                                       && a.Street == serviceAddress.Street
1049:                                                       && a.PremisesNew == serviceAddress.PremisesOld
1050:                                                   select a).FirstOrDefault();
1051:   
1052:                              if (statisticalAccess == null)
1053:                              {
1054:                                  statisticalAccess = (from a in accessList
1055:                                                       where a.AreaId == serviceAddress.AreaId
1056:                                                           && a.Block == serviceAddress.Block
1057:                                                           && a.Street == serviceAddress.Street
1058:                                                           && a.PremisesNew == serviceAddress.Boulevard
1059:                                                       select a).FirstOrDefault();
1060:   
1061:                                  if (statisticalAccess == null)
1062:                                  {
1063:                                      statisticalAccess = (from a in accessList
1064:                                                           where a.AreaId == serviceAddress.AreaId
1065:                                                               && a.Block == serviceAddress.Block
1066:                                                               && a.Street == serviceAddress.Street
1067:                                                               && a.PremisesOld == serviceAddress.Boulevard
1068:                                                           select a).FirstOrDefault();
1069:   
1070:                                      if (statisticalAccess == null)
1071:                                      {
1072:                                          statisticalAccess = (from a in accessList
1073:                                                               where a.AreaId == serviceAddress.AreaId
1074:                                                                   && a.Block == serviceAddress.Block
1075:                                                                   && a.PremisesOld == serviceAddress.PremisesOld
1076:                                                               select a).FirstOrDefault();
1077:   
1078:                                          if (statisticalAccess == null)
1079:                                          {
1080:                                              statisticalAccess = (from a in accessList
1081:                                                                   where a.AreaId == serviceAddress.AreaId
1082:                                                                       && a.Block == serviceAddress.Block
1083:                                                                       && a.PremisesNew == serviceAddress.PremisesNew
1084:                                                                   select a).FirstOrDefault();
1085:   
1086:                                              if (statisticalAccess == null)
1087:                                              {
1088:                                                  statisticalAccess = (from a in accessList
1089:                                                                       where a.AreaId == serviceAddress.AreaId
1090:                                                                           && a.Block == serviceAddress.Block
1091:                                                                           && a.PremisesOld == serviceAddress.PremisesNew
1092:                                                                       select a).FirstOrDefault();
1093:   
1094:                                                  if (statisticalAccess == null)
1095:                                                  {
1096:                                                      statisticalAccess = (from a in accessList
1097:                                                                           where a.AreaId == serviceAddress.AreaId
1098:                                                                               && a.Block == serviceAddress.Block
1099:                                                                               && a.PremisesNew == serviceAddress.PremisesOld
1100:                                                                           select a).FirstOrDefault();
1101:   
1102:                                                      if (statisticalAccess == null)
1103:                                                      {
1104:                                                          statisticalAccess = (from a in accessList
1105:                                                                               where a.AreaId == serviceAddress.AreaId
1106:                                                                                   && a.Block == serviceAddress.Block
1107:                                                                                   && a.Street == serviceAddress.Street
1108:                                                                                   && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1109:                                                                                   && a.PremisesNew == serviceAddress.PremisesNew
1110:                                                                               select a).FirstOrDefault();
1111:   
1112:                                                          if (statisticalAccess == null)
1113:                                                          {
1114:                                                              statisticalAccess = (from a in accessList
1115:                                                                                   where a.AreaId == serviceAddress.AreaId
1116:                                                                                       && a.Block == serviceAddress.Block
1117:                                                                                       && a.Street == serviceAddress.Street
1118:                                                                                       && a.PremisesOld == serviceAddress.PremisesOld
1119:                                                                                       && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1120:                                                                                   select a).FirstOrDefault();
1121:   
1122:                                                              if (statisticalAccess == null)
1123:                                                              {
1124:                                                                  statisticalAccess = (from a in accessList
1125:                                                                                       where a.AreaId == serviceAddress.AreaId
1126:                                                                                           && a.Block == serviceAddress.Block
1127:                                                                                           && a.Street == serviceAddress.Street
1128:                                                                                           && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1129:                                                                                       select a).FirstOrDefault();
1130:   
1131:                                                                  if (statisticalAccess == null)
1132:                                                                  {
1133:                                                                      statisticalAccess = (from a in accessList
1134:                                                                                           where a.AreaId == serviceAddress.AreaId
1135:                                                                                               && a.Block == serviceAddress.Block
1136:                                                                                               && a.Street == serviceAddress.Street
1137:                                                                                               && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1138:                                                                                           select a).FirstOrDefault();
1139:   
1140:                                                                      if (statisticalAccess == null)
1141:                                                                      {
1142:                                                                          statisticalAccess = (from a in accessList
1143:                                                                                               where a.AreaId == serviceAddress.AreaId
1144:                                                                                                   && a.Block == serviceAddress.Block
1145:                                                                                                   && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1146:                                                                                                   && a.PremisesNew == serviceAddress.PremisesNew
1147:                                                                                               select a).FirstOrDefault();
1148:   
1149:                                                                          if (statisticalAccess == null)
1150:                                                                          {
1151:                                                                              statisticalAccess = (from a in accessList
1152:                                                                                                   where a.AreaId == serviceAddress.AreaId
1153:                                                                                                       && a.Block == serviceAddress.Block
1154:                                                                                                       && a.PremisesOld == serviceAddress.PremisesOld
1155:                                                                                                       && serviceAddress.PremisesNew != null && serviceAddress.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1156:                                                                                                   select a).FirstOrDefault();
1157:   
1158:                                                                              if (statisticalAccess == null)
1159:                                                                              {
1160:                                                                                  statisticalAccess = (from a in accessList
1161:                                                                                                       where a.AreaId == serviceAddress.AreaId
1162:                                                                                                           && a.Block == serviceAddress.Block
1163:                                                                                                           && serviceAddress.PremisesOld != null && a.PremisesOld != null && a.PremisesOld.Contains(serviceAddress.PremisesOld)
1164:                                                                                                       select a).FirstOrDefault();
1165:   
1166:                                                                                  if (statisticalAccess == null)
1167:                                                                                  {
1168:                                                                                      statisticalAccess = (from a in accessList
1169:                                                                                                           where a.AreaId == serviceAddress.AreaId
1170:                                                                                                               && a.Block == serviceAddress.Block
1171:                                                                                                               && serviceAddress.PremisesNew != null && a.PremisesNew != null && a.PremisesNew.Contains(serviceAddress.PremisesNew)
1172:                                                                                                           select a).FirstOrDefault();
1173:                                                                                  }
1174:                                                                              }
1175:                                                                          }
1176:                                                                      }
1177:                                                                  }
1178:                                                              }
1179:                                                          }
1180:                                                      }
1181:                                                  }
1182:                                              }
1183:                                          }
1184:                                      }
1185:                                  }
1186:                              }
1187:                          }
1188:                      }
1189:                  }
1190:              }
1191:   
1192:              return statisticalAccess;
1193:          }
1194:   
1195:          ////////////////////////////////////////////////////////////////////////////
1196:          ////////////////////////////////////////////////////////////////////////////
1197:   
1198:          /// <summary>
1199:          ///
1200:          /// </summary>
1201:          public static string ToSimpleTextString(Ia.Ngn.Cl.Model.Access access)
1202:          {
1203:              StringBuilder sb;
1204:              Ia.Ngn.Cl.Model.Business.NetworkDesignDocument.Vendor vendor;
1205:   
1206:              sb = new StringBuilder();
1207:   
1208:              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();
1209:   
1210:              sb.AppendLine("Vendor: " + vendor.Name);
1211:              sb.AppendLine("Name: " + access.Name);
1212:              sb.AppendLine("Address: " + access.Address);
1213:   
1214:              if (!string.IsNullOrEmpty(access.Paci)) sb.AppendLine("Paci: " + access.Paci);
1215:              if (!string.IsNullOrEmpty(access.Note)) sb.AppendLine("Note: " + access.Note);
1216:   
1217:              return sb.ToString();
1218:          }
1219:   
1220:          ////////////////////////////////////////////////////////////////////////////
1221:          ////////////////////////////////////////////////////////////////////////////
1222:      }
1223:   
1224:      ////////////////////////////////////////////////////////////////////////////
1225:      ////////////////////////////////////////////////////////////////////////////
1226:  }