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

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 System.Data;
    4: using System.Text;
    5:  
    6: namespace Ia.Ftn.Wa.Models.Application
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     ///
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   16:     ///
   17:     /// 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
   18:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   19:     ///
   20:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   21:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   22:     /// 
   23:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   24:     /// 
   25:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   26:     /// </remarks> 
   27:     public static class Index
   28:     {
   29:         ////////////////////////////////////////////////////////////////////////////
   30:  
   31:         /// <summary>
   32:         /// 
   33:         /// </summary>
   34:         public static void Configuration(RoleManager<IdentityRole> roleManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
   35:         {
   36:             StringBuilder sb;
   37:  
   38:             var list = new List<string>();
   39:  
   40:             applicationViewModel.AllowedToBeMigratedOltSymbolList = string.Join(", ", Ia.Ftn.Cl.Models.Business.Service.AllowedToBeMigratedOltSymbolList.ToArray());
   41:             applicationViewModel.AllowedToBeProvisionedOltSymbolList = string.Join(", ", Ia.Ftn.Cl.Models.Business.Service.AllowedToBeProvisionedOltSymbolList.ToArray());
   42:  
   43:             applicationViewModel.AllowedToBeMigratedDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Business.Service.AllowedToBeMigratedDomainList.ToArray());
   44:             applicationViewModel.AllowedToBeProvisionedDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Business.Service.AllowedToBeProvisionedDomainList.ToArray());
   45:  
   46:             applicationViewModel.ServiceRequestDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.ServiceRequest.ServiceRequestDomainList.ToArray().OrderBy(u => u.ToString()));
   47:             applicationViewModel.ServiceRequestHistoryDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.ServiceRequestHistory.ServiceRequestHistoryDomainList.ToArray().OrderBy(u => u.ToString()));
   48:  
   49:             applicationViewModel.DomainListText = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.DomainList.ToArray().OrderBy(u => u.ToString()));
   50:             applicationViewModel.NokiaSwitchDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.NokiaSwitchDomainList.ToArray().OrderBy(u => u.ToString()));
   51:             applicationViewModel.HuaweiSwitchDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.HuaweiSwitchDomainList.ToArray().OrderBy(u => u.ToString()));
   52:  
   53:             applicationViewModel.PstnDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.PstnDomainList.ToArray().OrderBy(u => u.ToString()));
   54:             applicationViewModel.AxePstnDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.AxePstnDomainList.ToArray().OrderBy(u => u.ToString()));
   55:             applicationViewModel.EwsdPstnDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.EwsdPstnDomainList.ToArray().OrderBy(u => u.ToString()));
   56:             applicationViewModel.MsanDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.MsanDomainList.ToArray().OrderBy(u => u.ToString()));
   57:             applicationViewModel.SoftXDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.SoftXDomainList.ToArray().OrderBy(u => u.ToString()));
   58:  
   59:             applicationViewModel.SpsDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.SpsDomainList.ToArray().OrderBy(u => u.ToString()));
   60:             applicationViewModel.PstnThatUsesNpServerDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.PstnThatUsesNpServerDomainList.ToArray().OrderBy(u => u.ToString()));
   61:  
   62:             applicationViewModel.PstnAndMsanDomainList = string.Join(", ", Ia.Ftn.Cl.Models.Data.Service.PstnAndMsanDomainList.ToArray().OrderBy(u => u.ToString()));
   63:  
   64:             var unsyncableAccessNameList = Ia.Ftn.Cl.Models.Data.ServiceRequestOnt.AccessNamesThatRevertToAnUnexplainedErroneousStateInTheCustomerDepartmentDatabaseAndAreExemptFromSynchronizationProcessingList();
   65:             applicationViewModel.UnsyncableAccessNameList = string.Join(", ", unsyncableAccessNameList.ToArray().OrderBy(u => u.ToString()));
   66:  
   67:  
   68:             list = new List<string>();
   69:             foreach (var kuwaitFtnArea in Ia.Ftn.Cl.Models.Data.Service.KuwaitFtnAreaList)
   70:             {
   71:                 list.Add("[" + kuwaitFtnArea.Name + " (" + kuwaitFtnArea.Symbol + "): " + kuwaitFtnArea.Id + "] ");
   72:             }
   73:             applicationViewModel.KuwaitFtnAreaList = string.Join(", ", list.ToArray().OrderBy(u => u.ToString()));
   74:  
   75:  
   76:             var siteList = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.SiteList select s).ToList();
   77:             sb = new StringBuilder();
   78:             foreach (var site in siteList) sb.AppendLine("[" + site.NameArabicName + ": " + site.Id + "], ");
   79:             applicationViewModel.SiteSymbolAndId = sb.ToString();
   80:  
   81:  
   82:             var oltList = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList select o).ToList();
   83:             sb = new StringBuilder();
   84:             foreach (var olt in oltList) sb.AppendLine(olt.AmsName + ": " + olt.Id + ", ");
   85:             applicationViewModel.OltAmsNameAndId = sb.ToString();
   86:  
   87:  
   88:             var siteMsanList = (from s in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.MsanList select s).ToList();
   89:             sb = new StringBuilder();
   90:             foreach (var siteMsan in siteMsanList) sb.AppendLine(siteMsan.NameSymbol + ": " + siteMsan.Id + ", ");
   91:             applicationViewModel.SiteMsanSymbolAndId = sb.ToString();
   92:  
   93:  
   94:             var msanDevList = (from s in Ia.Ftn.Cl.Models.Data.Huawei.Default.MsanDevList select s).ToList();
   95:             sb = new StringBuilder();
   96:             foreach (var msanDev in msanDevList) sb.AppendLine(msanDev.Dev + ", ");
   97:             applicationViewModel.MsanDevList = sb.ToString();
   98:  
   99:  
  100:             applicationViewModel.SymbolDomainSameSwitchVendorButDifferentSiteExceptionList = string.Join(", ", Ia.Ftn.Cl.Models.Business.Service.SymbolDomainSameSwitchVendorButDifferentSiteExceptionList.ToArray().OrderBy(u => u.ToString()));
  101:  
  102:  
  103:             applicationViewModel.ServiceRequestApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.ServiceRequestApplication.List.ToArray());
  104:             applicationViewModel.ServiceApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.ServiceApplication.List.ToArray());
  105:  
  106:             applicationViewModel.ProvisionApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.ProvisionApplication.List.ToArray());
  107:             applicationViewModel.AmsApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.AmsApplication.List.ToArray());
  108:             applicationViewModel.NceApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.NceApplication.List.ToArray());
  109:             applicationViewModel.AxeApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.AxeApplication.List.ToArray());
  110:             applicationViewModel.NetManagerApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.NetManagerApplication.List.ToArray());
  111:             applicationViewModel.SoftXApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.SoftXApplication.List.ToArray());
  112:             applicationViewModel.SpsApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.SpsApplication.List.ToArray());
  113:             applicationViewModel.FtnApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.FtnApplication.List.ToArray());
  114:             applicationViewModel.TelegramApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.TelegramApplication.List.ToArray());
  115:             applicationViewModel.SecretaryApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.SecretaryApplication.List.ToArray());
  116:             applicationViewModel.EmailApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.EmailApplication.List.ToArray());
  117:             applicationViewModel.SchedulerApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.SchedulerApplication.List.ToArray());
  118:             applicationViewModel.SdcApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.SdcApplication.List.ToArray());
  119:             applicationViewModel.MdaaApplication = string.Join("<br/>", Ia.Ftn.Cl.Models.Data.MessageQueue.MdaaApplication.List.ToArray());
  120:  
  121:             /*
  122:                 var v = Ia.Ftn.Cl.Models.Data.Service.DomainList;
  123:                 string sql;
  124:                 sql = "where Service not like '" + string.Join("%' and Service not like '", v) + "%'";
  125:              */
  126:  
  127:  
  128:             var roleList = Ia.Ftn.Cl.Models.Identity.RoleList(roleManager);
  129:  
  130:             sb = new StringBuilder();
  131:             foreach (var role in roleList) sb.AppendLine(role.Name + "<br />");
  132:             applicationViewModel.IdentityRoles = sb.ToString();
  133:         }
  134:  
  135:         ////////////////////////////////////////////////////////////////////////////
  136:         ////////////////////////////////////////////////////////////////////////////
  137:  
  138:         /// <summary>
  139:         /// 
  140:         /// </summary>
  141:         public static void SettingViewModel(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  142:         {
  143:             var users = userManager.Users;
  144:  
  145:             var list = users.ToDictionary(m => m.Id, m => m.UserName);
  146:  
  147:             applicationViewModel.UserSelectList = new SelectList(list, "Key", "Value");
  148:         }
  149:  
  150:         ////////////////////////////////////////////////////////////////////////////
  151:  
  152:         /// <summary>
  153:         /// 
  154:         /// </summary>
  155:         public static void SettingPost(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, RoleManager<IdentityRole> roleManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel, string commandName)
  156:         {
  157:             if (commandName == "nullifyUserInReportAndReportHistory") NullifyUserInReportAndReportHistory(ref applicationViewModel);
  158:             else if (commandName == "createFrameworkRolesIfNotExist") CreateFrameworkRolesIfNotExist(roleManager, ref applicationViewModel);
  159:             else if (commandName == "updateFrameworkRoleToStaffIdentityRoleList") UpdateFrameworkRoleToStaffIdentityRoleList(userManager, roleManager, ref applicationViewModel);
  160:             else if (commandName == "unlockoutAllUsers") UnlockoutAllUsers(ref applicationViewModel);
  161:             else if (commandName == "setMembershipIsApprovedToFalseIfUserLastActivityDateIsLessThanDateTime") SetMembershipIsApprovedToFalseIfUserLastActivityDateIsLessThanDateTime(ref applicationViewModel);
  162:             else if (commandName == "deleteStaffIfUserLastActivityDateIsLessThanDateTime") DeleteStaffIfUserLastActivityDateIsLessThanDateTime(ref applicationViewModel);
  163:             else if (commandName == "shutdownAllActiveApplications") ShutdownAllActiveApplications(ref applicationViewModel);
  164:             else
  165:             {
  166:             }
  167:         }
  168:  
  169:         ////////////////////////////////////////////////////////////////////////////
  170:         ////////////////////////////////////////////////////////////////////////////
  171:  
  172:         /// <summary>
  173:         /// 
  174:         /// </summary>
  175:         public static void MailPost(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, RoleManager<IdentityRole> roleManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel, string selectedValue)
  176:         {
  177:             string content, subject;
  178:             DataTable accessDataTable;
  179:  
  180:             var applicationContact = Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationContact");
  181:             var applicationEmail = Ia.Cl.Models.ApplicationConfiguration.GetSetting("AppSettings:ApplicationEmail");
  182:  
  183:             if (selectedValue == "1")
  184:             {
  185:                 subject = "Table of ONTs that are provisioned and ready within FTN access network but do not exist in the Customer Department's database (" + DateTime.Now.AddHours(3).ToString("yyyy-MM-dd HH:mm") + ")";
  186:  
  187:                 accessDataTable = Ia.Ftn.Cl.Models.Ui.Access.ReadListWithOntListProvisionedAndReadyButDoNotExistInCustomerDepartmentDatabaseDataTable();
  188:  
  189:                 content = "Table of ONTs that are provisioned and ready within FTN access network but do not exist in the Customer Department's database (" + DateTime.Now.AddHours(3).ToString("yyyy-MM-dd HH:mm") + ")";
  190:  
  191:                 content += "\r\n";
  192:                 content += "\r\n";
  193:  
  194:                 content += Ia.Cl.Models.Default.GenerateTabSeparatedTextFromDataTable(accessDataTable);
  195:  
  196:                 applicationViewModel.Result = Ia.Ftn.Cl.Models.Ui.Mail.SendPlainMail(applicationContact, applicationEmail, subject, content);
  197:             }
  198:             else if (selectedValue == "2")
  199:             {
  200:                 applicationViewModel.Result = Ia.Ftn.Cl.Models.Ui.Administration.Default.EmailStatisticReport(applicationContact, applicationEmail);
  201:             }
  202:             else if (selectedValue == "3")
  203:             {
  204:                 applicationViewModel.Result = Ia.Ftn.Cl.Models.Ui.Administration.Default.EmailListOfPreviouslyPstnDomainServicesMigratedOrProvisionedIntoImsFiberOrImsMsanServicesInAllowedToBeMigratedOltsReport(applicationContact, applicationEmail);
  205:             }
  206:             else
  207:             {
  208:                 applicationViewModel.Result = new Ia.Cl.Models.Result();
  209:             }
  210:         }
  211:  
  212:         ////////////////////////////////////////////////////////////////////////////
  213:         ////////////////////////////////////////////////////////////////////////////
  214:  
  215:         /// <summary>
  216:         ///
  217:         /// </summary>
  218:         public static void NullifyUserInReportAndReportHistory(ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  219:         {
  220:             bool b;
  221:             int n1, n2;
  222:  
  223:             applicationViewModel.Result = new Ia.Cl.Models.Result();
  224:  
  225:             if (!string.IsNullOrEmpty(applicationViewModel.UserSelectedValue))
  226:             {
  227:                 var userId = applicationViewModel.UserSelectedValue;
  228:  
  229:                 b = Ia.Ftn.Cl.Models.Data.Report.NullifyUserId(userId, out n1);
  230:  
  231:                 if (b)
  232:                 {
  233:                     b = Ia.Ftn.Cl.Models.Data.ReportHistory.NullifyUserId(userId, out n2);
  234:  
  235:                     if (b)
  236:                     {
  237:                         applicationViewModel.Result.AddSuccess(n1 + " reports and " + n2 + " report histories updated.");
  238:                     }
  239:                     else
  240:                     {
  241:                         applicationViewModel.Result.AddError(n1 + " reports updated, but updating of report histories failed.");
  242:                     }
  243:                 }
  244:                 else
  245:                 {
  246:                     applicationViewModel.Result.AddError("Reports update failed, updating of report histories abandoned.");
  247:                 }
  248:             }
  249:             else
  250:             {
  251:                 applicationViewModel.Result.AddWarning("No users selected.");
  252:             }
  253:         }
  254:  
  255:         ////////////////////////////////////////////////////////////////////////////
  256:  
  257:         /// <summary>
  258:         ///
  259:         /// </summary>
  260:         public static void CreateFrameworkRolesIfNotExist(RoleManager<IdentityRole> roleManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  261:         {
  262:             Ia.Ftn.Cl.Models.Data.Administration.CreateFrameworkIdentityRolesIfTheyDoNotExist(roleManager);
  263:  
  264:             applicationViewModel.Result = new Ia.Cl.Models.Result();
  265:  
  266:             applicationViewModel.Result.AddSuccess("Command executed.");
  267:         }
  268:  
  269:         ////////////////////////////////////////////////////////////////////////////
  270:  
  271:         /// <summary>
  272:         ///
  273:         /// </summary>
  274:         public static void UpdateFrameworkRoleToStaffIdentityRoleList(UserManager<Ia.Ftn.Cl.Models.StaffIdentityUser> userManager, RoleManager<IdentityRole> roleManager, ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  275:         {
  276:             var staffIdentityUserList = Ia.Ftn.Cl.Models.Data.StaffIdentityUser.List();
  277:  
  278:             foreach (var staffIdentityUser in staffIdentityUserList)
  279:             {
  280:                 Ia.Ftn.Cl.Models.Business.Authority.UpdateFrameworkRolesOfStaffIdentityUser(userManager, roleManager, staffIdentityUser);
  281:             }
  282:  
  283:             applicationViewModel.Result = new Ia.Cl.Models.Result();
  284:  
  285:             applicationViewModel.Result.AddSuccess("Command executed.");
  286:         }
  287:  
  288:         ////////////////////////////////////////////////////////////////////////////
  289:  
  290:         /// <summary>
  291:         ///
  292:         /// </summary>
  293:         public static void UnlockoutAllUsers(ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  294:         {
  295:             var result = new Ia.Cl.Models.Result();
  296:  
  297:             Ia.Ftn.Cl.Models.Data.StaffIdentityUser.UnlockoutAllIdentityUsers();
  298:  
  299:             result.AddSuccess("Unlock All Locked-Out Users.");
  300:  
  301:             applicationViewModel.Result = result;
  302:         }
  303:  
  304:         ////////////////////////////////////////////////////////////////////////////
  305:  
  306:         /// <summary>
  307:         ///
  308:         /// </summary>
  309:         public static void SetMembershipIsApprovedToFalseIfUserLastActivityDateIsLessThanDateTime(ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  310:         {
  311:             var result = new Ia.Cl.Models.Result();
  312:             var dateTime = DateTime.UtcNow.AddHours(3);
  313:  
  314:             Ia.Ftn.Cl.Models.Data.StaffIdentityUser.SetMembershipIsApprovedToFalseIfUserLastActivityDateIsLessThanDateTime(dateTime.AddDays(-60));
  315:  
  316:             result.AddSuccess("Set Membership IsApproved to false if user's last activity date is before 60 days.");
  317:  
  318:             applicationViewModel.Result = result;
  319:         }
  320:  
  321:         ////////////////////////////////////////////////////////////////////////////
  322:  
  323:         /// <summary>
  324:         ///
  325:         /// </summary>
  326:         public static void DeleteStaffIfUserLastActivityDateIsLessThanDateTime(ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  327:         {
  328:             var result = new Ia.Cl.Models.Result();
  329:             var dateTime = DateTime.UtcNow.AddHours(3);
  330:  
  331:             Ia.Ftn.Cl.Models.Data.StaffIdentityUser.DeleteStaffIfUserLastActivityDateIsLessThanDateTime(dateTime.AddDays(-70));
  332:  
  333:             result.AddSuccess("Delete staff if user's last activity date is before 70 days.");
  334:  
  335:             applicationViewModel.Result = result;
  336:         }
  337:  
  338:         ////////////////////////////////////////////////////////////////////////////
  339:  
  340:         /// <summary>
  341:         ///
  342:         /// </summary>
  343:         public static void ShutdownAllActiveApplications(ref Ia.Ftn.Wa.Models.Application.ApplicationViewModel applicationViewModel)
  344:         {
  345:             Ia.Ftn.Cl.Models.Data.MessageQueue.SecretaryApplication.Enqueue(Ia.Ftn.Cl.Models.Business.MessageQueue.Application.FtnApplication, Ia.Ftn.Cl.Models.Business.MessageQueue.Process.ActiveApplicationRunningPermissionState, false);
  346:  
  347:             applicationViewModel.Result = new Ia.Cl.Models.Result();
  348:  
  349:             applicationViewModel.Result.AddSuccess("All active applications are being shutdown now (يتم إغلاق التطبيقات الفعالة)");
  350:         }
  351:  
  352:         ////////////////////////////////////////////////////////////////////////////
  353:         ////////////////////////////////////////////////////////////////////////////
  354:     }
  355:  
  356:     ////////////////////////////////////////////////////////////////////////////
  357:     ////////////////////////////////////////////////////////////////////////////
  358: }