Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Contact

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

Contact Entity Framework class for Next Generation Network (NGN) data model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Web;
   5:  using System.Web.Security;
   6:  using System.ComponentModel.DataAnnotations.Schema;
   7:   
   8:  namespace Ia.Ngn.Cl.Model.Data
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Contact Entity Framework class for Next Generation Network (NGN) data model.
  14:      /// </summary>
  15:      /// 
  16:      /// <remarks> 
  17:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  18:      ///
  19:      /// 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
  20:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  21:      ///
  22:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  23:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  24:      /// 
  25:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  26:      /// 
  27:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  28:      /// </remarks> 
  29:      public partial class Contact
  30:      {
  31:          /// <summary/>
  32:          public Contact() { }
  33:   
  34:          ////////////////////////////////////////////////////////////////////////////
  35:   
  36:          /// <summary>
  37:          ///
  38:          /// </summary>
  39:          public static void Create(Ia.Ngn.Cl.Model.Contact newContact, out Ia.Cl.Model.Result result)
  40:          {
  41:              result = new Ia.Cl.Model.Result();
  42:   
  43:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  44:              {
  45:                  newContact.Created = newContact.Updated = DateTime.UtcNow.AddHours(3);
  46:   
  47:                  db.Contacts.Add(newContact);
  48:                  db.SaveChanges();
  49:   
  50:                  result.AddSuccess(@"Contact """ + newContact.FullName + @""" created. ");
  51:              }
  52:          }
  53:   
  54:          ////////////////////////////////////////////////////////////////////////////
  55:   
  56:          /// <summary>
  57:          ///
  58:          /// </summary>
  59:          public static Ia.Ngn.Cl.Model.Contact Read(int id)
  60:          {
  61:              Ia.Ngn.Cl.Model.Contact contact;
  62:   
  63:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  64:              {
  65:                  contact = (from c in db.Contacts where c.Id == id select c).SingleOrDefault();
  66:              }
  67:   
  68:              return contact;
  69:          }
  70:   
  71:          ////////////////////////////////////////////////////////////////////////////
  72:   
  73:          /// <summary>
  74:          ///
  75:          /// </summary>
  76:          public static List<Ia.Ngn.Cl.Model.Contact> List
  77:          {
  78:              get
  79:              {
  80:                  List<Ia.Ngn.Cl.Model.Contact> contactList;
  81:   
  82:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  83:                  {
  84:                      contactList = (from c in db.Contacts select c).ToList();
  85:                  }
  86:   
  87:                  return contactList;
  88:              }
  89:          }
  90:   
  91:          ////////////////////////////////////////////////////////////////////////////
  92:   
  93:          /// <summary>
  94:          ///
  95:          /// </summary>
  96:          public static void Update(Ia.Ngn.Cl.Model.Contact updatedContact, out Ia.Cl.Model.Result result)
  97:          {
  98:              Ia.Ngn.Cl.Model.Contact contact;
  99:   
 100:              result = new Ia.Cl.Model.Result();
 101:   
 102:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 103:              {
 104:                  contact = (from c in db.Contacts where c.Id == updatedContact.Id select c).SingleOrDefault();
 105:   
 106:                  if (contact.Update(updatedContact))
 107:                  {
 108:                      db.Contacts.Attach(contact);
 109:                      db.Entry(contact).State = System.Data.Entity.EntityState.Modified;
 110:   
 111:                      result.AddSuccess("Contact " + updatedContact.FullName + @" updated. ");
 112:                  }
 113:                  else
 114:                  {
 115:                      result.AddWarning(@"No change in contact's information. Contact """ + updatedContact.FullName + @""" was not updated. ");
 116:                  }
 117:   
 118:                  db.SaveChanges();
 119:              }
 120:          }
 121:   
 122:          ////////////////////////////////////////////////////////////////////////////
 123:   
 124:          /// <summary>
 125:          ///
 126:          /// </summary>
 127:          public static void Delete(int id, out Ia.Cl.Model.Result result)
 128:          {
 129:              result = new Ia.Cl.Model.Result();
 130:   
 131:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 132:              {
 133:                  var contact = (from c in db.Contacts where c.Id == id select c).FirstOrDefault();
 134:   
 135:                  db.Contacts.Remove(contact);
 136:                  db.SaveChanges();
 137:   
 138:                  result.AddSuccess(@"Contact """ + contact.FullName + @""" deleted. ");
 139:              }
 140:          }
 141:   
 142:          ////////////////////////////////////////////////////////////////////////////
 143:          ////////////////////////////////////////////////////////////////////////////
 144:      }
 145:   
 146:      ////////////////////////////////////////////////////////////////////////////
 147:      ////////////////////////////////////////////////////////////////////////////
 148:  }