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

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

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

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4:  
    5: namespace Ia.Ftn.Cl.Models.Data
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Contact Entity Framework class for Fixed Telecommunications Network (FTN) data model.
   11:     /// </summary>
   12:     /// 
   13:     /// <remarks> 
   14:     /// Copyright © 2006-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   15:     /// </remarks> 
   16:     public class Contact
   17:     {
   18:         /// <summary/>
   19:         public Contact() { }
   20:  
   21:         ////////////////////////////////////////////////////////////////////////////
   22:  
   23:         /// <summary>
   24:         ///
   25:         /// </summary>
   26:         public static void Create(Ia.Ftn.Cl.Models.Contact newContact, out Ia.Cl.Models.Result result)
   27:         {
   28:             result = new Ia.Cl.Models.Result();
   29:  
   30:             using (var db = new Ia.Ftn.Cl.Db())
   31:             {
   32:                 newContact.Created = newContact.Updated = DateTime.UtcNow.AddHours(3);
   33:  
   34:                 db.Contacts.Add(newContact);
   35:                 db.SaveChanges();
   36:  
   37:                 result.AddSuccess(@"Contact """ + newContact.FullName + @""" created. ");
   38:             }
   39:         }
   40:  
   41:         ////////////////////////////////////////////////////////////////////////////
   42:  
   43:         /// <summary>
   44:         ///
   45:         /// </summary>
   46:         public static Ia.Ftn.Cl.Models.Contact Read(int id)
   47:         {
   48:             Ia.Ftn.Cl.Models.Contact contact;
   49:  
   50:             using (var db = new Ia.Ftn.Cl.Db())
   51:             {
   52:                 contact = (from c in db.Contacts where c.Id == id select c).SingleOrDefault();
   53:             }
   54:  
   55:             return contact;
   56:         }
   57:  
   58:         ////////////////////////////////////////////////////////////////////////////
   59:  
   60:         /// <summary>
   61:         ///
   62:         /// </summary>
   63:         public static List<Ia.Ftn.Cl.Models.Contact> List
   64:         {
   65:             get
   66:             {
   67:                 List<Ia.Ftn.Cl.Models.Contact> contactList;
   68:  
   69:                 using (var db = new Ia.Ftn.Cl.Db())
   70:                 {
   71:                     contactList = (from c in db.Contacts select c).ToList();
   72:                 }
   73:  
   74:                 return contactList;
   75:             }
   76:         }
   77:  
   78:         ////////////////////////////////////////////////////////////////////////////
   79:  
   80:         /// <summary>
   81:         ///
   82:         /// </summary>
   83:         public static void Update(Ia.Ftn.Cl.Models.Contact updatedContact, out Ia.Cl.Models.Result result)
   84:         {
   85:             Ia.Ftn.Cl.Models.Contact contact;
   86:  
   87:             result = new Ia.Cl.Models.Result();
   88:  
   89:             using (var db = new Ia.Ftn.Cl.Db())
   90:             {
   91:                 contact = (from c in db.Contacts where c.Id == updatedContact.Id select c).SingleOrDefault();
   92:  
   93:                 if (contact.Update(updatedContact))
   94:                 {
   95:                     db.Contacts.Attach(contact);
   96:                     db.Entry(contact).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
   97:  
   98:                     result.AddSuccess("Contact " + updatedContact.FullName + @" updated. ");
   99:                 }
  100:                 else
  101:                 {
  102:                     result.AddWarning(@"No change in contact's information. Contact """ + updatedContact.FullName + @""" was not updated. ");
  103:                 }
  104:  
  105:                 db.SaveChanges();
  106:             }
  107:         }
  108:  
  109:         ////////////////////////////////////////////////////////////////////////////
  110:  
  111:         /// <summary>
  112:         ///
  113:         /// </summary>
  114:         public static void Delete(int id, out Ia.Cl.Models.Result result)
  115:         {
  116:             result = new Ia.Cl.Models.Result();
  117:  
  118:             using (var db = new Ia.Ftn.Cl.Db())
  119:             {
  120:                 var contact = (from c in db.Contacts where c.Id == id select c).FirstOrDefault();
  121:  
  122:                 db.Contacts.Remove(contact);
  123:                 db.SaveChanges();
  124:  
  125:                 result.AddSuccess(@"Contact """ + contact.FullName + @""" deleted. ");
  126:             }
  127:         }
  128:  
  129:         ////////////////////////////////////////////////////////////////////////////
  130:         ////////////////////////////////////////////////////////////////////////////
  131:     }
  132:  
  133:     ////////////////////////////////////////////////////////////////////////////
  134:     ////////////////////////////////////////////////////////////////////////////
  135: }