شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation LinksHome » Code Library » Transaction

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

Transaction Entity Framework class for Next Generation Network (NGN) entity model.

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