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

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

Service Request Ont Detail support class for Fixed Telecommunications Network (FTN) data model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Linq;
    5:  
    6: namespace Ia.Ftn.Cl.Models.Data
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     /// Service Request Ont Detail support class for Fixed Telecommunications Network (FTN) data model.
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2017-2018 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     /// </remarks> 
   17:     public class ServiceRequestOntDetail
   18:     {
   19:         private const int LengthOfRequestOntIdRange = 100;
   20:         private static Dictionary<string, string> ontAccessIdToOntAccessNameDictionary = new Dictionary<string, string>();
   21:         private static Queue<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>();
   22:         private static Queue<Tuple<string, string>> serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>();
   23:  
   24:         ////////////////////////////////////////////////////////////////////////////
   25:  
   26:         /// <summary>
   27:         ///
   28:         /// </summary>
   29:         public ServiceRequestOntDetail() { }
   30:  
   31:         ////////////////////////////////////////////////////////////////////////////    
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public static void ServiceRequestOntDetailCreateAndDeleteList(out List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailCreateList, out List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailDeleteList)
   37:         {
   38:             int serviceType, servicePosition;
   39:             string id;
   40:             DateTime now;
   41:             Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail;
   42:             Ia.Ftn.Cl.Models.ServiceRequestOnt serviceRequestOnt;
   43:             List<Ia.Ftn.Cl.Models.Business.ServiceServiceRequestOnt> insertList, deleteList;
   44:  
   45:             now = DateTime.UtcNow.AddHours(3);
   46:  
   47:             Ia.Ftn.Cl.Models.Data.Service.DifferenceBetweenServiceAndServiceRequestOntDetailsOfTheCustomerDepartmentDatabase(out insertList, out deleteList);
   48:  
   49:             serviceRequestOntDetailCreateList = new List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>(insertList.Count);
   50:  
   51:             foreach (Ia.Ftn.Cl.Models.Business.ServiceServiceRequestOnt ssro in insertList)
   52:             {
   53:                 serviceType = ssro.ServiceType;
   54:                 servicePosition = ssro.ServicePosition;
   55:                 serviceRequestOnt = ssro.ServiceRequestOnt;
   56:  
   57:                 id = Ia.Ftn.Cl.Models.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
   58:  
   59:                 serviceRequestOntDetail = new Ia.Ftn.Cl.Models.ServiceRequestOntDetail()
   60:                 {
   61:                     Id = id,
   62:                     Service = ssro.Service,
   63:                     ServiceType = serviceType,
   64:                     ServicePosition = servicePosition,
   65:                     ServiceRequestOnt = serviceRequestOnt,
   66:                     Created = now,
   67:                     Updated = now
   68:                 };
   69:  
   70:                 serviceRequestOntDetailCreateList.Add(serviceRequestOntDetail);
   71:             }
   72:  
   73:  
   74:             serviceRequestOntDetailDeleteList = new List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>(deleteList.Count);
   75:  
   76:             foreach (Ia.Ftn.Cl.Models.Business.ServiceServiceRequestOnt ssro in deleteList)
   77:             {
   78:                 serviceType = ssro.ServiceType;
   79:                 servicePosition = ssro.ServicePosition;
   80:                 serviceRequestOnt = ssro.ServiceRequestOnt;
   81:  
   82:                 id = Ia.Ftn.Cl.Models.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, 0, 0);
   83:  
   84:                 // this is a dummy non-existant ServiceRequestOntDetail
   85:                 serviceRequestOntDetail = new Ia.Ftn.Cl.Models.ServiceRequestOntDetail()
   86:                 {
   87:                     Id = id,
   88:                     Service = ssro.Service,
   89:                     ServiceType = serviceType,
   90:                     ServicePosition = servicePosition,
   91:                     ServiceRequestOnt = serviceRequestOnt,
   92:                     Created = now,
   93:                     Updated = now
   94:                 };
   95:  
   96:                 serviceRequestOntDetailDeleteList.Add(serviceRequestOntDetail);
   97:             }
   98:         }
   99:  
  100:         ////////////////////////////////////////////////////////////////////////////    
  101:  
  102:         /// <summary>
  103:         ///
  104:         /// </summary>
  105:         public static Ia.Ftn.Cl.Models.ServiceRequestOntDetail ServiceRequestOntDetailNotUpdatedInCustomerDepartmentDatabase(out Ia.Cl.Models.Result result)
  106:         {
  107:             int serviceType, servicePosition;
  108:             string id;
  109:             DateTime now;
  110:             Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail;
  111:             Ia.Ftn.Cl.Models.ServiceRequestOnt serviceRequestOnt;
  112:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailList;
  113:             List<Ia.Ftn.Cl.Models.Business.ServiceServiceRequestOnt> list;
  114:  
  115:             result = new Ia.Cl.Models.Result();
  116:             now = DateTime.UtcNow.AddHours(3);
  117:  
  118:             if (serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count == 0)
  119:             {
  120:                 serviceRequestOntDetailList = new List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>();
  121:  
  122:                 list = Ia.Ftn.Cl.Models.Data.Service.ServiceServiceRequestOntDetailWithMismatchedInformationInServiceRequestOntDetailList();
  123:  
  124:                 foreach (Ia.Ftn.Cl.Models.Business.ServiceServiceRequestOnt ssro in list)
  125:                 {
  126:                     serviceType = ssro.ServiceType;
  127:                     servicePosition = ssro.ServicePosition;
  128:                     serviceRequestOnt = ssro.ServiceRequestOnt;
  129:  
  130:                     id = Ia.Ftn.Cl.Models.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOnt.Id, serviceType, servicePosition);
  131:  
  132:                     serviceRequestOntDetail = new Ia.Ftn.Cl.Models.ServiceRequestOntDetail()
  133:                     {
  134:                         Id = id,
  135:                         Service = ssro.Service,
  136:                         ServiceType = serviceType,
  137:                         ServicePosition = servicePosition,
  138:                         ServiceRequestOnt = serviceRequestOnt,
  139:                         Created = now,
  140:                         Updated = now
  141:                     };
  142:  
  143:                     serviceRequestOntDetailList.Add(serviceRequestOntDetail);
  144:                 }
  145:  
  146:                 serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue = new Queue<Ia.Ftn.Cl.Models.ServiceRequestOntDetail>(serviceRequestOntDetailList);
  147:             }
  148:  
  149:             if (serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count > 0)
  150:             {
  151:                 serviceRequestOntDetail = serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Dequeue();
  152:  
  153:                 result.AddSuccess("(" + serviceRequestOntDetail.ServiceRequestOnt.Name + "/" + serviceRequestOntDetailNotUpdatedInCustomerDepartmentDatabaseQueue.Count + ")");
  154:             }
  155:             else
  156:             {
  157:                 serviceRequestOntDetail = null;
  158:  
  159:                 result.AddSuccess("No mismatch in properties between FTN and billing database. ");
  160:             }
  161:  
  162:             return serviceRequestOntDetail;
  163:         }
  164:  
  165:         ////////////////////////////////////////////////////////////////////////////    
  166:  
  167:         /// <summary>
  168:         ///
  169:         /// </summary>
  170:         public static Tuple<string, string> ServiceRequestOntDetailIdStartEndRangeManager(out Ia.Cl.Models.Result result)
  171:         {
  172:             string startAccessName, endAccessName;
  173:             Tuple<string, string> tuple;
  174:             List<string> ontListAccessIdList;
  175:             List<Tuple<string, string>> tupleList;
  176:  
  177:             result = new Ia.Cl.Models.Result();
  178:  
  179:             if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count == 0)
  180:             {
  181:                 ontListAccessIdList = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdList;
  182:                 ontAccessIdToOntAccessNameDictionary = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntAccessNameDictionary;
  183:  
  184:                 tupleList = Ia.Cl.Models.Default.OptimizedStartEndRangeTupleList(ontListAccessIdList, LengthOfRequestOntIdRange);
  185:  
  186:                 serviceRequestAccessIdOptimizedStartEndRangeTupleQueue = new Queue<Tuple<string, string>>(tupleList);
  187:             }
  188:  
  189:             if (serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count > 0)
  190:             {
  191:                 tuple = serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Dequeue();
  192:  
  193:                 // debug
  194:                 //tuple = new Tuple<string, string>("104010301512009", "104010301512019");
  195:  
  196:                 startAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item1];
  197:                 endAccessName = ontAccessIdToOntAccessNameDictionary[tuple.Item2];
  198:  
  199:                 result.AddSuccess("(" + startAccessName + " - " + endAccessName + "/" + serviceRequestAccessIdOptimizedStartEndRangeTupleQueue.Count + ")");
  200:             }
  201:             else
  202:             {
  203:                 tuple = null;
  204:  
  205:                 result.AddWarning("(0-0 0/0)");
  206:             }
  207:  
  208:             return tuple;
  209:         }
  210:  
  211:         ////////////////////////////////////////////////////////////////////////////    
  212:  
  213:         /// <summary>
  214:         ///
  215:         /// </summary>
  216:         public static string OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(Tuple<string, string> startEndRangeTuple)
  217:         {
  218:             return OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(startEndRangeTuple.Item1, startEndRangeTuple.Item2);
  219:         }
  220:  
  221:         ////////////////////////////////////////////////////////////////////////////    
  222:  
  223:         /// <summary>
  224:         ///
  225:         /// </summary>
  226:         public static string OracleSqlCommandSelectProperServiceRequestOntDetailRecordList(string start, string end)
  227:         {
  228:             string sql;
  229:  
  230:             // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
  231:  
  232:             if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end)) sql = @"select id, line_ser, ethernet_ser, phone_no, internet_srv_no from ont_details where (id >= " + start + " and id <= " + end + @") order by id asc";
  233:             else sql = string.Empty;
  234:  
  235:             return sql;
  236:         }
  237:  
  238:         ////////////////////////////////////////////////////////////////////////////    
  239:  
  240:         /// <summary>
  241:         ///
  242:         /// </summary>
  243:         public static string OracleSqlCommandInsertServiceRequestOntDetailRecord(Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail)
  244:         {
  245:             int line_ser, ethernet_ser, phone_no;
  246:             string sql, internet_srv_no;
  247:  
  248:             // convert ServiceRequestOntDetail to the format needed in ONT_DETAILS
  249:  
  250:             if (serviceRequestOntDetail.ServiceType == 1)
  251:             {
  252:                 line_ser = serviceRequestOntDetail.ServicePosition;
  253:                 ethernet_ser = 0;
  254:                 phone_no = int.Parse(serviceRequestOntDetail.Service);
  255:                 internet_srv_no = string.Empty;
  256:             }
  257:             else //if (serviceRequestOntDetail.ServiceType == 2)
  258:             {
  259:                 line_ser = 0;
  260:                 ethernet_ser = serviceRequestOntDetail.ServicePosition;
  261:                 phone_no = 0;
  262:                 internet_srv_no = serviceRequestOntDetail.Service;
  263:             }
  264:  
  265:             sql = @"insert into ONT_DETAILS(ID, LINE_SER, ETHERNET_SER, PHONE_NO, INTERNET_SRV_NO) values "
  266:                          + @"("
  267:                          + @"N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote;,"
  268:                          + @"N&quote;" + line_ser + @"&quote;,"
  269:                          + @"N&quote;" + ethernet_ser + @"&quote;,"
  270:                          + @"N&quote;" + phone_no + @"&quote;,"
  271:                          + @"N&quote;" + internet_srv_no + @"&quote;"
  272:                                                      + @")";
  273:  
  274:             sql = sql.Replace("'", "''");
  275:             sql = sql.Replace("&quote;", "'");
  276:  
  277:             return sql;
  278:         }
  279:  
  280:         ////////////////////////////////////////////////////////////////////////////    
  281:  
  282:         /// <summary>
  283:         ///
  284:         /// </summary>
  285:         public static string OracleSqlCommandUpdateServiceRequestOntDetailRecord(Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail)
  286:         {
  287:             int line_ser, ethernet_ser, phone_no;
  288:             string sql, internet_srv_no;
  289:  
  290:             // convert ServiceRequestOntDetail to the format needed in ONT_DETAILS
  291:  
  292:             if (serviceRequestOntDetail.ServiceType == 1)
  293:             {
  294:                 line_ser = serviceRequestOntDetail.ServicePosition;
  295:                 ethernet_ser = 0;
  296:                 phone_no = int.Parse(serviceRequestOntDetail.Service);
  297:                 internet_srv_no = string.Empty;
  298:             }
  299:             else //if (serviceRequestOntDetail.ServiceType == 2)
  300:             {
  301:                 line_ser = 0;
  302:                 ethernet_ser = serviceRequestOntDetail.ServicePosition;
  303:                 phone_no = 0;
  304:                 internet_srv_no = serviceRequestOntDetail.Service;
  305:             }
  306:  
  307:             sql = @"update ONT_DETAILS set LINE_SER = " + line_ser + @", "
  308: + @"ETHERNET_SER = " + ethernet_ser + @", "
  309: + @"PHONE_NO = " + phone_no + @", "
  310: + @"INTERNET_SRV_NO = N&quote;" + internet_srv_no + @"&quote; "
  311: + @" where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote;";
  312:  
  313:             sql = sql.Replace("'", "''");
  314:             sql = sql.Replace("&quote;", "'");
  315:  
  316:             return sql;
  317:         }
  318:  
  319:         ////////////////////////////////////////////////////////////////////////////    
  320:  
  321:         /// <summary>
  322:         ///
  323:         /// </summary>
  324:         public static string OracleSqlCommandDeleteServiceRequestOntDetailRecord(Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail)
  325:         {
  326:             string sql;
  327:  
  328:             // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
  329:  
  330:             // sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and LINE_SER = N&quote;" + serviceRequestOntDetail.ServicePosition + @"&quote;";
  331:             // sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and PHONE_NO = " + serviceRequestOntDetail.Service + @"";
  332:             sql = @"delete from ONT_DETAILS where ID = N&quote;" + serviceRequestOntDetail.ServiceRequestOnt.Id + @"&quote; and (PHONE_NO = " + serviceRequestOntDetail.Service + @" or LINE_SER = " + serviceRequestOntDetail.ServicePosition + @")";
  333:  
  334:             // delete from ONT_DETAILS where ID = N'1060210011518004' and (PHONE_NO = 23751510 or LINE_SER = 1)
  335:  
  336:             sql = sql.Replace("'", "''");
  337:             sql = sql.Replace("&quote;", "'");
  338:  
  339:             return sql;
  340:         }
  341:  
  342:         ////////////////////////////////////////////////////////////////////////////    
  343:  
  344:         /// <summary>
  345:         ///
  346:         /// </summary>
  347:         public static string OracleSqlCommandDeleteServiceRequestOntDetailRecordByService(string service)
  348:         {
  349:             string sql;
  350:  
  351:             sql = @"delete from ONT_DETAILS where PHONE_NO = " + service + @"";
  352:  
  353:             sql = sql.Replace("'", "''");
  354:             sql = sql.Replace("&quote;", "'");
  355:  
  356:             return sql;
  357:         }
  358:  
  359:         ////////////////////////////////////////////////////////////////////////////    
  360:  
  361:         /// <summary>
  362:         ///
  363:         /// </summary>
  364:         public static string OracleSqlCommandDeleteServiceRequestOntDetailRecord(string sqlWhereString)
  365:         {
  366:             string sql;
  367:  
  368:             // Note that ONT_DETAILS.ID is just the ServiceRequestOnt.Id
  369:  
  370:             sql = @"delete from ONT_DETAILS where " + sqlWhereString;
  371:  
  372:             return sql;
  373:         }
  374:  
  375:         ////////////////////////////////////////////////////////////////////////////
  376:  
  377:         /// <summary>
  378:         ///
  379:         /// </summary>
  380:         public static Ia.Cl.Models.Result UpdateForServiceRequestOntIdRangeWithOutputDataTable(DataTable dataTable, Tuple<string, string> startEndRangeTuple)
  381:         {
  382:             bool validRecord; // isUpdated;
  383:             int serviceType, servicePosition, readItemCount, existingItemCount, insertedItemCount, updatedItemCount, deletedItemCount;
  384:             string service, r, start, end, serviceRequestOntId, serviceRequestOntDetailId;
  385:             Ia.Cl.Models.Result result;
  386:             Ia.Ftn.Cl.Models.ServiceRequestOntDetail serviceRequestOntDetail, newServiceRequestOntDetail;
  387:             Ia.Ftn.Cl.Models.ServiceRequestOnt serviceRequestOnt;
  388:             List<string> insertedItemIdList, newServiceRequestOntDetailIdList;
  389:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailList;
  390:  
  391:             validRecord = false; // isUpdated = false;
  392:             serviceType = servicePosition = 0;
  393:             readItemCount = existingItemCount = insertedItemCount = updatedItemCount = deletedItemCount = 0;
  394:             service = r = string.Empty;
  395:  
  396:             result = new Ia.Cl.Models.Result();
  397:             insertedItemIdList = new List<string>();
  398:             newServiceRequestOntDetailIdList = new List<string>();
  399:  
  400:             if (dataTable != null)
  401:             {
  402:                 using (var db = new Ia.Ftn.Cl.Db())
  403:                 {
  404:                     readItemCount = dataTable.Rows.Count;
  405:  
  406:                     start = startEndRangeTuple.Item1;
  407:                     end = startEndRangeTuple.Item2;
  408:  
  409:                     serviceRequestOntDetailList = Ia.Ftn.Cl.Models.Data.ServiceRequestOntDetail.ReadListWithinServiceRequestOntIdRange(start, end);
  410:                     existingItemCount = serviceRequestOntDetailList.Count;
  411:  
  412:                     insertedItemIdList = new List<string>(dataTable.Rows.Count + 1);
  413:  
  414:                     int line_ser, ethernet_ser, phone_no;
  415:                     string internet_srv_no;
  416:  
  417:                     foreach (DataRow dataRow in dataTable.Rows)
  418:                     {
  419:                         serviceRequestOntId = dataRow["Id"].ToString();
  420:  
  421:                         if (int.TryParse(dataRow["line_ser"].ToString(), out line_ser) && int.TryParse(dataRow["ethernet_ser"].ToString(), out ethernet_ser) && int.TryParse(dataRow["phone_no"].ToString(), out phone_no))
  422:                         {
  423:                             internet_srv_no = dataRow["internet_srv_no"].ToString();
  424:  
  425:                             // I will convert from the Customer department database convention to my own
  426:  
  427:                             if (line_ser != 0)
  428:                             {
  429:                                 serviceType = Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService;
  430:                                 service = phone_no.ToString();
  431:                                 servicePosition = line_ser;
  432:  
  433:                                 validRecord = true;
  434:                             }
  435:                             else if (ethernet_ser != 0)
  436:                             {
  437:                                 serviceType = 2; //?? maybe remove ethernet data completely
  438:                                 service = internet_srv_no;
  439:                                 servicePosition = ethernet_ser;
  440:  
  441:                                 validRecord = true;
  442:                             }
  443:                             else
  444:                             {
  445:                                 validRecord = false;
  446:                             }
  447:                         }
  448:                         else
  449:                         {
  450:                             validRecord = false;
  451:                         }
  452:  
  453:                         if (validRecord)
  454:                         {
  455:                             serviceRequestOntDetailId = Ia.Ftn.Cl.Models.Business.ServiceRequestOntDetail.ServiceRequestOntDetailId(serviceRequestOntId, serviceType, servicePosition);
  456:  
  457:                             serviceRequestOnt = (from sro in db.ServiceRequestOnts where sro.Id == serviceRequestOntId select sro).SingleOrDefault();
  458:  
  459:                             serviceRequestOntDetail = (from srod in db.ServiceRequestOntDetails where srod.Id == serviceRequestOntDetailId select srod).SingleOrDefault();
  460:  
  461:                             newServiceRequestOntDetail = new Ia.Ftn.Cl.Models.ServiceRequestOntDetail()
  462:                             {
  463:                                 Id = serviceRequestOntDetailId,
  464:                                 ServiceType = serviceType,
  465:                                 Service = service,
  466:                                 ServicePosition = servicePosition,
  467:                                 Created = DateTime.UtcNow.AddHours(3),
  468:                                 Updated = DateTime.UtcNow.AddHours(3),
  469:                                 ServiceRequestOnt = serviceRequestOnt,
  470:                             };
  471:  
  472:                             if (serviceRequestOntDetail == null)
  473:                             {
  474:                                 insertedItemIdList.Add(serviceRequestOntDetailId);
  475:  
  476:                                 db.ServiceRequestOntDetails.Add(newServiceRequestOntDetail);
  477:  
  478:                                 insertedItemCount++;
  479:                             }
  480:                             else
  481:                             {
  482:                                 // below: copy values from newServiceRequestOntDetail to serviceRequestOntDetail
  483:  
  484:                                 if (serviceRequestOntDetail.Update(newServiceRequestOntDetail))
  485:                                 {
  486:                                     db.ServiceRequestOntDetails.Attach(serviceRequestOntDetail);
  487:                                     db.Entry(serviceRequestOntDetail).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  488:  
  489:                                     updatedItemCount++;
  490:                                 }
  491:                             }
  492:  
  493:                             // below: this will enable the removal of records that don't have a valid record
  494:                             newServiceRequestOntDetailIdList.Add(serviceRequestOntDetailId);
  495:                         }
  496:                         else
  497:                         {
  498:  
  499:                         }
  500:                     }
  501:  
  502:                     //db.SaveChanges(); // I don't know the problem here keep this due to some strange errors
  503:  
  504:                     // below: this function will remove values that were not present in the reading
  505:                     if (serviceRequestOntDetailList.Count > 0)
  506:                     {
  507:                         foreach (Ia.Ftn.Cl.Models.ServiceRequestOntDetail srod in serviceRequestOntDetailList)
  508:                         {
  509:                             if (!newServiceRequestOntDetailIdList.Contains(srod.Id))
  510:                             {
  511:                                 serviceRequestOntDetail = (from srod2 in db.ServiceRequestOntDetails where srod2.Id == srod.Id select srod2).SingleOrDefault();
  512:  
  513:                                 if (serviceRequestOntDetail != null)
  514:                                 {
  515:                                     db.ServiceRequestOntDetails.Remove(serviceRequestOntDetail);
  516:                                     deletedItemCount++;
  517:                                 }
  518:                             }
  519:                         }
  520:  
  521:                         //db.SaveChanges(); // keep this due to some strange errors
  522:                     }
  523:  
  524:                     db.SaveChanges(); // keep this due to some strange errors
  525:  
  526:                     //if (insertedItemCount != 0 || updatedItemCount != 0 || deletedItemCount != 0) isUpdated = true;
  527:                     //else isUpdated = false;
  528:  
  529:                     result.AddSuccess("(" + readItemCount + "/" + existingItemCount + "/" + insertedItemCount + "," + updatedItemCount + "," + deletedItemCount + ") ");
  530:                 }
  531:             }
  532:             else
  533:             {
  534:                 result.AddWarning("(dataTable == null/?/?) ");
  535:             }
  536:  
  537:             return result;
  538:         }
  539:  
  540:         ////////////////////////////////////////////////////////////////////////////
  541:  
  542:         /// <summary>
  543:         ///
  544:         /// </summary>
  545:         public static bool DeleteByAccessId(string accessId, out string result)
  546:         {
  547:             bool recordExisted;
  548:  
  549:             recordExisted = false;
  550:             result = string.Empty;
  551:  
  552:             using (var db = new Ia.Ftn.Cl.Db())
  553:             {
  554:                 //--delete from ServiceRequestOntDetails where ServiceRequestOnts _Id = (select id from ServiceRequestOnts where Access_Id = '1040101010040004')
  555:  
  556:                 var v = (from srod in db.ServiceRequestOntDetails
  557:                          join sro in db.ServiceRequestOnts on srod.ServiceRequestOnt.Id equals sro.Id
  558:                          where sro.Access.Id == accessId
  559:                          select srod).FirstOrDefault();
  560:  
  561:                 if (v != null)
  562:                 {
  563:                     db.ServiceRequestOntDetails.Remove(v);
  564:                     db.SaveChanges();
  565:  
  566:                     recordExisted = true;
  567:                 }
  568:                 else recordExisted = false;
  569:             }
  570:  
  571:             return recordExisted;
  572:         }
  573:  
  574:         ////////////////////////////////////////////////////////////////////////////
  575:  
  576:         /// <summary>
  577:         ///
  578:         /// </summary>
  579:         public static List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> ReadListWithinIdRange(string start, string end)
  580:         {
  581:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailList;
  582:  
  583:             using (var db = new Ia.Ftn.Cl.Db())
  584:             {
  585:                 serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails where srod.Id.CompareTo(start) >= 0 && srod.Id.CompareTo(end) <= 0 select srod).ToList();
  586:             }
  587:  
  588:             return serviceRequestOntDetailList;
  589:         }
  590:  
  591:         ////////////////////////////////////////////////////////////////////////////
  592:  
  593:         /// <summary>
  594:         ///
  595:         /// </summary>
  596:         public static List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> ReadListWithinServiceRequestOntIdRange(string start, string end)
  597:         {
  598:             List<Ia.Ftn.Cl.Models.ServiceRequestOntDetail> serviceRequestOntDetailList;
  599:  
  600:             using (var db = new Ia.Ftn.Cl.Db())
  601:             {
  602:                 serviceRequestOntDetailList = (from srod in db.ServiceRequestOntDetails
  603:                                                where srod.ServiceRequestOnt.Id.CompareTo(start) >= 0 && srod.ServiceRequestOnt.Id.CompareTo(end) <= 0
  604:                                                select srod).ToList();
  605:             }
  606:  
  607:             return serviceRequestOntDetailList;
  608:         }
  609:  
  610:         ////////////////////////////////////////////////////////////////////////////    
  611:         ////////////////////////////////////////////////////////////////////////////    
  612:     }
  613:  
  614:     ////////////////////////////////////////////////////////////////////////////
  615:     ////////////////////////////////////////////////////////////////////////////
  616: }