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

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

    1: using Microsoft.AspNetCore.Mvc.Rendering;
    2: using System.Net;
    3:  
    4: namespace Ia.Ftn.Wa.Models.Provision.Access
    5: {
    6:     ////////////////////////////////////////////////////////////////////////////
    7:  
    8:     /// <summary publish="true">
    9:     ///
   10:     /// </summary>
   11:     /// 
   12:     /// <remarks> 
   13:     /// Copyright © 2006-2025 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   14:     ///
   15:     /// 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
   16:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   17:     ///
   18:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   19:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   20:     /// 
   21:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   22:     /// 
   23:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   24:     /// </remarks> 
   25:     public static class Manage
   26:     {
   27:         ////////////////////////////////////////////////////////////////////////////
   28:  
   29:         /// <summary>
   30:         ///
   31:         /// </summary>
   32:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel)
   33:         {
   34:             OltSelectList(ref manageViewModel);
   35:  
   36:             manageViewModel.InsertButtonEnabled = Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Create, manageViewModel.CurrentStaffIdentityUser);
   37:         }
   38:  
   39:         ////////////////////////////////////////////////////////////////////////////
   40:  
   41:         /// <summary>
   42:         ///
   43:         /// </summary>
   44:         public static void Post(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel, string commandName, string accessId)
   45:         {
   46:             if (commandName == "insert") Insert(ref manageViewModel);
   47:             else if (commandName == "edit") Edit(ref manageViewModel, accessId);
   48:             else if (commandName == "update") Update(ref manageViewModel, accessId);
   49:             else if (commandName == "delete") Delete(ref manageViewModel, accessId);
   50:             else if (commandName == "cancel") Cancel(ref manageViewModel);
   51:             else
   52:             {
   53:             }
   54:         }
   55:  
   56:         ////////////////////////////////////////////////////////////////////////////
   57:         ////////////////////////////////////////////////////////////////////////////
   58:  
   59:         /// <summary>
   60:         ///
   61:         /// </summary>
   62:         private static void Insert(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel)
   63:         {
   64:             var blockText = WebUtility.HtmlDecode(manageViewModel.BlockInput);
   65:             var street = WebUtility.HtmlDecode(manageViewModel.StreetInput);
   66:             var premisesOld = WebUtility.HtmlDecode(manageViewModel.PremisesOldInput);
   67:             var premisesNew = WebUtility.HtmlDecode(manageViewModel.PremisesNewInput);
   68:             var paci = WebUtility.HtmlDecode(manageViewModel.PaciInput);
   69:             var note = WebUtility.HtmlDecode(manageViewModel.NoteInput);
   70:  
   71:             var odf = string.Empty;
   72:  
   73:             var result = new Ia.Cl.Models.Result();
   74:             manageViewModel.InsertResult = new Ia.Cl.Models.Result();
   75:             manageViewModel.Result = new Ia.Cl.Models.Result();
   76:  
   77:             var oltId = int.Parse(manageViewModel.OltSelectedValue);
   78:             var ponNumber = int.Parse(manageViewModel.PonSelectedValue);
   79:  
   80:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Create, manageViewModel.CurrentStaffIdentityUser))
   81:             {
   82:                 if (!string.IsNullOrEmpty(manageViewModel.OntSelectedValue))
   83:                 {
   84:                     var ontNumber = int.Parse(manageViewModel.OntSelectedValue);
   85:  
   86:                     if (oltId > 0 && ponNumber > 0)
   87:                     {
   88:                         paci = Ia.Ftn.Cl.Models.Business.Access.NormalizePaciEntry(paci);
   89:  
   90:                         if (!string.IsNullOrEmpty(paci) && int.TryParse(paci, out int i))
   91:                         {
   92:                             var accessListByPaci = Ia.Ftn.Cl.Models.Data.Access.ReadListByPaci(paci);
   93:  
   94:                             // the new access is acceptable if the PACI is new or PACI exists with similar block and premises-old
   95:                             if (accessListByPaci.Count == 0 || accessListByPaci.Any(u => u.Block == blockText && u.PremisesOld == premisesOld))
   96:                             {
   97:                                 if (!string.IsNullOrEmpty(blockText))
   98:                                 {
   99:                                     if (!string.IsNullOrEmpty(premisesOld))
  100:                                     {
  101:                                         var block = blockText;
  102:  
  103:                                         var nddOnt = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntList
  104:                                                       where o.Pon.PonGroup.Olt.Id == oltId && o.Pon.Number == ponNumber && o.Number == ontNumber
  105:                                                       select o).SingleOrDefault();
  106:  
  107:                                         if (nddOnt != null)
  108:                                         {
  109:                                             var accessName = nddOnt.Access.Name;
  110:  
  111:                                             var areaId = Ia.Ftn.Cl.Models.Data.Access.AreaIdFromOltIdAndPon(oltId, ponNumber);
  112:  
  113:                                             // if areaId = 0 we will try to get the area by matching OLT symbol with site's area list symbols. This is not always correct, but its good as a last resort
  114:                                             if (areaId == 0) areaId = (from kna in Ia.Ftn.Cl.Models.Data.Service.KuwaitFtnAreaList
  115:                                                                        where kna.Symbol == nddOnt.Pon.PonGroup.Symbol
  116:                                                                        select kna.Id).SingleOrDefault();
  117:  
  118:                                             var kuwaitOfnArea = Ia.Ftn.Cl.Models.Data.Service.KuwaitFtnAreaById(areaId);
  119:  
  120:                                             if (kuwaitOfnArea != null)
  121:                                             {
  122:                                                 Ia.Ftn.Cl.Models.Business.Access.Create(Ia.Ftn.Cl.Models.Business.MessageQueue.Application.FtnApplication, accessName, kuwaitOfnArea.Symbol, block, street, premisesOld, premisesNew, odf, paci, note, manageViewModel.CurrentStaffIdentityUser, out result);
  123:                                             }
  124:                                             else result.AddError("kuwaitOfnArea is null");
  125:                                         }
  126:                                         else result.AddError("nddOnt is null");
  127:                                     }
  128:                                     else result.AddError("PremisesOld (Parcel) was not assigned");
  129:                                 }
  130:                                 else result.AddError("Block was not assigned");
  131:                             }
  132:                             else result.AddError("PACI number " + paci + " is already assigned to another ONT. To submit other ONTs with this same PACI their address must also have the same block and old permises numbers");
  133:                         }
  134:                         else result.AddError("PACI is undefined or invalid");
  135:                     }
  136:                     else result.AddError("oltId and/or ponNumber ViewState values are invalid");
  137:                 }
  138:                 else result.AddError("Nothing selected in the drop down list");
  139:             }
  140:             else result.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة)");
  141:  
  142:             if (result.IsSuccessful)
  143:             {
  144:                 manageViewModel.BlockInput = manageViewModel.StreetInput = manageViewModel.PremisesOldInput = manageViewModel.PremisesNewInput = manageViewModel.PaciInput = manageViewModel.NoteInput = string.Empty;
  145:             }
  146:             else
  147:             {
  148:             }
  149:  
  150:             manageViewModel.InsertResult = manageViewModel.Result = result;
  151:         }
  152:  
  153:         ////////////////////////////////////////////////////////////////////////////
  154:  
  155:         /// <summary>
  156:         ///
  157:         /// </summary>
  158:         private static void Edit(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel, string accessId)
  159:         {
  160:             manageViewModel.AccessListEditId = accessId;
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:  
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         private static void Cancel(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel)
  169:         {
  170:             manageViewModel.AccessListEditId = string.Empty;
  171:         }
  172:  
  173:         ////////////////////////////////////////////////////////////////////////////
  174:  
  175:         /// <summary>
  176:         /// 
  177:         /// </summary>
  178:         private static void Update(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel, string accessId)
  179:         {
  180:             var result = new Ia.Cl.Models.Result();
  181:             manageViewModel.UpdateResult = new Ia.Cl.Models.Result();
  182:             manageViewModel.Result = new Ia.Cl.Models.Result();
  183:  
  184:             var oltId = int.Parse(manageViewModel.OltSelectedValue);
  185:             var ponNumber = int.Parse(manageViewModel.PonSelectedValue);
  186:             var ontNumber = int.Parse(manageViewModel.OntSelectedValue);
  187:  
  188:             manageViewModel.AccessListEditId = accessId;
  189:  
  190:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, manageViewModel.CurrentStaffIdentityUser))
  191:             {
  192:                 var blockText = WebUtility.HtmlDecode(manageViewModel.BlockEditInput);
  193:                 var street = WebUtility.HtmlDecode(manageViewModel.StreetEditInput);
  194:                 var premisesOld = WebUtility.HtmlDecode(manageViewModel.PremisesOldEditInput);
  195:                 var premisesNew = WebUtility.HtmlDecode(manageViewModel.PremisesNewEditInput);
  196:                 var paci = WebUtility.HtmlDecode(manageViewModel.PaciEditInput);
  197:                 var note = WebUtility.HtmlDecode(manageViewModel.NoteEditInput);
  198:  
  199:                 var access = Ia.Ftn.Cl.Models.Data.Access.Read(accessId);
  200:  
  201:                 ontNumber = access.Ont;
  202:  
  203:                 if (ontNumber > 0)
  204:                 {
  205:                     paci = Ia.Ftn.Cl.Models.Business.Access.NormalizePaciEntry(paci);
  206:  
  207:                     if (!string.IsNullOrEmpty(paci) && int.TryParse(paci, out int i))
  208:                     {
  209:                         if (!string.IsNullOrEmpty(blockText))
  210:                         {
  211:                             if (!string.IsNullOrEmpty(premisesOld))
  212:                             {
  213:                                 var block = blockText;
  214:  
  215:                                 var dateTime = DateTime.UtcNow.AddHours(3);
  216:  
  217:                                 var updatedAccess = new Ia.Ftn.Cl.Models.Access()
  218:                                 {
  219:                                     Id = accessId,
  220:                                     AreaId = access.AreaId,
  221:                                     Block = block,
  222:                                     Street = street,
  223:                                     PremisesOld = premisesOld,
  224:                                     PremisesNew = premisesNew,
  225:                                     Paci = paci,
  226:                                     Note = note,
  227:                                     Olt = access.Olt,
  228:                                     Odf = access.Odf,
  229:                                     Pon = access.Pon,
  230:                                     Ont = access.Ont,
  231:                                     Created = access.Created,
  232:                                     Updated = dateTime,
  233:                                     StaffIdentityUser = manageViewModel.CurrentStaffIdentityUser
  234:                                 };
  235:  
  236:                                 var isSuccess = Ia.Ftn.Cl.Models.Data.Access.Update(updatedAccess, out string r);
  237:  
  238:                                 // Ia.Ftn.Cl.Models.Data.MessageQueue.AccessNameQueue.ProvisionAccessQueue.Enqueue(updatedAccess.Name);
  239:  
  240:                                 if (isSuccess)
  241:                                 {
  242:                                     manageViewModel.UpdateResult.AddSuccess("Access updated (تم تحديث معلومات الجهاز)");
  243:  
  244:                                     manageViewModel.AccessListEditId = string.Empty;
  245:                                 }
  246:                                 else manageViewModel.UpdateResult.AddError(r);
  247:                             }
  248:                             else result.AddError("premisesOld (parcel) was not assigned");
  249:                         }
  250:                         else result.AddError("block was not assigned");
  251:                     }
  252:                     else result.AddError("PACI is undefined or invalid");
  253:                 }
  254:                 else result.AddError("ontNumber is invalid");
  255:             }
  256:             else result.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة)");
  257:  
  258:             if (result.IsSuccessful)
  259:             {
  260:                 manageViewModel.BlockInput = manageViewModel.StreetInput = manageViewModel.PremisesOldInput = manageViewModel.PremisesNewInput = manageViewModel.PaciInput = manageViewModel.NoteInput = string.Empty;
  261:             }
  262:             else
  263:             {
  264:             }
  265:  
  266:             manageViewModel.UpdateResult = manageViewModel.Result = result;
  267:         }
  268:  
  269:         ////////////////////////////////////////////////////////////////////////////
  270:  
  271:         /// <summary>
  272:         /// 
  273:         /// </summary>
  274:         private static void Delete(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel, string accessId)
  275:         {
  276:             var result = new Ia.Cl.Models.Result();
  277:             manageViewModel.UpdateResult = new Ia.Cl.Models.Result();
  278:             manageViewModel.Result = new Ia.Cl.Models.Result();
  279:  
  280:             var oltId = int.Parse(manageViewModel.OltSelectedValue);
  281:             var ponNumber = int.Parse(manageViewModel.PonSelectedValue);
  282:             var ontNumber = int.Parse(manageViewModel.OntSelectedValue);
  283:  
  284:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanCreateReadUpdateDeleteAccessList(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Delete, manageViewModel.CurrentStaffIdentityUser))
  285:             {
  286:                 var nddOnt = Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary.ContainsKey(accessId) ? Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OntAccessIdToOntDictionary[accessId] : null;
  287:  
  288:                 if (nddOnt != null)
  289:                 {
  290:                     var accessName = nddOnt.Access.Name;
  291:  
  292:                     Ia.Ftn.Cl.Models.Business.Access.Delete(Ia.Ftn.Cl.Models.Business.MessageQueue.Application.FtnApplication, accessName, manageViewModel.CurrentStaffIdentityUser.Id, out result);
  293:  
  294:                     //Ia.Ftn.Cl.Models.Data.MessageQueue.AccessNameQueue.ProvisionAccessQueue.Enqueue(accessName);
  295:                 }
  296:                 else result.AddError("nddOnt is null");
  297:             }
  298:             else result.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة)");
  299:  
  300:             if (result.IsSuccessful)
  301:             {
  302:                 manageViewModel.BlockInput = manageViewModel.StreetInput = manageViewModel.PremisesOldInput = manageViewModel.PremisesNewInput = manageViewModel.PaciInput = manageViewModel.NoteInput = string.Empty;
  303:             }
  304:             else
  305:             {
  306:             }
  307:  
  308:             manageViewModel.UpdateResult = manageViewModel.Result = result;
  309:         }
  310:  
  311:         ////////////////////////////////////////////////////////////////////////////
  312:         ////////////////////////////////////////////////////////////////////////////
  313:  
  314:         /// <summary>
  315:         ///
  316:         /// </summary>
  317:         private static void OltSelectList(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel)
  318:         {
  319:             var list = (from o in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.OltList
  320:                         select new { Value = o.Id, Text = o.Symbol + " (" + o.AmsName + ")" }).OrderBy(u => u.Text).ToList();
  321:  
  322:             if (!string.IsNullOrEmpty(manageViewModel.OltSelectedValue))
  323:             {
  324:                 manageViewModel.OltSelectList = new SelectList(list, "Value", "Text", manageViewModel.OltSelectedValue);
  325:             }
  326:             else
  327:             {
  328:                 manageViewModel.OltSelectList = new SelectList(list, "Value", "Text", list[0].Value);
  329:                 manageViewModel.OltSelectedValue = list[0].Value.ToString();
  330:             }
  331:  
  332:             if (manageViewModel.OltSelectedValue != manageViewModel.OltPreviouslySelectedValue)
  333:             {
  334:                 manageViewModel.PonSelectedValue = string.Empty;
  335:             }
  336:  
  337:             manageViewModel.OltPreviouslySelectedValue = manageViewModel.OltSelectedValue;
  338:  
  339:             PonSelectList(ref manageViewModel);
  340:         }
  341:  
  342:         ////////////////////////////////////////////////////////////////////////////
  343:  
  344:         /// <summary>
  345:         ///
  346:         /// </summary>
  347:         private static void PonSelectList(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel)
  348:         {
  349:             if (!string.IsNullOrEmpty(manageViewModel.OltSelectedValue))
  350:             {
  351:                 var oltId = int.Parse(manageViewModel.OltSelectedValue);
  352:  
  353:                 var list = (from p in Ia.Ftn.Cl.Models.Data.NetworkDesignDocument.PonList where p.PonGroup.Olt.Id == oltId select p).OrderBy(a => a.Number).ToList();
  354:  
  355:                 if (!string.IsNullOrEmpty(manageViewModel.PonSelectedValue))
  356:                 {
  357:                     manageViewModel.PonSelectList = new SelectList(list, "Number", "Number", manageViewModel.PonSelectedValue);
  358:                 }
  359:                 else
  360:                 {
  361:                     manageViewModel.PonSelectList = new SelectList(list, "Number", "Number", list[0].Number.ToString());
  362:                     manageViewModel.PonSelectedValue = list[0].Number.ToString();
  363:                 }
  364:  
  365:                 if (manageViewModel.PonSelectedValue != manageViewModel.PonPreviouslySelectedValue)
  366:                 {
  367:                     manageViewModel.OntSelectedValue = string.Empty;
  368:                 }
  369:  
  370:                 manageViewModel.PonPreviouslySelectedValue = manageViewModel.PonSelectedValue;
  371:  
  372:                 OntSelectList(ref manageViewModel, oltId);
  373:             }
  374:             else manageViewModel.InsertButtonEnabled = false;
  375:         }
  376:  
  377:         ////////////////////////////////////////////////////////////////////////////
  378:  
  379:         /// <summary>
  380:         ///
  381:         /// </summary>
  382:         private static void OntSelectList(ref Ia.Ftn.Wa.Models.Provision.Access.ManageViewModel manageViewModel, int oltId)
  383:         {
  384:             if (!string.IsNullOrEmpty(manageViewModel.PonSelectedValue))
  385:             {
  386:                 var ponNumber = int.Parse(manageViewModel.PonSelectedValue);
  387:  
  388:                 var accessList = Ia.Ftn.Cl.Models.Data.Access.List(oltId, ponNumber);
  389:  
  390:                 manageViewModel.AccessList = accessList;
  391:  
  392:                 List<int> ontNotInListList = Ia.Ftn.Cl.Models.Data.Access.OntsNotInAccessList(accessList);
  393:  
  394:                 var list = ontNotInListList.Select((x, i) => new { Value = x.ToString(), Text = x.ToString() }).ToList();
  395:  
  396:  
  397:  
  398:                 manageViewModel.OntSelectList = new SelectList(list, "Value", "Text", list[0].Value);
  399:                 manageViewModel.OntSelectedValue = list[0].Value;
  400:  
  401:                 /*
  402:                 if (!string.IsNullOrEmpty(manageViewModel.OntSelectedValue))
  403:                 {
  404:                     manageViewModel.OntSelectList = new SelectList(list, "Value", "Text", manageViewModel.OntSelectedValue);
  405:                 }
  406:                 else
  407:                 {
  408:                     manageViewModel.OntSelectList = new SelectList(list, "Value", "Text", list[0].Value);
  409:                     manageViewModel.OntSelectedValue = list[0].Value.ToString();
  410:                 }
  411:                 */
  412:  
  413:                 manageViewModel.InsertButtonEnabled = (ontNotInListList.Count > 0) ? true : false;
  414:             }
  415:             else manageViewModel.InsertButtonEnabled = false;
  416:         }
  417:  
  418:         ////////////////////////////////////////////////////////////////////////////
  419:         ////////////////////////////////////////////////////////////////////////////
  420:     }
  421:  
  422:     ////////////////////////////////////////////////////////////////////////////
  423:     ////////////////////////////////////////////////////////////////////////////
  424: }