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