Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » ServiceRequestService

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

Service Request Service support class of Next Generation Network'a (NGN's) business model.

   1:  using System;
   2:  using System.Collections;
   3:  using System.Collections.Generic;
   4:  using System.Linq;
   5:  using System.Web;
   6:  using System.ComponentModel.DataAnnotations;
   7:  using System.ComponentModel.DataAnnotations.Schema;
   8:  using System.Data;
   9:  using System.Text;
  10:   
  11:  namespace Ia.Ngn.Cl.Model.Business
  12:  {
  13:      ////////////////////////////////////////////////////////////////////////////
  14:   
  15:      /// <summary publish="true">
  16:      /// Service Request Service support class of Next Generation Network'a (NGN's) business model.
  17:      /// </summary>
  18:      /// 
  19:      /// <remarks> 
  20:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  21:      ///
  22:      /// 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
  23:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  24:      ///
  25:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  26:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  27:      /// 
  28:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  29:      /// 
  30:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  31:      /// </remarks> 
  32:      public partial class ServiceRequestService
  33:      {
  34:          private static StringBuilder log = new StringBuilder();
  35:   
  36:          /*
  37:          internal sealed class Tuple<TFirst, TSecond>
  38:          {
  39:              public Tuple(TFirst first, TSecond second) { First = first; Second = second; }
  40:  
  41:              public TFirst First { get; private set; }
  42:              public TSecond Second { get; private set; }
  43:  
  44:              public override bool Equals(object value)
  45:              {
  46:                  return value != null && Equals(value as Tuple<TFirst, TSecond>);
  47:              }
  48:  
  49:              private bool Equals(Tuple<TFirst, TSecond> type)
  50:              {
  51:                  return type != null
  52:                         && EqualityComparer<TFirst>.Default.Equals(type.First, First)
  53:                         && EqualityComparer<TSecond>.Default.Equals(type.Second, Second);
  54:              }
  55:  
  56:              public override int GetHashCode() { throw new NotImplementedException(); }
  57:  
  58:              public override string ToString()
  59:              {
  60:                  return "{ First = " + First + ", Second = " + Second + " }";
  61:              }
  62:          }
  63:           */
  64:   
  65:          ////////////////////////////////////////////////////////////////////////////
  66:   
  67:          /// <summary>
  68:          ///
  69:          /// </summary>
  70:          public enum ServiceRequestServiceType { Create = 1, Read, Update, Delete };
  71:   
  72:          ////////////////////////////////////////////////////////////////////////////
  73:   
  74:          /// <summary>
  75:          ///
  76:          /// </summary>
  77:          public ServiceRequestService() { }
  78:   
  79:          ////////////////////////////////////////////////////////////////////////////
  80:   
  81:          /// <summary>
  82:          ///
  83:          /// </summary>
  84:          public static string ServiceIdToService(string service)
  85:          {
  86:              return Ia.Ngn.Cl.Model.Business.Service.ServiceIdToService(service);
  87:          }
  88:   
  89:          ////////////////////////////////////////////////////////////////////////////
  90:   
  91:          /// <summary>
  92:          ///
  93:          /// </summary>
  94:          public static string ServiceRequestServiceId(string service, int serviceType)
  95:          {
  96:              // below:
  97:              string id;
  98:   
  99:              id = Ia.Ngn.Cl.Model.Business.Service2.ServiceId(service, serviceType);
 100:   
 101:              return id;
 102:          }
 103:   
 104:          ////////////////////////////////////////////////////////////////////////////
 105:   
 106:          /// <summary>
 107:          ///
 108:          /// </summary>
 109:          public static void UpdateServiceSuspension(string service, bool serviceSuspensionState, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact, out Ia.Cl.Model.Result result)
 110:          {
 111:              string numberString;
 112:   
 113:              result = new Ia.Cl.Model.Result();
 114:   
 115:              numberString = service; // HttpServerUtility.HtmlEncode(service);
 116:              numberString = numberString.Trim();
 117:   
 118:              if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Update, staffContact))
 119:              {
 120:                  if (numberString.Length > 0 && int.TryParse(numberString, out int number))
 121:                  {
 122:                      if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(number))
 123:                      {
 124:                          Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateServiceSuspension(number.ToString(), serviceSuspensionState, staffContact.UserId, out result);
 125:   
 126:                          if (result.IsSuccessful)
 127:                          {
 128:                              result.AddSuccess("Service record '" + numberString + "' has its service suspension value updated to '" + serviceSuspensionState.ToString().ToLower() + "'");
 129:                          }
 130:                          else
 131:                          {
 132:                          }
 133:                      }
 134:                      else
 135:                      {
 136:                          result.AddError(@"The number '" + number + @"' does not belong to the network (الرقم لا ينتمي للشبكة). ");
 137:                      }
 138:                  }
 139:                  else
 140:                  {
 141:                      result.AddError("Number format is incorrect or nothing was entered (الرقم غير مفهوم أو مفقود). ");
 142:                  }
 143:              }
 144:              else
 145:              {
 146:                  result.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة). ");
 147:              }
 148:          }
 149:   
 150:          ////////////////////////////////////////////////////////////////////////////
 151:   
 152:          /// <summary>
 153:          ///
 154:          /// </summary>
 155:          public static void ReadServiceSuspension(string service, Ia.Ngn.Cl.Model.Business.Administration.StaffContact staffContact, string key, out bool isSuspended, out DateTime serviceLastUpdated, out Ia.Cl.Model.Result result)
 156:          {
 157:              string numberString;
 158:              DateTime now;
 159:              Ia.Ngn.Cl.Model.Service2 service2;
 160:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 161:   
 162:              result = new Ia.Cl.Model.Result();
 163:   
 164:              isSuspended = false;
 165:              serviceLastUpdated = DateTime.MinValue;
 166:   
 167:              numberString = service; // Server.HtmlDecode(serviceTextBox.Text);
 168:              numberString = numberString.Trim();
 169:   
 170:              now = DateTime.UtcNow.AddHours(3);
 171:   
 172:              if (Ia.Ngn.Cl.Model.Business.Authority.StaffContactCanReadUpdateServiceSuspension(Ia.Ngn.Cl.Model.Business.Authority.PersistentStorageFunction.Read, staffContact))
 173:              {
 174:                  if (numberString.Length > 0 && int.TryParse(numberString, out int number))
 175:                  {
 176:                      if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(number))
 177:                      {
 178:                          serviceRequestService = Ia.Ngn.Cl.Model.Data.ServiceRequestService.Read(number);
 179:                          service2 = Ia.Ngn.Cl.Model.Data.Service2.Read(number);
 180:   
 181:                          if (serviceRequestService != null && service2 != null)
 182:                          {
 183:                              result.AddSuccess("Pending service suspension value is '" + serviceRequestService.ServiceSuspension.ToString().ToLower() + "' (updated: " + serviceRequestService.Updated + "). System service suspension value is '" + service2.ServiceSuspension.ToString().ToLower() + "' (updated: " + service2.Updated + "). ");
 184:   
 185:                              isSuspended = service2.ServiceSuspension;
 186:                              serviceLastUpdated = service2.Updated;
 187:                          }
 188:                          else
 189:                          {
 190:                              result.AddError("Service and/or service request service record for '" + numberString + "' does not exist. ");
 191:                          }
 192:                      }
 193:                      else
 194:                      {
 195:                          result.AddError(@"The number '" + number + @"' does not belong to the network (الرقم لا ينتمي للشبكة). ");
 196:                      }
 197:                  }
 198:                  else
 199:                  {
 200:                      result.AddError("Number format is incorrect or nothing was entered (الرقم غير مفهوم أو مفقود). ");
 201:                  }
 202:              }
 203:              else
 204:              {
 205:                  result.AddError("You are not authorized to read this value (لست مخولاً بقراءة هذه القيمة). ");
 206:              }
 207:          }
 208:   
 209:          ////////////////////////////////////////////////////////////////////////////
 210:   
 211:          /// <summary>
 212:          /// Update service-request-service table with data from service requests
 213:          /// </summary>
 214:          public static void UpdateForServiceRequestIdRange(Tuple<int, int> startEndRange, out string result)
 215:          {
 216:              bool recordExisted, initialRecordCreated;
 217:              int serviceType;
 218:              string service, serviceRequestServiceId, r0, r1, r2;
 219:              DateTime lastRequestDateTime;
 220:              Hashtable serviceNumberChangeHashtable;
 221:              Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService;
 222:              Ia.Ngn.Cl.Model.ServiceInitialState serviceInitialState;
 223:              List<int> numberList, changedNumberList;
 224:              List<string> serviceList;
 225:              List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList;
 226:              List<Ia.Ngn.Cl.Model.ServiceRequest> serviceRequestList;
 227:              List<Ia.Ngn.Cl.Model.ServiceRequestService> serviceRequestServiceList;
 228:              List<Ia.Ngn.Cl.Model.ServiceInitialState> serviceInitialStateList;
 229:   
 230:              recordExisted = false;
 231:              r0 = r1 = r2 = "";
 232:              serviceNumberChangeHashtable = new Hashtable(10);
 233:              // above: serviceNumberChangeHashtable will contain serviceRequestServiceId as keys and the new number as value
 234:   
 235:              lastRequestDateTime = DateTime.MinValue;
 236:   
 237:              // 1. Read all SRs for this range
 238:              serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.ReadListWithinIdRange(startEndRange.Item1, startEndRange.Item2);
 239:   
 240:              // 2. Collect numbers in int format into int list
 241:              numberList = serviceRequestList.DistinctNumberList();
 242:              //numberList = new List<int>();
 243:              //numberList.Add(24848450);
 244:   
 245:              // 3. Read all SRs related to collected numbers
 246:              serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(numberList);
 247:   
 248:              // 4. Read all SRTs related to collected numbers
 249:              serviceRequestTypeList = Ia.Ngn.Cl.Model.Data.ServiceRequestType.RelatedToServiceRequestNumberList(numberList);
 250:   
 251:              // 5 Read all possible changed numbers from all SRT and add them to service list
 252:              changedNumberList = Ia.Ngn.Cl.Model.Business.ServiceRequestType.PossibleChangedNumberList(serviceRequestTypeList);
 253:   
 254:              if (changedNumberList.Count > 0)
 255:              {
 256:                  numberList.AddRange(changedNumberList);
 257:                  numberList = numberList.Distinct().ToList();
 258:   
 259:                  // 6 Read all SRs related to collected numbers
 260:                  serviceRequestList = Ia.Ngn.Cl.Model.Data.ServiceRequest.List(numberList);
 261:   
 262:                  // 7. Read all SRTs related to collected numbers
 263:                  serviceRequestTypeList = Ia.Ngn.Cl.Model.Data.ServiceRequestType.RelatedToServiceRequestNumberList(numberList);
 264:              }
 265:   
 266:              // 8. Collect numbers in string format into int list (add changed number list)
 267:              serviceList = (from n in numberList select n.ToString()).ToList<string>();
 268:   
 269:              // 9. Read initial states of a service for all numbers in the list
 270:              serviceInitialStateList = Ia.Ngn.Cl.Model.Data.ServiceInitialState.ReadList(numberList);
 271:   
 272:              // 10. Initialize SRS empty list
 273:              serviceRequestServiceList = new List<Ia.Ngn.Cl.Model.ServiceRequestService>(serviceRequestList.Count);
 274:   
 275:              serviceType = 1; // (?) <type id="1" name="Dn"
 276:   
 277:              // 11. Loop through all sr records by request id ascending
 278:              foreach (Ia.Ngn.Cl.Model.ServiceRequest sr in serviceRequestList.OrderBy(p => p.Id))
 279:              {
 280:                  if (Ia.Ngn.Cl.Model.Business.Authority.ServiceRequestIsAllowedProcessing(sr))
 281:                  {
 282:                      // below: we will only process service requests that have status = 2003 or status = 2005
 283:                      if (sr.Status == 2003 || sr.Status == 2005)
 284:                      {
 285:                          // below: we will only process service requests that have allowed service Ids
 286:                          if (Ia.Ngn.Cl.Model.Data.ServiceRequest.ServiceIdAllowedForProcessingList.Contains(sr.ServiceId))
 287:                          {
 288:                              // <status id="2003" arabicName="قيد التنفيذ" />
 289:                              // <status id="2005" arabicName="تم التنفيذ" />
 290:   
 291:                              // below: first check if there is already a SRS record within this loop
 292:   
 293:                              initialRecordCreated = false;
 294:   
 295:                              service = sr.Number.ToString();
 296:   
 297:                              serviceRequestServiceId = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(service, serviceType);
 298:   
 299:                              serviceRequestService = (from srs in serviceRequestServiceList where srs.Id == serviceRequestServiceId select srs).OrderByDescending(u => u.Updated).GroupBy(u => u.Id).Select(u => u.First()).FirstOrDefault(); //.SingleOrDefault();
 300:   
 301:                              if (serviceRequestService == null || serviceRequestService.Provisioned == false)
 302:                              {
 303:                                  if(serviceRequestService == null) serviceRequestService = new Ia.Ngn.Cl.Model.ServiceRequestService();
 304:   
 305:                                  serviceRequestService.Id = serviceRequestServiceId;
 306:                                  serviceRequestService.Service = service;
 307:                                  serviceRequestService.AreaCode = Ia.Ngn.Cl.Model.Business.Service.CountryCode;
 308:                                  serviceRequestService.ServiceType = serviceType;
 309:                                  //serviceRequestService.Type = ??;
 310:                                  serviceRequestService.Provisioned = true;
 311:   
 312:                                  serviceInitialState = (from sis in serviceInitialStateList where sis.Id == serviceRequestServiceId select sis).SingleOrDefault();
 313:   
 314:                                  if (serviceInitialState != null)
 315:                                  {
 316:                                      serviceRequestService.CopyComplementaryService(serviceInitialState);
 317:                                  }
 318:                                  else
 319:                                  {
 320:                                      // below: We had some problems with Huawei numbers not having complete service orders. this will enable some services initially. If an installation order comes it will override this. If not, this will enable services
 321:                                      // for incomplete service orders
 322:                                      serviceRequestService.CallerId = true;
 323:                                      //serviceRequestService.WakeupCall = true;
 324:                                      //serviceRequestService.InternationalCallingUserControlled = true;
 325:                                      serviceRequestService.CallWaiting = true;
 326:                                      //serviceRequestService.CallForwarding = true;
 327:                                      //serviceRequestService.ConferenceCall = true;
 328:                                  }
 329:   
 330:                                  recordExisted = false;
 331:                              }
 332:                              else recordExisted = true;
 333:   
 334:                              if (sr.ServiceCategoryId == 3)
 335:                              {
 336:                                  // <category id="1" arabicName="الخدمات الهاتفية" />
 337:   
 338:                                  TelephonyService(sr, serviceRequestTypeList, ref serviceRequestService, ref lastRequestDateTime, recordExisted, out initialRecordCreated);
 339:                              }
 340:                              else if (sr.ServiceCategoryId == 49)
 341:                              {
 342:                                  // <category id="49" arabicName="إنترنت ألياف ضوئية - مشترك" />
 343:                              }
 344:                              else
 345:                              {
 346:                                  //r0 += "service category id=" + sr.ServiceCategoryId + " was not recognized. \r\n";
 347:                              }
 348:   
 349:                              // below: important, only update if it is null
 350:                              //if (srs.Access != null) newServiceRequestService.Access = Ia.Ngn.Cl.Model.Access.Read(db, srs.Access.Id);
 351:   
 352:                              //if(serviceRequestService != null) recordExisted = serviceRequestServiceList.Any(srs => srs.Id == serviceRequestService.Id);
 353:   
 354:                              //if (initialRecordCreated)
 355:                              //{
 356:                              //    serviceRequestServiceList.Add(serviceRequestService);
 357:                              //    sr.ServiceRequestService = serviceRequestService;
 358:                              //}
 359:                              //else
 360:                              //{
 361:                              if (!recordExisted)
 362:                              {
 363:                                  if (serviceRequestService != null)
 364:                                  {
 365:                                      serviceRequestServiceList.Add(serviceRequestService);
 366:   
 367:                                      sr.ServiceRequestService = serviceRequestService;
 368:                                  }
 369:                              }
 370:                              else if (recordExisted)
 371:                              {
 372:                                  if (serviceRequestService == null)
 373:                                  {
 374:                                      serviceRequestService.Provisioned = false;
 375:   
 376:                                      // remove entry from list
 377:                                      //var itemToRemove = serviceRequestServiceList.SingleOrDefault(r => r.Id == serviceRequestServiceId);
 378:   
 379:                                      //if (itemToRemove != null) serviceRequestServiceList.Remove(itemToRemove);
 380:   
 381:                                      //sr.ServiceRequestService = null;
 382:                                  }
 383:                                  else
 384:                                  {
 385:                                      sr.ServiceRequestService = serviceRequestService;
 386:                                  }
 387:                              }
 388:                              //}
 389:                          }
 390:                          else
 391:                          {
 392:                              //r0 += "serviceId=" + sr.ServiceId + " unprocessed. \r\n";
 393:                          }
 394:                      }
 395:                      else
 396:                      {
 397:                          //r0 += "status=" + sr.Status + " unprocessed. \r\n";
 398:                      }
 399:                  }
 400:              }
 401:   
 402:              // 12. Remove duplicates (Linq orderyby boolean See http://stackoverflow.com/questions/9481054/linq-orderyby-boolean)
 403:              serviceRequestServiceList = serviceRequestServiceList.OrderByDescending(u => u.Updated).OrderByDescending(u => u.Provisioned).GroupBy(u => u.Id).Select(u => u.First()).ToList();
 404:   
 405:              // 13. Update service request services
 406:              Ia.Ngn.Cl.Model.Data.ServiceRequestService.UpdateWithServiceList(serviceList, serviceRequestServiceList, out r1);
 407:   
 408:              // 14. Update service requests with SRS foreign keys
 409:              Ia.Ngn.Cl.Model.Data.ServiceRequest.UpdateWithServiceList(serviceList, serviceRequestList, out r2);
 410:   
 411:              // 15. Update service initial state
 412:              //Ia.Ngn.Cl.Model.Data.ServiceInitialState.DeleteIfServiceRequestServiceExistsList(serviceRequestServiceList, out r3);
 413:   
 414:              result = r1 + " " + r2; // + " " + r3;
 415:          }
 416:   
 417:          ////////////////////////////////////////////////////////////////////////////
 418:   
 419:          /// <summary>
 420:          ///
 421:          /// </summary>
 422:          private static void TelephonyService(Ia.Ngn.Cl.Model.ServiceRequest serviceRequest, List<Ia.Ngn.Cl.Model.ServiceRequestType> serviceRequestTypeList, ref Ia.Ngn.Cl.Model.ServiceRequestService serviceRequestService, ref DateTime lastRequestDateTime, bool recordExists, out bool initialRecordCreated)
 423:          {
 424:              int serviceType;
 425:              string changedServiceNumber;//, level;
 426:              //Ia.Ngn.Cl.Model.Business.ServiceAddress serviceAddress;
 427:              Ia.Ngn.Cl.Model.Access access;
 428:              //List<Ia.Ngn.Cl.Model.Access> accessList;
 429:   
 430:              /*
 431:               * <service id="15" arabicName="خدمة المحاسبة" />
 432:               * <service id="42" arabicName="نقل داخلي" />
 433:               * <service id="44" arabicName="تغيير نوع إشتراك" />
 434:               * <service id="63" arabicName="ايقاف التحويل الآلي/بدالة فرع" />
 435:               * <service id="64" arabicName="ايقاف التحويل الآلي/بدالة رئيس" />
 436:               * <service id="65" arabicName="إيقاف المحاسبة الذاتية" />
 437:               * <service id="271" arabicName="تغيير اسم"/>
 438:               */
 439:   
 440:              initialRecordCreated = false;
 441:              serviceType = 1; // <type id="1" name="Dn"
 442:   
 443:              // below: we will process only telephone service numbers that fall within network specs.
 444:              if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(serviceRequest.Number))
 445:              {
 446:                  lastRequestDateTime = serviceRequest.RequestDateTime;
 447:   
 448:                  if (serviceRequest.ServiceId == 1 || serviceRequest.ServiceId == 129 || serviceRequest.ServiceId == 39 || serviceRequest.ServiceId == 41 || serviceRequest.ServiceId == 54)
 449:                  {
 450:                      // <service id="1" arabicName="خط هاتف" />
 451:                      // <service id="129" arabicName="خط هاتف مع نداء آلي"/>
 452:                      // <service id="39" arabicName="نقل خارجى" />
 453:                      // <service id="41" arabicName="تغيير رقم" />
 454:                      // <service id="54" arabicName="اعادة تركيب" />
 455:   
 456:                      if (serviceRequest.ServiceId == 1 || serviceRequest.ServiceId == 129 || serviceRequest.ServiceId == 39 || serviceRequest.ServiceId == 54)
 457:                      {
 458:                          // <service id="1" arabicName="خط هاتف" />
 459:                          // <service id="129" arabicName="خط هاتف مع نداء آلي"/>
 460:                          // <service id="39" arabicName="نقل خارجى" />
 461:                          // <service id="54" arabicName="اعادة تركيب" />
 462:   
 463:                          if (/*!recordExists &&*/ serviceRequest.ServiceId == 1 || serviceRequest.ServiceId == 129 || serviceRequest.ServiceId == 54)
 464:                          {
 465:                              // <service id="1" arabicName="خط هاتف" />
 466:                              // <service id="129" arabicName="خط هاتف مع نداء آلي"/>
 467:                              // <service id="54" arabicName="اعادة تركيب" />
 468:   
 469:                              // below: keep this here and don't move it out to accommodate 39
 470:                              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 471:                              {
 472:                                  // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == Guid.Empty && update.Id > stored.Id)
 473:                                  access = Ia.Ngn.Cl.Model.Business.ServiceRequestType.ExtractAccess(serviceRequest.Id, serviceRequestTypeList);
 474:   
 475:                                  if (access != null) serviceRequestService.Access = (from a in db.Accesses where a.Id == access.Id select a).SingleOrDefault();
 476:                                  else serviceRequestService.Access = null;
 477:                                  /*
 478:                                   * I will not use statistical estimation for incomplete workorders
 479:                                  else
 480:                                  {
 481:                                      serviceAddress = Ia.Ngn.Cl.Model.Business.ServiceRequest.StatisticalServiceAddress(serviceRequestService.Service, serviceRequest.CustomerAddress, out level);
 482:  
 483:                                      if (serviceAddress != null)
 484:                                      {
 485:                                          accessList = (from a in db.Accesses where a.AreaId == serviceAddress.AreaId select a).ToList();
 486:  
 487:                                          access = Ia.Ngn.Cl.Model.Data.Access.StatisticalAccess(serviceAddress, ref accessList);
 488:  
 489:                                          if (access != null)
 490:                                          {
 491:                                              serviceRequestService.Access = (from a in db.Accesses where a.Id == access.Id select a).SingleOrDefault();
 492:                                          }
 493:                                          else serviceRequestService.Access = null;
 494:                                      }
 495:                                      else serviceRequestService.Access = null;
 496:                                  }
 497:                                  */
 498:                              }
 499:   
 500:                              serviceRequestService.CallerId = false;
 501:   
 502:                              serviceRequestService.AlarmCall = false;
 503:                              serviceRequestService.WakeupCall = false;
 504:   
 505:                              ///serviceRequestService.InternationalCallingUserControlled = true; // as requested by MOC NGN management
 506:                              serviceRequestService.CallWaiting = false;
 507:                              serviceRequestService.CallForwarding = false;
 508:                              serviceRequestService.ConferenceCall = false;
 509:                              serviceRequestService.CallBarring = false;
 510:   
 511:                              if (serviceRequest.ServiceId == 1 || serviceRequest.ServiceId == 54) serviceRequestService.InternationalCalling = false;
 512:                              else if (serviceRequest.ServiceId == 129) serviceRequestService.InternationalCalling = true;
 513:                              
 514:                              initialRecordCreated = true;
 515:                          }
 516:                          else if (/*recordExists &&*/ serviceRequest.ServiceId == 39)
 517:                          {
 518:                              // <service id="39" arabicName="نقل خارجى" />
 519:   
 520:                              // old: in this case the SRT values of the original 1 or 129 will be updated, therefore we will not do anything here, and the original 1 or 129 will have the result of this 39 service
 521:                              // update: it seems that the 39 order has the new destination address now
 522:   
 523:                              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 524:                              {
 525:                                  // important: ServiceRequestService.Update() will only update stored.Access if it is null, or (stored.userId == Guid.Empty && update.Id > stored.Id)
 526:                                  access = Ia.Ngn.Cl.Model.Business.ServiceRequestType.ExtractAccess(serviceRequest.Id, serviceRequestTypeList);
 527:   
 528:                                  if (access != null) serviceRequestService.Access = (from a in db.Accesses where a.Id == access.Id select a).SingleOrDefault();
 529:                                  //else serviceRequestService.Access = null;
 530:                              }
 531:                          }
 532:                      }
 533:                      else if (/*recordExists &&*/ serviceRequest.ServiceId == 41)
 534:                      {
 535:                          // <service id="41" arabicName="تغيير رقم" />
 536:   
 537:                          // below: <type id="11" name="dn" arabicName="dn" oracleFieldName="الرقم الجديد"/>
 538:                          changedServiceNumber = (from srt in serviceRequestTypeList where srt.ServiceRequest.Id == serviceRequest.Id && srt.TypeId == 11 select srt.Value).SingleOrDefault();
 539:   
 540:                          if (Ia.Ngn.Cl.Model.Business.Service.NumberIsWithinAllowedDomainList(changedServiceNumber))
 541:                          {
 542:                              serviceRequestService.Id = Ia.Ngn.Cl.Model.Business.ServiceRequestService.ServiceRequestServiceId(changedServiceNumber, serviceType);
 543:                              serviceRequestService.Service = changedServiceNumber;
 544:                          }
 545:                          else
 546:                          {
 547:   
 548:                          }
 549:                      }
 550:                  }
 551:                  else if (serviceRequest.ServiceId == 43)
 552:                  {
 553:                      // <service id="43" arabicName="تنازل" />
 554:   
 555:                      // Id    Number    Serial    Status    RequestDateTime    CustomerId    CustomerName    CustomerCategoryId    CustomerAddress    ServiceId    ServiceCategoryId    Balance    Created    Updated    UserId    ServiceRequestService_Id
 556:                      // 1821798    24573325    1    2005    2015-08-20 00:00:00.000    1500989    محمد مهاوش سويد السعيدي    1    الجهراء الجهراء,قطعة 5 شارع 1 جادة قسائم العثمان قسيمة الا زرق 29, منزل 529    43    3    0    2015-08-20 20:41:04.403    2015-08-20 20:41:04.403    00000000-0000-0000-0000-000000000000    NULL
 557:                      // 1821312    25234142    0    2005    2015-08-19 00:00:00.000    1476656    رنا فيصل عبدالرزاق الخالد    1    حولى الشهداء,قطعة 1 شارع 3, منزل 501    43    3    0    2015-08-19 11:13:32.827    2015-08-19 11:13:32.827    00000000-0000-0000-0000-000000000000    NULL
 558:   
 559:                      // No SRT records. Nothing to do.
 560:                  }
 561:                  else
 562:                  {
 563:                      //if (recordExists)
 564:                      //{
 565:                      switch (serviceRequest.ServiceId)
 566:                      {
 567:                          // below: <service id="40" arabicName="رفع خط" />
 568:                          case 40:
 569:                              {
 570:                                  serviceRequestService.Provisioned = false;
 571:                                  // serviceRequestService = null;
 572:                                  break;
 573:                              }
 574:   
 575:                          // below: <service id="12" arabicName="خدمة الإنتظار" />
 576:                          case 12: { serviceRequestService.CallWaiting = true; break; }
 577:   
 578:                          // below: <service id="68" arabicName="إيقاف خدمة الإنتظار" />
 579:                          case 68: { serviceRequestService.CallWaiting = false; break; }
 580:   
 581:                          // below: <service id="13" arabicName="التحكم بالصفر الدولي" />
 582:                          case 13: { serviceRequestService.InternationalCallingUserControlled = true; break; }
 583:   
 584:                          // below: <service id="67" arabicName="وقف التحكم بالصفر" />
 585:                          case 67: { serviceRequestService.InternationalCallingUserControlled = false; break; }
 586:   
 587:                          // below: <service id="14" arabicName="كاشف رقم" />
 588:                          case 14: { serviceRequestService.CallerId = true; break; }
 589:   
 590:                          // below: <service id="66" arabicName="إيقاف كاشف" />
 591:                          case 66: { serviceRequestService.CallerId = false; break; }
 592:   
 593:                          // below: <service id="5" arabicName="تحويل مكالمات" />
 594:                          case 5: { serviceRequestService.CallForwarding = true; break; }
 595:   
 596:                          // below: <service id="75" arabicName="إيقاف التحويل" />
 597:                          case 75: { serviceRequestService.CallForwarding = false; break; }
 598:   
 599:                          // below: <service id="20" arabicName="النداء الآلي" />
 600:                          case 20: { serviceRequestService.InternationalCalling = true; break; }
 601:   
 602:                          // below: <service id="19" arabicName="قطع النداء الآلي" />
 603:                          case 19: { serviceRequestService.InternationalCalling = false; break; }
 604:   
 605:                          // below: <service id="38" arabicName="مجموعة الخدمات" />
 606:                          case 38:
 607:                              {
 608:                                  serviceRequestService.CallerId = true;
 609:   
 610:                                  serviceRequestService.AlarmCall = true;
 611:                                  serviceRequestService.WakeupCall = true;
 612:   
 613:                                  //serviceRequestService.InternationalCallingUserControlled = true;
 614:                                  serviceRequestService.CallWaiting = true;
 615:                                  serviceRequestService.CallForwarding = true;
 616:                                  serviceRequestService.ConferenceCall = true;
 617:                                  break;
 618:                              }
 619:   
 620:                          // below: <service id="62" arabicName="إيقاف مجموعة الخدمات" />
 621:                          case 62:
 622:                              {
 623:                                  serviceRequestService.CallerId = false;
 624:   
 625:                                  serviceRequestService.AlarmCall = false;
 626:                                  serviceRequestService.WakeupCall = false;
 627:   
 628:                                  //serviceRequestService.InternationalCallingUserControlled = false;
 629:                                  serviceRequestService.CallWaiting = false;
 630:                                  serviceRequestService.CallForwarding = false;
 631:                                  serviceRequestService.ConferenceCall = false;
 632:                                  break;
 633:                              }
 634:   
 635:                          // below: <service id="52" arabicName="قطع حرارة" />
 636:                          case 52: { serviceRequestService.CallBarring = true; break; }
 637:   
 638:                          // below: <service id="53" arabicName="اعادة حرارة" />
 639:                          case 53: { serviceRequestService.CallBarring = false; break; }
 640:   
 641:                          // below: <service id="7" arabicName="منع الإتصال" />
 642:                          case 7: { serviceRequestService.BarringOfAllOutgoingCalls = true; break; }
 643:   
 644:                          // below: <service id="73" arabicName="إيقاف منع الإتصال" />
 645:                          case 73: { serviceRequestService.BarringOfAllOutgoingCalls = false; break; }
 646:   
 647:                          // below: <service id="8" arabicName="ايقاف استقبال" />
 648:                          case 8: { serviceRequestService.BarringOfAllIncomingCalls = true; break; }
 649:   
 650:                          // below: <service id="72" arabicName="رد استقبال" />
 651:                          case 72: { serviceRequestService.BarringOfAllIncomingCalls = false; break; }
 652:   
 653:                          // below: <service id="10" arabicName="خدمة الإيقاظ" />
 654:                          case 10:
 655:                              {
 656:                                  serviceRequestService.AlarmCall = true;
 657:                                  serviceRequestService.WakeupCall = true;
 658:                                  break;
 659:                              }
 660:   
 661:                          // below: <service id="70" arabicName="إيقاف خدمة الإيقاظ" />
 662:                          case 70:
 663:                              {
 664:                                  serviceRequestService.AlarmCall = false;
 665:                                  serviceRequestService.WakeupCall = false;
 666:                                  break;
 667:                              }
 668:   
 669:                          // below: <service id="6" arabicName="استشارة" />
 670:                          case 6: { serviceRequestService.ConferenceCall = true; break; }
 671:   
 672:                          // below: <service id="74" arabicName="إيقاف استشارة" />
 673:                          case 74: { serviceRequestService.ConferenceCall = false; break; }
 674:   
 675:                          // below: <service id="11" arabicName="إختصار الرقم" />
 676:                          case 11: { serviceRequestService.AbbriviatedCalling = true; break; }
 677:   
 678:                          // below: <service id="69" arabicName="إيقاف إختصار الرقم" />
 679:                          case 69: { serviceRequestService.AbbriviatedCalling = false; break; }
 680:   
 681:                          // ???
 682:                          // below: <service id="55" arabicName="مفتاح بدالة" />
 683:                          //case 55: { srs.?? = false; break; }
 684:   
 685:                          // below: <if id="60" name_ar="إيقاف مفتاح بدالة"...
 686:                          //case 60: { dr["pbx_dn_key"] = DBNull.Value; break; }
 687:   
 688:                          // below: <if id="56" name_ar="فرع بدالة"...
 689:                          //case 56:
 690:                          //    {
 691:                          //        u = r["pbx_dn"].ToString();
 692:                          //        u = Regex.Replace(u, @"\/\d", ""); // remove that last /0
 693:                          //        pbx_dn = int.Parse(Ia.Ngn.Cs.This.Digit_7_to_8(u));
 694:                          //        dr["pbx_dn_key"] = pbx_dn;
 695:                          //        break;
 696:                          //    }
 697:   
 698:                          // below: <if id="59" name_ar="إيقاف فرع بدالة"...
 699:                          //case 59: { dr["pbx_dn_key"] = DBNull.Value; break; }
 700:   
 701:                          default:
 702:                              {
 703:                                  log.AppendLine("TelephonyService(): For ServiceRequest.Number=" + serviceRequest.Number + " ServiceId=" + serviceRequest.ServiceId + " was not recognized. ");
 704:                                  break;
 705:                              }
 706:                      }
 707:                      //}
 708:                      //else
 709:                      //{
 710:                      //    log.AppendLine("TelephonyService(): For ServiceRequest.Number=" + serviceRequest.Number + " ServiceId=" + serviceRequest.ServiceId + " record did not exist before this step. ");
 711:                      //}
 712:                  }
 713:              }
 714:              else
 715:              {
 716:                  // below: sent provisioned to false
 717:                  serviceRequestService.Provisioned = false;
 718:                  lastRequestDateTime = DateTime.MinValue;
 719:                  //serviceRequestService = null;
 720:              }
 721:   
 722:              if(serviceRequestService.LastRequestDateTime < lastRequestDateTime) serviceRequestService.LastRequestDateTime = lastRequestDateTime;
 723:          }
 724:   
 725:          ////////////////////////////////////////////////////////////////////////////
 726:          ////////////////////////////////////////////////////////////////////////////
 727:      }
 728:   
 729:      ////////////////////////////////////////////////////////////////////////////
 730:      ////////////////////////////////////////////////////////////////////////////
 731:  }