)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
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:     ///
   20:     /// 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
   21:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   22:     ///
   23:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   24:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   25:     /// 
   26:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   27:     /// 
   28:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   29:     /// </remarks> 
   30:     public class Transaction
   31:     {
   32:         ////////////////////////////////////////////////////////////////////////////
   33:  
   34:         /// <summary>
   35:         ///
   36:         /// </summary>
   37:         public Transaction() { }
   38:  
   39:         /// <summary/>
   40:         public int Id { get; set; }
   41:  
   42:         /// <summary/>
   43:         public int TypeId { get; set; }
   44:  
   45:         /// <summary/>
   46:         public int StateId { get; set; }
   47:  
   48:         /// <summary/>
   49:         public int PriorityId { get; set; }
   50:  
   51:         /// <summary/>
   52:         public int RecipientId { get; set; }
   53:  
   54:         /// <summary/>
   55:         public int NumberOfTimesMessageSent { get; set; }
   56:  
   57:         /// <summary/>
   58:         public bool Closed { get; set; }
   59:  
   60:         /// <summary/>
   61:         public string Message { get; set; }
   62:  
   63:         /// <summary/>
   64:         public DateTime? MessageSent { get; set; }
   65:  
   66:         /// <summary/>
   67:         public string Response { get; set; }
   68:  
   69:         /// <summary/>
   70:         public DateTime? ResponseReceived { get; set; }
   71:  
   72:         /// <summary/>
   73:         public DateTime Created { get; set; }
   74:  
   75:         /// <summary/>
   76:         public DateTime Updated { get; set; }
   77:  
   78:         /// <summary/>
   79:         [ForeignKey("StaffIdentityUser_Id")]
   80:         public virtual StaffIdentityUser StaffIdentityUser { get; set; }
   81:  
   82:         ////////////////////////////////////////////////////////////////////////////    
   83:         ////////////////////////////////////////////////////////////////////////////    
   84:  
   85:         /// <summary>
   86:         ///
   87:         /// </summary>
   88:         public static bool Create(Transaction newItem, out int itemId)
   89:         {
   90:             bool b;
   91:  
   92:             b = false;
   93:  
   94:             using (var db = new Ia.Ftn.Cl.Db())
   95:             {
   96:                 newItem.Created = newItem.Updated = DateTime.UtcNow.AddHours(3);
   97:  
   98:                 db.Transactions.Add(newItem);
   99:                 db.SaveChanges();
  100:  
  101:                 itemId = newItem.Id;
  102:  
  103:                 b = true;
  104:             }
  105:  
  106:             return b;
  107:         }
  108:  
  109:         ////////////////////////////////////////////////////////////////////////////
  110:  
  111:         /// <summary>
  112:         ///
  113:         /// </summary>
  114:         public static Transaction Read(int id)
  115:         {
  116:             Transaction item;
  117:  
  118:             using (var db = new Ia.Ftn.Cl.Db())
  119:             {
  120:                 item = (from t in db.Transactions where t.Id == id select t).SingleOrDefault();
  121:             }
  122:  
  123:             return item;
  124:         }
  125:  
  126:         ////////////////////////////////////////////////////////////////////////////
  127:  
  128:         /// <summary>
  129:         ///
  130:         /// </summary>
  131:         public static List<Transaction> ReadList()
  132:         {
  133:             List<Transaction> itemList;
  134:  
  135:             using (var db = new Ia.Ftn.Cl.Db())
  136:             {
  137:                 itemList = (from t in db.Transactions select t).ToList();
  138:             }
  139:  
  140:             return itemList;
  141:         }
  142:  
  143:         ////////////////////////////////////////////////////////////////////////////
  144:  
  145:         /// <summary>
  146:         ///
  147:         /// </summary>
  148:         public static bool Update(Transaction updatedItem, out string result)
  149:         {
  150:             bool b;
  151:  
  152:             b = false;
  153:             result = string.Empty;
  154:  
  155:             using (var db = new Ia.Ftn.Cl.Db())
  156:             {
  157:                 updatedItem = (from t in db.Transactions where t.Id == updatedItem.Id select t).SingleOrDefault();
  158:  
  159:                 updatedItem.Updated = DateTime.UtcNow.AddHours(3);
  160:  
  161:                 db.Transactions.Attach(updatedItem);
  162:  
  163:                 var v = db.Entry(updatedItem);
  164:                 v.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  165:                 db.SaveChanges();
  166:  
  167:                 b = true;
  168:             }
  169:  
  170:             return b;
  171:         }
  172:  
  173:         ////////////////////////////////////////////////////////////////////////////
  174:  
  175:         /// <summary>
  176:         ///
  177:         /// </summary>
  178:         public bool Update(Transaction transactionOnt)
  179:         {
  180:             // below: this will not update Id, Created
  181:             bool updated;
  182:  
  183:             updated = false;
  184:  
  185:             if (this.Closed != transactionOnt.Closed) { this.Closed = transactionOnt.Closed; updated = true; }
  186:             else if (this.Message != transactionOnt.Message) { this.Message = transactionOnt.Message; updated = true; }
  187:             else if (this.MessageSent != transactionOnt.MessageSent) { this.MessageSent = transactionOnt.MessageSent; updated = true; }
  188:             else if (this.NumberOfTimesMessageSent != transactionOnt.NumberOfTimesMessageSent) { this.NumberOfTimesMessageSent = transactionOnt.NumberOfTimesMessageSent; updated = true; }
  189:             else if (this.PriorityId != transactionOnt.PriorityId) { this.PriorityId = transactionOnt.PriorityId; updated = true; }
  190:             else if (this.RecipientId != transactionOnt.RecipientId) { this.RecipientId = transactionOnt.RecipientId; updated = true; }
  191:             else if (this.Response != transactionOnt.Response) { this.Response = transactionOnt.Response; updated = true; }
  192:             else if (this.ResponseReceived != transactionOnt.ResponseReceived) { this.ResponseReceived = transactionOnt.ResponseReceived; updated = true; }
  193:             else if (this.StateId != transactionOnt.StateId) { this.StateId = transactionOnt.StateId; updated = true; }
  194:             else if (this.TypeId != transactionOnt.TypeId) { this.TypeId = transactionOnt.TypeId; updated = true; }
  195:             else if (this.StaffIdentityUser.Id != transactionOnt.StaffIdentityUser.Id) { this.StaffIdentityUser.Id = transactionOnt.StaffIdentityUser.Id; updated = true; }
  196:  
  197:             if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
  198:  
  199:             return updated;
  200:         }
  201:  
  202:         ////////////////////////////////////////////////////////////////////////////
  203:  
  204:         /// <summary>
  205:         ///
  206:         /// </summary>
  207:         public static bool Delete(int id, out string result)
  208:         {
  209:             bool b;
  210:  
  211:             b = false;
  212:             result = string.Empty;
  213:  
  214:             using (var db = new Ia.Ftn.Cl.Db())
  215:             {
  216:                 var v = (from t in db.Transactions where t.Id == id select t).FirstOrDefault();
  217:  
  218:                 db.Transactions.Remove(v);
  219:                 db.SaveChanges();
  220:  
  221:                 b = true;
  222:             }
  223:  
  224:             return b;
  225:         }
  226:  
  227:         ////////////////////////////////////////////////////////////////////////////
  228:         ////////////////////////////////////////////////////////////////////////////
  229:     }
  230:  
  231:     ////////////////////////////////////////////////////////////////////////////
  232:     ////////////////////////////////////////////////////////////////////////////   
  233: }