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

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.Data;
    3: using System.Net;
    4: using System.Text;
    5:  
    6: namespace Ia.Ftn.Wa.Models.Provision
    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:     /// </remarks> 
   17:     public static class ServiceExemption
   18:     {
   19:         ////////////////////////////////////////////////////////////////////////////
   20:  
   21:         /// <summary>
   22:         ///
   23:         /// </summary>
   24:         public static void ViewModel(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel)
   25:         {
   26:             serviceExemptionViewModel.DiagnosticLabel = "Diagnostics: ";
   27:  
   28:             serviceExemptionViewModel.ServiceExemptionList = Ia.Ftn.Cl.Models.Data.ServiceExemption.List().OrderBy(c => c.Created).ToList();
   29:  
   30:             serviceExemptionViewModel.InsertButtonEnabled = serviceExemptionViewModel.InsertButtonEnabled && Ia.Ftn.Cl.Models.Business.Authority.StaffCanInsertUpdateDeleteServiceExemption(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Create, serviceExemptionViewModel.CurrentStaffIdentityUser);
   31:         }
   32:  
   33:         ////////////////////////////////////////////////////////////////////////////
   34:  
   35:         /// <summary>
   36:         ///
   37:         /// </summary>
   38:         public static void Post(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel, string commandName, string serviceExemptionId)
   39:         {
   40:             if (commandName == "insert") Insert(ref serviceExemptionViewModel);
   41:             else if (commandName == "edit") Edit(ref serviceExemptionViewModel, serviceExemptionId);
   42:             else if (commandName == "update") Update(ref serviceExemptionViewModel, serviceExemptionId);
   43:             else if (commandName == "delete") Delete(ref serviceExemptionViewModel, serviceExemptionId);
   44:             else if (commandName == "cancel") Cancel(ref serviceExemptionViewModel);
   45:             else
   46:             {
   47:             }
   48:         }
   49:  
   50:         ////////////////////////////////////////////////////////////////////////////
   51:  
   52:         /// <summary>
   53:         ///
   54:         /// </summary>
   55:         private static void Insert(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel)
   56:         {
   57:             int number;
   58:             string id, service, note, serviceExemptionId, result;
   59:             DateTime now;
   60:             Ia.Ftn.Cl.Models.ServiceExemption serviceExemption;
   61:  
   62:             serviceExemptionViewModel.Result = new Ia.Cl.Models.Result();
   63:  
   64:             service = WebUtility.HtmlDecode(serviceExemptionViewModel.ServiceInput);
   65:             note = WebUtility.HtmlDecode(serviceExemptionViewModel.NoteTextArea);
   66:  
   67:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanInsertUpdateDeleteServiceExemption(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Create, serviceExemptionViewModel.CurrentStaffIdentityUser))
   68:             {
   69:                 if (!string.IsNullOrEmpty(service))
   70:                 {
   71:                     service = service.Trim();
   72:  
   73:                     if (service.Length > 0)
   74:                     {
   75:                         if (int.TryParse(service, out number))
   76:                         {
   77:                             if (Ia.Ftn.Cl.Models.Business.Service.ServiceHasEightDigitsAndIsWithinAllowedDomainList(number))
   78:                             {
   79:                                 now = DateTime.UtcNow.AddHours(3);
   80:  
   81:                                 id = Ia.Ftn.Cl.Models.ServiceExemption.ServiceServiceExemptionId(service, Ia.Ftn.Cl.Models.Business.Service.ServiceType.ImsService);
   82:  
   83:                                 var serviceExemption0 = Ia.Ftn.Cl.Models.Data.ServiceExemption.Read(id);
   84:  
   85:                                 if (serviceExemption0 == null)
   86:                                 {
   87:                                     serviceExemption = new Ia.Ftn.Cl.Models.ServiceExemption()
   88:                                     {
   89:                                         Id = id,
   90:                                         Service = service,
   91:                                         Note = note,
   92:                                         StaffIdentityUser = serviceExemptionViewModel.CurrentStaffIdentityUser,
   93:                                         Created = now,
   94:                                         Updated = now
   95:                                     };
   96:  
   97:                                     serviceExemptionId = Ia.Ftn.Cl.Models.Data.ServiceExemption.Create(serviceExemption, out result);
   98:  
   99:                                     if (!string.IsNullOrEmpty(serviceExemptionId))
  100:                                     {
  101:                                         serviceExemptionViewModel.Result.AddSuccess("Service \"" + service + "\" added to exemption list (تمت إضافة الرقم للقائمة)");
  102:                                     }
  103:                                     else serviceExemptionViewModel.Result.AddError(result);
  104:                                 }
  105:                                 else serviceExemptionViewModel.Result.AddError("The number \"" + number + "\" already exists in the list (الرقم ينتمي للقائمة)");
  106:                             }
  107:                             else serviceExemptionViewModel.Result.AddError("The number \"" + number + "\" does not belong to the network (الرقم لا ينتمي للشبكة)");
  108:                         }
  109:                         else serviceExemptionViewModel.Result.AddError("Entry is not a number (لم يتم إدخال رقم)");
  110:                     }
  111:                     else serviceExemptionViewModel.Result.AddError("No input was entered (لم يتم إدخال أي شيء)");
  112:                 }
  113:                 else serviceExemptionViewModel.Result.AddError("No input was entered (لم يتم إدخال أي شيء)");
  114:             }
  115:             else serviceExemptionViewModel.Result.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة)");
  116:         }
  117:  
  118:         ////////////////////////////////////////////////////////////////////////////
  119:  
  120:         /// <summary>
  121:         ///
  122:         /// </summary>
  123:         private static void Edit(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel, string serviceExemptionId)
  124:         {
  125:             serviceExemptionViewModel.ServiceExemptionEditId = serviceExemptionId;
  126:         }
  127:  
  128:         ////////////////////////////////////////////////////////////////////////////
  129:  
  130:         /// <summary>
  131:         ///
  132:         /// </summary>
  133:         private static void Cancel(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel)
  134:         {
  135:             serviceExemptionViewModel.ServiceExemptionEditId = string.Empty;
  136:         }
  137:  
  138:         ////////////////////////////////////////////////////////////////////////////
  139:  
  140:         /// <summary>
  141:         /// 
  142:         /// </summary>
  143:         private static void Update(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel, string serviceExemptionId)
  144:         {
  145:             string note, result;
  146:             DateTime now;
  147:  
  148:             serviceExemptionViewModel.UpdateResult = new Ia.Cl.Models.Result();
  149:  
  150:             serviceExemptionViewModel.ServiceExemptionEditId = serviceExemptionId;
  151:  
  152:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanInsertUpdateDeleteServiceExemption(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Update, serviceExemptionViewModel.CurrentStaffIdentityUser))
  153:             {
  154:                 now = DateTime.UtcNow.AddHours(3);
  155:  
  156:                 note = WebUtility.HtmlDecode(serviceExemptionViewModel.NoteTextAreaEdit);
  157:  
  158:                 var updatedServiceExemption = new Ia.Ftn.Cl.Models.ServiceExemption()
  159:                 {
  160:                     Id = serviceExemptionId,
  161:                     Note = note,
  162:                     StaffIdentityUser = serviceExemptionViewModel.CurrentStaffIdentityUser,
  163:                     Updated = now
  164:                 };
  165:  
  166:                 var isSuccess = Ia.Ftn.Cl.Models.Data.ServiceExemption.Update(updatedServiceExemption, out result);
  167:  
  168:                 if (isSuccess)
  169:                 {
  170:                     serviceExemptionViewModel.UpdateResult.AddSuccess("Service exemption updated (تم تحديث الاستثناءات)");
  171:  
  172:                     serviceExemptionViewModel.ServiceExemptionEditId = string.Empty;
  173:                 }
  174:                 else serviceExemptionViewModel.UpdateResult.AddError(result);
  175:             }
  176:             else serviceExemptionViewModel.UpdateResult.AddError("You are not authorized to modify this value (لست مخولاً بتعديل هذه القيمة)");
  177:         }
  178:  
  179:         ////////////////////////////////////////////////////////////////////////////
  180:  
  181:         /// <summary>
  182:         /// 
  183:         /// </summary>
  184:         private static void Delete(ref Ia.Ftn.Wa.Models.Provision.ServiceExemptionViewModel serviceExemptionViewModel, string serviceExemptionId)
  185:         {
  186:             serviceExemptionViewModel.UpdateResult = new Ia.Cl.Models.Result();
  187:  
  188:             if (Ia.Ftn.Cl.Models.Business.Authority.StaffCanInsertUpdateDeleteServiceExemption(Ia.Ftn.Cl.Models.Business.Authority.PersistentStorageFunction.Delete, serviceExemptionViewModel.CurrentStaffIdentityUser))
  189:             {
  190:                 var serviceExemption = Ia.Ftn.Cl.Models.Data.ServiceExemption.Read(serviceExemptionId);
  191:  
  192:                 var service = serviceExemption.Service;
  193:  
  194:                 var b = Ia.Ftn.Cl.Models.Data.ServiceExemption.Delete(serviceExemptionId);
  195:  
  196:                 serviceExemptionViewModel.UpdateResult.AddSuccess(@"Service exemption """ + service + @""" deleted");
  197:             }
  198:             else serviceExemptionViewModel.UpdateResult.AddError("You are not authorized to delete this value (لست مخولاً بمسح هذه القيمة)");
  199:         }
  200:  
  201:         ////////////////////////////////////////////////////////////////////////////
  202:         ////////////////////////////////////////////////////////////////////////////
  203:     }
  204:  
  205:     ////////////////////////////////////////////////////////////////////////////
  206:     ////////////////////////////////////////////////////////////////////////////
  207: }