)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Contact (Ia.Ftn.Cl.Model.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.Model.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:     ///
   16:     /// 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
   17:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   18:     ///
   19:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   20:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   21:     /// 
   22:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   23:     /// 
   24:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   25:     /// </remarks> 
   26:     public class Contact
   27:     {
   28:         /// <summary/>
   29:         public Contact() { }
   30:  
   31:         ////////////////////////////////////////////////////////////////////////////
   32:  
   33:         /// <summary>
   34:         ///
   35:         /// </summary>
   36:         public static void Create(Ia.Ftn.Cl.Model.Contact newContact, out Ia.Cl.Models.Result result)
   37:         {
   38:             result = new Ia.Cl.Models.Result();
   39:  
   40:             using (var db = new Ia.Ftn.Cl.Model.Db())
   41:             {
   42:                 newContact.Created = newContact.Updated = DateTime.UtcNow.AddHours(3);
   43:  
   44:                 db.Contacts.Add(newContact);
   45:                 db.SaveChanges();
   46:  
   47:                 result.AddSuccess(@"Contact """ + newContact.FullName + @""" created. ");
   48:             }
   49:         }
   50:  
   51:         ////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         public static Ia.Ftn.Cl.Model.Contact Read(int id)
   57:         {
   58:             Ia.Ftn.Cl.Model.Contact contact;
   59:  
   60:             using (var db = new Ia.Ftn.Cl.Model.Db())
   61:             {
   62:                 contact = (from c in db.Contacts where c.Id == id select c).SingleOrDefault();
   63:             }
   64:  
   65:             return contact;
   66:         }
   67:  
   68:         ////////////////////////////////////////////////////////////////////////////
   69:  
   70:         /// <summary>
   71:         ///
   72:         /// </summary>
   73:         public static List<Ia.Ftn.Cl.Model.Contact> List
   74:         {
   75:             get
   76:             {
   77:                 List<Ia.Ftn.Cl.Model.Contact> contactList;
   78:  
   79:                 using (var db = new Ia.Ftn.Cl.Model.Db())
   80:                 {
   81:                     contactList = (from c in db.Contacts select c).ToList();
   82:                 }
   83:  
   84:                 return contactList;
   85:             }
   86:         }
   87:  
   88:         ////////////////////////////////////////////////////////////////////////////
   89:  
   90:         /// <summary>
   91:         ///
   92:         /// </summary>
   93:         public static void Update(Ia.Ftn.Cl.Model.Contact updatedContact, out Ia.Cl.Models.Result result)
   94:         {
   95:             Ia.Ftn.Cl.Model.Contact contact;
   96:  
   97:             result = new Ia.Cl.Models.Result();
   98:  
   99:             using (var db = new Ia.Ftn.Cl.Model.Db())
  100:             {
  101:                 contact = (from c in db.Contacts where c.Id == updatedContact.Id select c).SingleOrDefault();
  102:  
  103:                 if (contact.Update(updatedContact))
  104:                 {
  105:                     db.Contacts.Attach(contact);
  106:                     db.Entry(contact).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
  107:  
  108:                     result.AddSuccess("Contact " + updatedContact.FullName + @" updated. ");
  109:                 }
  110:                 else
  111:                 {
  112:                     result.AddWarning(@"No change in contact's information. Contact """ + updatedContact.FullName + @""" was not updated. ");
  113:                 }
  114:  
  115:                 db.SaveChanges();
  116:             }
  117:         }
  118:  
  119:         ////////////////////////////////////////////////////////////////////////////
  120:  
  121:         /// <summary>
  122:         ///
  123:         /// </summary>
  124:         public static void Delete(int id, out Ia.Cl.Models.Result result)
  125:         {
  126:             result = new Ia.Cl.Models.Result();
  127:  
  128:             using (var db = new Ia.Ftn.Cl.Model.Db())
  129:             {
  130:                 var contact = (from c in db.Contacts where c.Id == id select c).FirstOrDefault();
  131:  
  132:                 db.Contacts.Remove(contact);
  133:                 db.SaveChanges();
  134:  
  135:                 result.AddSuccess(@"Contact """ + contact.FullName + @""" deleted. ");
  136:             }
  137:         }
  138:  
  139:         ////////////////////////////////////////////////////////////////////////////
  140:         ////////////////////////////////////////////////////////////////////////////
  141:     }
  142:  
  143:     ////////////////////////////////////////////////////////////////////////////
  144:     ////////////////////////////////////////////////////////////////////////////
  145: }