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:          /// <summary/>
  35:          public static Guid FieldUserGuid { get { return new Guid("0B0152F0-2F74-4603-BB3B-B571457B2995"); } }
  36:   
  37:          /// <summary/>
  38:          public static Guid TndUserGuid { get { return new Guid("2B83AD5B-1C70-499A-A9F1-DE3334AAE1A3"); } }
  39:   
  40:          ////////////////////////////////////////////////////////////////////////////
  41:   
  42:          /// <summary>
  43:          ///
  44:          /// </summary>
  45:          public static void Create(Ia.Ngn.Cl.Model.Contact newContact, out Ia.Cl.Model.Result result)
  46:          {
  47:              result = new Ia.Cl.Model.Result();
  48:   
  49:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  50:              {
  51:                  newContact.Created = newContact.Updated = DateTime.UtcNow.AddHours(3);
  52:   
  53:                  db.Contacts.Add(newContact);
  54:                  db.SaveChanges();
  55:   
  56:                  result.AddSuccess(@"Contact """ + newContact.FullName + @""" created. ");
  57:              }
  58:          }
  59:   
  60:          ////////////////////////////////////////////////////////////////////////////
  61:   
  62:          /// <summary>
  63:          ///
  64:          /// </summary>
  65:          public static Ia.Ngn.Cl.Model.Contact Read(int id)
  66:          {
  67:              Ia.Ngn.Cl.Model.Contact contact;
  68:   
  69:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
  70:              {
  71:                  contact = (from c in db.Contacts where c.Id == id select c).SingleOrDefault();
  72:              }
  73:   
  74:              return contact;
  75:          }
  76:   
  77:          ////////////////////////////////////////////////////////////////////////////
  78:   
  79:          /// <summary>
  80:          ///
  81:          /// </summary>
  82:          public static List<Ia.Ngn.Cl.Model.Contact> List
  83:          {
  84:              get
  85:              {
  86:                  List<Ia.Ngn.Cl.Model.Contact> contactList;
  87:   
  88:                  using (var db = new Ia.Ngn.Cl.Model.Ngn())
  89:                  {
  90:                      contactList = (from c in db.Contacts select c).ToList();
  91:                  }
  92:   
  93:                  return contactList;
  94:              }
  95:          }
  96:   
  97:          ////////////////////////////////////////////////////////////////////////////
  98:   
  99:          /// <summary>
 100:          ///
 101:          /// </summary>
 102:          public static void Update(Ia.Ngn.Cl.Model.Contact updatedContact, out Ia.Cl.Model.Result result)
 103:          {
 104:              Ia.Ngn.Cl.Model.Contact contact;
 105:   
 106:              result = new Ia.Cl.Model.Result();
 107:   
 108:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 109:              {
 110:                  contact = (from c in db.Contacts where c.Id == updatedContact.Id select c).SingleOrDefault();
 111:   
 112:                  if (contact.Update(updatedContact))
 113:                  {
 114:                      db.Contacts.Attach(contact);
 115:                      db.Entry(contact).State = System.Data.Entity.EntityState.Modified;
 116:   
 117:                      result.AddSuccess("Contact " + updatedContact.FullName + @" updated. ");
 118:                  }
 119:                  else
 120:                  {
 121:                      result.AddWarning(@"No change in contact's information. Contact """ + updatedContact.FullName + @""" was not updated. ");
 122:                  }
 123:   
 124:                  db.SaveChanges();
 125:              }
 126:          }
 127:   
 128:          ////////////////////////////////////////////////////////////////////////////
 129:   
 130:          /// <summary>
 131:          ///
 132:          /// </summary>
 133:          public static void Delete(int id, out Ia.Cl.Model.Result result)
 134:          {
 135:              result = new Ia.Cl.Model.Result();
 136:   
 137:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 138:              {
 139:                  var contact = (from c in db.Contacts where c.Id == id select c).FirstOrDefault();
 140:   
 141:                  db.Contacts.Remove(contact);
 142:                  db.SaveChanges();
 143:   
 144:                  result.AddSuccess(@"Contact """ + contact.FullName + @""" deleted. ");
 145:              }
 146:          }
 147:   
 148:          ////////////////////////////////////////////////////////////////////////////
 149:          ////////////////////////////////////////////////////////////////////////////
 150:      }
 151:   
 152:      ////////////////////////////////////////////////////////////////////////////
 153:      ////////////////////////////////////////////////////////////////////////////
 154:  }