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