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

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

Transaction Entity Framework class for Fixed Telecommunications Network (FTN) entity model.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Data;
    4: using System.Linq;
    5: using System.ComponentModel.DataAnnotations.Schema;
    6: using System.Threading;
    7: using System.Threading.Tasks;
    8:  
    9: namespace Ia.Ftn.Cl.Models
   10: {
   11:     ////////////////////////////////////////////////////////////////////////////
   12:  
   13:     /// <summary publish="true">
   14:     /// Transaction Entity Framework class for Fixed Telecommunications Network (FTN) entity model.
   15:     /// </summary>
   16:     /// 
   17:     /// <remarks> 
   18:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     /// </remarks> 
   20:     public class Transaction
   21:     {
   22:         ////////////////////////////////////////////////////////////////////////////
   23:  
   24:         /// <summary>
   25:         ///
   26:         /// </summary>
   27:         public Transaction() { }
   28:  
   29:         /// <summary/>
   30:         public int Id { get; set; }
   31:  
   32:         /// <summary/>
   33:         public int TypeId { get; set; }
   34:  
   35:         /// <summary/>
   36:         public int StateId { get; set; }
   37:  
   38:         /// <summary/>
   39:         public int PriorityId { get; set; }
   40:  
   41:         /// <summary/>
   42:         public int RecipientId { get; set; }
   43:  
   44:         /// <summary/>
   45:         public int NumberOfTimesMessageSent { get; set; }
   46:  
   47:         /// <summary/>
   48:         public bool Closed { get; set; }
   49:  
   50:         /// <summary/>
   51:         public string Message { get; set; }
   52:  
   53:         /// <summary/>
   54:         public DateTime? MessageSent { get; set; }
   55:  
   56:         /// <summary/>
   57:         public string Response { get; set; }
   58:  
   59:         /// <summary/>
   60:         public DateTime? ResponseReceived { get; set; }
   61:  
   62:         /// <summary/>
   63:         public DateTime Created { get; set; }
   64:  
   65:         /// <summary/>
   66:         public DateTime Updated { get; set; }
   67:  
   68:         /// <summary/>
   69:         [ForeignKey("StaffIdentityUser_Id")]
   70:         public virtual StaffIdentityUser StaffIdentityUser { get; set; }
   71:  
   72:         ////////////////////////////////////////////////////////////////////////////    
   73:         ////////////////////////////////////////////////////////////////////////////    
   74:  
   75:         /// <summary>
   76:         ///
   77:         /// </summary>
   78:         public static bool Create(Transaction newItem, out int itemId)
   79:         {
   80:             bool b;
   81:  
   82:             b = false;
   83:  
   84:             using (var db = new Ia.Ftn.Cl.Db())
   85:             {
   86:                 newItem.Created = newItem.Updated = DateTime.UtcNow.AddHours(3);
   87:  
   88:                 db.Transactions.Add(newItem);
   89:                 db.SaveChanges();
   90:  
   91:                 itemId = newItem.Id;
   92:  
   93:                 b = true;
   94:             }
   95:  
   96:             return b;
   97:         }
   98:  
   99:         ////////////////////////////////////////////////////////////////////////////
  100:  
  101:         /// <summary>
  102:         ///
  103:         /// </summary>
  104:         public static Transaction Read(int id)
  105:         {
  106:             Transaction item;
  107:  
  108:             using (var db = new Ia.Ftn.Cl.Db())
  109:             {
  110:                 item = (from t in db.Transactions where t.Id == id select t).SingleOrDefault();
  111:             }
  112:  
  113:             return item;
  114:         }
  115:  
  116:         ////////////////////////////////////////////////////////////////////////////
  117:  
  118:         /// <summary>
  119:         ///
  120:         /// </summary>
  121:         public static List<Transaction> ReadList()
  122:         {
  123:             List<Transaction> itemList;
  124:  
  125:             using (var db = new Ia.Ftn.Cl.Db())
  126:             {
  127:                 itemList = (from t in db.Transactions select t).ToList();
  128:             }
  129:  
  130:             return itemList;
  131:         }
  132:  
  133:         ////////////////////////////////////////////////////////////////////////////
  134:  
  135:         /// <summary>
  136:         ///
  137:         /// </summary>
  138:         public static bool Update(Transaction updatedItem, out string result)
  139:         {
  140:             bool b;
  141:  
  142:             b = false;
  143:             result = string.Empty;
  144:  
  145:             using (var db = new Ia.Ftn.Cl.Db())
  146:             {
  147:                 updatedItem = (from t in db.Transactions where t.Id == updatedItem.Id select t).SingleOrDefault();
  148:  
  149:                 updatedItem.Updated = DateTime.UtcNow.AddHours(3);
  150:  
  151:                 db.Transactions.Attach(updatedItem);
  152:  
  153:                 var v = db.Entry(updatedItem);
  154:                 v.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  155:                 db.SaveChanges();
  156:  
  157:                 b = true;
  158:             }
  159:  
  160:             return b;
  161:         }
  162:  
  163:         ////////////////////////////////////////////////////////////////////////////
  164:  
  165:         /// <summary>
  166:         ///
  167:         /// </summary>
  168:         public bool Update(Transaction transactionOnt)
  169:         {
  170:             // below: this will not update Id, Created
  171:             bool updated;
  172:  
  173:             updated = false;
  174:  
  175:             if (this.Closed != transactionOnt.Closed) { this.Closed = transactionOnt.Closed; updated = true; }
  176:             else if (this.Message != transactionOnt.Message) { this.Message = transactionOnt.Message; updated = true; }
  177:             else if (this.MessageSent != transactionOnt.MessageSent) { this.MessageSent = transactionOnt.MessageSent; updated = true; }
  178:             else if (this.NumberOfTimesMessageSent != transactionOnt.NumberOfTimesMessageSent) { this.NumberOfTimesMessageSent = transactionOnt.NumberOfTimesMessageSent; updated = true; }
  179:             else if (this.PriorityId != transactionOnt.PriorityId) { this.PriorityId = transactionOnt.PriorityId; updated = true; }
  180:             else if (this.RecipientId != transactionOnt.RecipientId) { this.RecipientId = transactionOnt.RecipientId; updated = true; }
  181:             else if (this.Response != transactionOnt.Response) { this.Response = transactionOnt.Response; updated = true; }
  182:             else if (this.ResponseReceived != transactionOnt.ResponseReceived) { this.ResponseReceived = transactionOnt.ResponseReceived; updated = true; }
  183:             else if (this.StateId != transactionOnt.StateId) { this.StateId = transactionOnt.StateId; updated = true; }
  184:             else if (this.TypeId != transactionOnt.TypeId) { this.TypeId = transactionOnt.TypeId; updated = true; }
  185:             else if (this.StaffIdentityUser.Id != transactionOnt.StaffIdentityUser.Id) { this.StaffIdentityUser.Id = transactionOnt.StaffIdentityUser.Id; updated = true; }
  186:  
  187:             if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
  188:  
  189:             return updated;
  190:         }
  191:  
  192:         ////////////////////////////////////////////////////////////////////////////
  193:  
  194:         /// <summary>
  195:         ///
  196:         /// </summary>
  197:         public static bool Delete(int id, out string result)
  198:         {
  199:             bool b;
  200:  
  201:             b = false;
  202:             result = string.Empty;
  203:  
  204:             using (var db = new Ia.Ftn.Cl.Db())
  205:             {
  206:                 var v = (from t in db.Transactions where t.Id == id select t).FirstOrDefault();
  207:  
  208:                 db.Transactions.Remove(v);
  209:                 db.SaveChanges();
  210:  
  211:                 b = true;
  212:             }
  213:  
  214:             return b;
  215:         }
  216:  
  217:         ////////////////////////////////////////////////////////////////////////////
  218:         ////////////////////////////////////////////////////////////////////////////
  219:     }
  220:  
  221:     ////////////////////////////////////////////////////////////////////////////
  222:     ////////////////////////////////////////////////////////////////////////////   
  223: }