)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
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:     /// </remarks> 
   17:     public class ServiceExemption
   18:     {
   19:         /// <summary/>
   20:         public ServiceExemption() { }
   21:  
   22:         ////////////////////////////////////////////////////////////////////////////
   23:  
   24:         /// <summary>
   25:         ///
   26:         /// </summary>
   27:         public static string Create(Ia.Ftn.Cl.Models.ServiceExemption serviceExemption, out string result)
   28:         {
   29:             string id;
   30:  
   31:             id = string.Empty;
   32:             result = string.Empty;
   33:  
   34:             using (var db = new Ia.Ftn.Cl.Db())
   35:             {
   36:                 serviceExemption.StaffIdentityUser = (from s in db.StaffIdentityUsers where s.Id == serviceExemption.StaffIdentityUser.Id select s).SingleOrDefault();
   37:  
   38:                 serviceExemption.Created = serviceExemption.Updated = DateTime.UtcNow.AddHours(3);
   39:  
   40:                 db.ServiceExemptions.Add(serviceExemption);
   41:                 db.SaveChanges();
   42:  
   43:                 id = serviceExemption.Service;
   44:             }
   45:  
   46:             return id;
   47:         }
   48:  
   49:         ////////////////////////////////////////////////////////////////////////////
   50:  
   51:         /// <summary>
   52:         ///
   53:         /// </summary>
   54:         public static Ia.Ftn.Cl.Models.ServiceExemption Read(string id)
   55:         {
   56:             Ia.Ftn.Cl.Models.ServiceExemption serviceExemption;
   57:  
   58:             using (var db = new Ia.Ftn.Cl.Db())
   59:             {
   60:                 serviceExemption = (from s in db.ServiceExemptions where s.Id == id select s).SingleOrDefault();
   61:             }
   62:  
   63:             return serviceExemption;
   64:         }
   65:  
   66:         ////////////////////////////////////////////////////////////////////////////
   67:  
   68:         /// <summary>
   69:         ///
   70:         /// </summary>
   71:         public static List<Ia.Ftn.Cl.Models.ServiceExemption> List()
   72:         {
   73:             List<Ia.Ftn.Cl.Models.ServiceExemption> list;
   74:  
   75:             using (var db = new Ia.Ftn.Cl.Db())
   76:             {
   77:                 list = (from s in db.ServiceExemptions select s).Include(u => u.StaffIdentityUser).ToList();
   78:             }
   79:  
   80:             return list;
   81:         }
   82:  
   83:         ////////////////////////////////////////////////////////////////////////////
   84:  
   85:         /// <summary>
   86:         ///
   87:         /// </summary>
   88:         public static List<string> ServiceIdList()
   89:         {
   90:             List<string> list;
   91:  
   92:             using (var db = new Ia.Ftn.Cl.Db())
   93:             {
   94:                 list = (from s in db.ServiceExemptions select s.Id).AsNoTracking().ToList();
   95:             }
   96:  
   97:             return list;
   98:         }
   99:  
  100:         ////////////////////////////////////////////////////////////////////////////
  101:  
  102:         /// <summary>
  103:         ///
  104:         /// </summary>
  105:         public static List<string> ServiceList()
  106:         {
  107:             List<string> list;
  108:  
  109:             using (var db = new Ia.Ftn.Cl.Db())
  110:             {
  111:                 list = (from s in db.ServiceExemptions select s.Service).AsNoTracking().ToList();
  112:             }
  113:  
  114:             return list;
  115:         }
  116:  
  117:         ////////////////////////////////////////////////////////////////////////////
  118:  
  119:         /// <summary>
  120:         ///
  121:         /// </summary>
  122:         public static bool Update(Ia.Ftn.Cl.Models.ServiceExemption updatedServiceExemption, out string result)
  123:         {
  124:             bool b;
  125:             Ia.Ftn.Cl.Models.ServiceExemption serviceExemption;
  126:  
  127:             b = false;
  128:             result = string.Empty;
  129:  
  130:             using (var db = new Ia.Ftn.Cl.Db())
  131:             {
  132:                 serviceExemption = (from se in db.ServiceExemptions
  133:                                     where se.Id == updatedServiceExemption.Id
  134:                                     select se).Include(u => u.StaffIdentityUser).SingleOrDefault();
  135:  
  136:                 if (serviceExemption.Update(updatedServiceExemption))
  137:                 {
  138:                     serviceExemption.StaffIdentityUser = (from s in db.StaffIdentityUsers where s.Id == serviceExemption.StaffIdentityUser.Id select s).SingleOrDefault();
  139:  
  140:                     db.ServiceExemptions.Attach(serviceExemption);
  141:                     db.Entry(serviceExemption).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  142:                 }
  143:  
  144:                 db.SaveChanges();
  145:  
  146:                 b = true;
  147:             }
  148:  
  149:             return b;
  150:         }
  151:  
  152:         ////////////////////////////////////////////////////////////////////////////
  153:  
  154:         /// <summary>
  155:         ///
  156:         /// </summary>
  157:         public static bool Delete(string id)
  158:         {
  159:             bool b;
  160:  
  161:             b = false;
  162:  
  163:             using (var db = new Ia.Ftn.Cl.Db())
  164:             {
  165:                 var v = (from s in db.ServiceExemptions where s.Id == id select s).FirstOrDefault();
  166:  
  167:                 db.ServiceExemptions.Remove(v);
  168:                 db.SaveChanges();
  169:  
  170:                 b = true;
  171:             }
  172:  
  173:             return b;
  174:         }
  175:  
  176:         ////////////////////////////////////////////////////////////////////////////
  177:         ////////////////////////////////////////////////////////////////////////////
  178:     }
  179:  
  180:     ////////////////////////////////////////////////////////////////////////////
  181:     ////////////////////////////////////////////////////////////////////////////
  182: }