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

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

    1: using Microsoft.AspNetCore.Identity;
    2: using Microsoft.AspNetCore.Mvc.Rendering;
    3: using Microsoft.EntityFrameworkCore;
    4: using System.Data;
    5: using System.Net;
    6: using System.Text.RegularExpressions;
    7:  
    8: namespace Ia.Ftn.Wa.Models.Maintenance
    9: {
   10:     ////////////////////////////////////////////////////////////////////////////
   11:  
   12:     /// <summary publish="true">
   13:     ///
   14:     /// </summary>
   15:     /// 
   16:     /// <remarks> 
   17:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   18:     /// </remarks> 
   19:     public static class Bulk
   20:     {
   21:         private static List<string> queueList;
   22:         private static List<Ia.Ftn.Cl.Models.Business.ServiceNddOntAccessName> serviceAccessNameList;
   23:         private static List<Ia.Ftn.Cl.Models.Business.ServiceNddOntAccessNameAddress> serviceAccessNameAddressList;
   24:  
   25:         ////////////////////////////////////////////////////////////////////////////
   26:  
   27:         /// <summary>
   28:         ///
   29:         /// </summary>
   30:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Maintenance.BulkViewModel bulkViewModel, UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, Ia.Ftn.Cl.Models.StaffIdentityUser currentStaffIdentityUser)
   31:         {
   32:  
   33:         }
   34:  
   35:         ////////////////////////////////////////////////////////////////////////////
   36:  
   37:         /// <summary>
   38:         ///
   39:         /// </summary>
   40:         public static void Post(ref Ia.Ftn.Wa.Models.Maintenance.BulkViewModel bulkViewModel, UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, Ia.Ftn.Cl.Models.StaffIdentityUser currentStaffIdentityUser)
   41:         {
   42:             bool isMigrated, noService, isDuplicate, isFiber, notProvisioned;
   43:             int totalCount, migratedCount, noServiceCount, isDuplicateCount, isFiberCount, notProvisionedCount;
   44:             string input, rawInput, note;
   45:  
   46:             List<string> serviceList;
   47:  
   48:             var result = new Ia.Cl.Models.Result();
   49:  
   50:             bulkViewModel.Result = new Ia.Cl.Models.Result();
   51:  
   52:             rawInput = WebUtility.HtmlDecode(bulkViewModel.TextTextArea);
   53:  
   54:             if (!string.IsNullOrEmpty(rawInput))
   55:             {
   56:                 if (!string.IsNullOrEmpty(bulkViewModel.SelectedValue))
   57:                 {
   58:                     input = rawInput.Trim();
   59:  
   60:                     if (bulkViewModel.SelectedValue == "insertServiceAccessIntoQueue")
   61:                     {
   62:                         Ia.Ftn.Cl.Models.Business.Maintenance.Default.BulkQueue(input, out result);
   63:                     }
   64:                     else if (bulkViewModel.SelectedValue == "listAccessNameForService")
   65:                     {
   66:                         Ia.Ftn.Cl.Models.Business.Maintenance.Find.BulkSearch(input, out serviceAccessNameList, out result);
   67:  
   68:                         if (result.IsSuccessful)
   69:                         {
   70:                             bulkViewModel.ServiceNddOntAccessNameList = serviceAccessNameList;
   71:                         }
   72:                         else
   73:                         {
   74:                         }
   75:                     }
   76:                     else if (bulkViewModel.SelectedValue == "listAccessNameAndAddressForService")
   77:                     {
   78:                         Ia.Ftn.Cl.Models.Business.Maintenance.Find.BulkSearch(input, out serviceAccessNameAddressList, out result);
   79:  
   80:                         if (result.IsSuccessful)
   81:                         {
   82:                             bulkViewModel.ServiceNddOntAccessNameAddressList = serviceAccessNameAddressList;
   83:                         }
   84:                         else
   85:                         {
   86:                         }
   87:                     }
   88:                     else if (bulkViewModel.SelectedValue == "list2ForService")
   89:                     {
   90:                         totalCount = migratedCount = noServiceCount = isDuplicateCount = isFiberCount = notProvisionedCount = 0;
   91:  
   92:                         var matchCollection = Regex.Matches(input, @"\d{8}");
   93:  
   94:                         if (matchCollection.Count > 0)
   95:                         {
   96:                             serviceList = new List<string>();
   97:  
   98:                             foreach (Match match in matchCollection)
   99:                             {
  100:                                 totalCount++;
  101:  
  102:                                 serviceList.Add(match.Value);
  103:                             }
  104:  
  105:                             var duplicateServiceList = serviceList.GroupBy(x => x).Where(group => group.Count() > 1).Select(group => group.Key);
  106:  
  107:                             using (var db = new Ia.Ftn.Cl.Db())
  108:                             {
  109:                                 var dataTable = new DataTable("MSAN service status");
  110:                                 dataTable.Columns.Add("Service");
  111:                                 dataTable.Columns.Add("ServiceType");
  112:                                 dataTable.Columns.Add("Provisioned");
  113:                                 dataTable.Columns.Add("Route");
  114:                                 dataTable.Columns.Add("IsMsan");
  115:                                 dataTable.Columns.Add("EvpuName");
  116:                                 dataTable.Columns.Add("Note");
  117:  
  118:                                 var list = (from s in db.Service2
  119:                                             join se in db.Seruattrs on s.Service equals se.USRNUM into ses
  120:                                             from se in ses.DefaultIfEmpty()
  121:  
  122:                                             join evpu in db.EmsVoipPstnUsers on "+965" + s.Service equals evpu.DN into evpus
  123:                                             from evpu in evpus.DefaultIfEmpty()
  124:  
  125:                                             join srs in db.ServiceRequestServices on s.Service equals srs.Service
  126:                                             where serviceList.Contains(s.Service)
  127:                                             select new
  128:                                             {
  129:                                                 s.Service,
  130:                                                 ServiceType = Ia.Ftn.Cl.Models.Data.Service.ServiceType(s.ServiceType).NameArabicName, // will not display nicely with .ColoredNameArabicName,
  131:                                                 Provisioned = Ia.Cl.Models.Default.YesNoText(srs.Provisioned),
  132:                                                 Route = evpu != null ? Ia.Ftn.Cl.Models.Business.Huawei.Seruattr.RnidxRouteName[se.RNIDX2] : string.Empty,
  133:                                                 IsMsan = Ia.Cl.Models.Default.YesNoText(evpu != null ? Ia.Ftn.Cl.Models.Business.NumberFormatConverter.IsMatchToImpuAid(evpu.DN) : false),
  134:                                                 EvpuName = evpu != null && Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevLicByEmsVoipPstnUserId(evpu.Id) != null ? Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevLicByEmsVoipPstnUserId(evpu.Id).Name : string.Empty,
  135:                                                 Note = string.Empty,
  136:                                             }).AsNoTracking().ToList();
  137:  
  138:                                 foreach (var service in serviceList)
  139:                                 {
  140:                                     isDuplicate = duplicateServiceList.Contains(service);
  141:  
  142:                                     var ll = list.FindAll(u => u.Service == service);
  143:  
  144:                                     foreach (var l in ll)
  145:                                     {
  146:                                         if (l != null)
  147:                                         {
  148:                                             isMigrated = (l.ServiceType == "Digital (رقمي)" && l.Provisioned == "Yes" && l.Route == "Huawei IMS" && l.IsMsan == "Yes" && !string.IsNullOrEmpty(l.EvpuName));
  149:  
  150:                                             isFiber = (l.ServiceType == "Digital (رقمي)" && l.IsMsan == "No");
  151:                                             notProvisioned = (l.Provisioned == "No");
  152:  
  153:                                             if (isDuplicate && isFiber && notProvisioned) note = "Duplicate, fiber, and not provisioned";
  154:                                             else if (isDuplicate && isFiber) note = "Duplicate and fiber";
  155:                                             else if (isDuplicate && notProvisioned) note = "Duplicate and not provisioned";
  156:                                             else if (isFiber && notProvisioned) note = "Fiber and not provisioned";
  157:                                             else if (isDuplicate) note = "Duplicate";
  158:                                             else if (isFiber) note = "Fiber";
  159:                                             else if (notProvisioned) note = "Not provisioned";
  160:                                             else note = string.Empty;
  161:  
  162:                                             dataTable.Rows.Add(service, l.ServiceType, l.Provisioned, l.Route, l.IsMsan, l.EvpuName, note);
  163:  
  164:                                             if (isFiber) isFiberCount++;
  165:                                             if (notProvisioned) notProvisionedCount++;
  166:  
  167:                                             if (isMigrated) migratedCount++;
  168:                                         }
  169:                                         else
  170:                                         {
  171:                                             noService = true;
  172:  
  173:                                             if (isDuplicate && noService) note = "Duplicate and no service";
  174:                                             else if (isDuplicate) note = "Duplicate";
  175:                                             else if (noService) note = "No service";
  176:                                             else note = string.Empty;
  177:  
  178:                                             dataTable.Rows.Add(service, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, note);
  179:  
  180:                                             if (noService) noServiceCount++;
  181:                                         }
  182:  
  183:                                         if (isDuplicate) isDuplicateCount++;
  184:                                     }
  185:                                 }
  186:  
  187:                                 bulkViewModel.DataTable = dataTable; // list.OrderBy(u => u.Service);
  188:  
  189:                                 result.AddSuccess(@"Total submittals: " + totalCount + @"<br/>
  190: Duplicates: " + isDuplicateCount + @"<br/>
  191: No service: " + noServiceCount + @"<br/>
  192: Fiber: " + isFiberCount + @"<br/>
  193: Not provisioned: " + notProvisionedCount + @"<br/>
  194: Migrated: " + migratedCount + @" (might include duplicates)<br/>
  195: ");
  196:                             }
  197:                         }
  198:                         else result.AddError("Nothing was inserted (لم يتم إدخال أي شيء)");
  199:                     }
  200:                     else result.AddError("Nothing selected (لم يتم اختيار أي شيء)");
  201:                 }
  202:                 else result.AddError("Nothing selected (لم يتم اختيار أي شيء)");
  203:             }
  204:             else result.AddError("Nothing was inserted (لم يتم إدخال أي شيء)");
  205:  
  206:             bulkViewModel.Result = result;
  207:         }
  208:  
  209:         ////////////////////////////////////////////////////////////////////////////
  210:         ////////////////////////////////////////////////////////////////////////////
  211:     }
  212:  
  213:     ////////////////////////////////////////////////////////////////////////////
  214:     ////////////////////////////////////////////////////////////////////////////
  215: }