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

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

ServiceExemption Framework class for Fixed Telecommunications Network (FTN) data model.

    1: using Microsoft.EntityFrameworkCore;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Linq;
    5:  
    6: namespace Ia.Ftn.Cl.Models.Data
    7: {
    8:     ////////////////////////////////////////////////////////////////////////////
    9:  
   10:     /// <summary publish="true">
   11:     /// ServiceExemption Framework class for Fixed Telecommunications Network (FTN) data model.
   12:     /// </summary>
   13:     /// 
   14:     /// <remarks> 
   15:     /// Copyright © 2006-2020 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 class ServiceExemption
   28:     {
   29:         /// <summary/>
   30:         public ServiceExemption() { }
   31:  
   32:         ////////////////////////////////////////////////////////////////////////////
   33:  
   34:         /// <summary>
   35:         ///
   36:         /// </summary>
   37:         public static string Create(Ia.Ftn.Cl.Models.ServiceExemption serviceExemption, out string result)
   38:         {
   39:             string id;
   40:  
   41:             id = string.Empty;
   42:             result = string.Empty;
   43:  
   44:             using (var db = new Ia.Ftn.Cl.Db())
   45:             {
   46:                 serviceExemption.StaffIdentityUser = (from s in db.StaffIdentityUsers where s.Id == serviceExemption.StaffIdentityUser.Id select s).SingleOrDefault();
   47:  
   48:                 serviceExemption.Created = serviceExemption.Updated = DateTime.UtcNow.AddHours(3);
   49:  
   50:                 db.ServiceExemptions.Add(serviceExemption);
   51:                 db.SaveChanges();
   52:  
   53:                 id = serviceExemption.Service;
   54:             }
   55:  
   56:             return id;
   57:         }
   58:  
   59:         ////////////////////////////////////////////////////////////////////////////
   60:  
   61:         /// <summary>
   62:         ///
   63:         /// </summary>
   64:         public static Ia.Ftn.Cl.Models.ServiceExemption Read(string id)
   65:         {
   66:             Ia.Ftn.Cl.Models.ServiceExemption serviceExemption;
   67:  
   68:             using (var db = new Ia.Ftn.Cl.Db())
   69:             {
   70:                 serviceExemption = (from s in db.ServiceExemptions where s.Id == id select s).SingleOrDefault();
   71:             }
   72:  
   73:             return serviceExemption;
   74:         }
   75:  
   76:         ////////////////////////////////////////////////////////////////////////////
   77:  
   78:         /// <summary>
   79:         ///
   80:         /// </summary>
   81:         public static List<Ia.Ftn.Cl.Models.ServiceExemption> List()
   82:         {
   83:             List<Ia.Ftn.Cl.Models.ServiceExemption> list;
   84:  
   85:             using (var db = new Ia.Ftn.Cl.Db())
   86:             {
   87:                 list = (from s in db.ServiceExemptions select s).Include(u => u.StaffIdentityUser).ToList();
   88:             }
   89:  
   90:             return list;
   91:         }
   92:  
   93:         ////////////////////////////////////////////////////////////////////////////
   94:  
   95:         /// <summary>
   96:         ///
   97:         /// </summary>
   98:         public static List<string> ServiceIdList()
   99:         {
  100:             List<string> list;
  101:  
  102:             using (var db = new Ia.Ftn.Cl.Db())
  103:             {
  104:                 list = (from s in db.ServiceExemptions select s.Id).AsNoTracking().ToList();
  105:             }
  106:  
  107:             return list;
  108:         }
  109:  
  110:         ////////////////////////////////////////////////////////////////////////////
  111:  
  112:         /// <summary>
  113:         ///
  114:         /// </summary>
  115:         public static List<string> ServiceList()
  116:         {
  117:             List<string> list;
  118:  
  119:             using (var db = new Ia.Ftn.Cl.Db())
  120:             {
  121:                 list = (from s in db.ServiceExemptions select s.Service).AsNoTracking().ToList();
  122:             }
  123:  
  124:             return list;
  125:         }
  126:  
  127:         ////////////////////////////////////////////////////////////////////////////
  128:  
  129:         /// <summary>
  130:         ///
  131:         /// </summary>
  132:         public static bool Update(Ia.Ftn.Cl.Models.ServiceExemption updatedServiceExemption, out string result)
  133:         {
  134:             bool b;
  135:             Ia.Ftn.Cl.Models.ServiceExemption serviceExemption;
  136:  
  137:             b = false;
  138:             result = string.Empty;
  139:  
  140:             using (var db = new Ia.Ftn.Cl.Db())
  141:             {
  142:                 serviceExemption = (from se in db.ServiceExemptions
  143:                                     where se.Id == updatedServiceExemption.Id
  144:                                     select se).Include(u => u.StaffIdentityUser).SingleOrDefault();
  145:  
  146:                 if (serviceExemption.Update(updatedServiceExemption))
  147:                 {
  148:                     serviceExemption.StaffIdentityUser = (from s in db.StaffIdentityUsers where s.Id == serviceExemption.StaffIdentityUser.Id select s).SingleOrDefault();
  149:  
  150:                     db.ServiceExemptions.Attach(serviceExemption);
  151:                     db.Entry(serviceExemption).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  152:                 }
  153:  
  154:                 db.SaveChanges();
  155:  
  156:                 b = true;
  157:             }
  158:  
  159:             return b;
  160:         }
  161:  
  162:         ////////////////////////////////////////////////////////////////////////////
  163:  
  164:         /// <summary>
  165:         ///
  166:         /// </summary>
  167:         public static bool Delete(string id)
  168:         {
  169:             bool b;
  170:  
  171:             b = false;
  172:  
  173:             using (var db = new Ia.Ftn.Cl.Db())
  174:             {
  175:                 var v = (from s in db.ServiceExemptions where s.Id == id select s).FirstOrDefault();
  176:  
  177:                 db.ServiceExemptions.Remove(v);
  178:                 db.SaveChanges();
  179:  
  180:                 b = true;
  181:             }
  182:  
  183:             return b;
  184:         }
  185:  
  186:         ////////////////////////////////////////////////////////////////////////////
  187:         ////////////////////////////////////////////////////////////////////////////
  188:     }
  189:  
  190:     ////////////////////////////////////////////////////////////////////////////
  191:     ////////////////////////////////////////////////////////////////////////////
  192: }