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

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

Staff Entity Framework class for Next Generation Network (NGN) entity 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
   9:  {
  10:      ////////////////////////////////////////////////////////////////////////////
  11:   
  12:      /// <summary publish="true">
  13:      /// Staff Entity Framework class for Next Generation Network (NGN) entity 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 Staff
  30:      {
  31:          /// <summary/>
  32:          public Staff() { }
  33:   
  34:          /// <summary/>
  35:          public int Id { get; set; }
  36:   
  37:          /// <summary/>
  38:          public bool IsHead { get; set; }
  39:   
  40:          /// <summary/>
  41:          public int AdministrativeFrameworkId { get; set; }
  42:   
  43:          /// <summary/>
  44:          public string FirstName { get; set; }
  45:   
  46:          /// <summary/>
  47:          public string MiddleName { get; set; }
  48:   
  49:          /// <summary/>
  50:          public string LastName { get; set; }
  51:   
  52:          /// <summary/>
  53:          public int EmploymentId { get; set; }
  54:   
  55:          /// <summary/>
  56:          public DateTime? EmploymentDate { get; set; }
  57:   
  58:          /// <summary/>
  59:          public string IpPbxExtension { get; set; }
  60:   
  61:          /// <summary/>
  62:          public string TwitterUserName { get; set; }
  63:   
  64:          /// <summary/>
  65:          public DateTime Created { get; set; }
  66:   
  67:          /// <summary/>
  68:          public DateTime Updated { get; set; }
  69:   
  70:          /// <summary/>
  71:          public System.Guid UserId { get; set; }
  72:   
  73:          /// <summary/>
  74:          [NotMapped]       
  75:          public string FullName
  76:          {
  77:              get
  78:              {
  79:                  string fullName;
  80:   
  81:                  fullName = FirstName + " " + MiddleName + " " + LastName;
  82:   
  83:                  fullName = fullName.Replace("  ", " ");
  84:   
  85:                  return fullName;
  86:              }
  87:          }
  88:   
  89:          /// <summary/>
  90:          [NotMapped]
  91:          public string FirstAndMiddleName
  92:          {
  93:              get
  94:              {
  95:                  string firstAndMiddleName;
  96:   
  97:                  firstAndMiddleName = FirstName + " " + MiddleName;
  98:   
  99:                  firstAndMiddleName = firstAndMiddleName.Replace("  ", " ");
 100:   
 101:                  return firstAndMiddleName;
 102:              }
 103:          }
 104:   
 105:          /// <summary/>
 106:          [NotMapped]
 107:          public virtual Ia.Ngn.Cl.Model.Data.Administration.Framework Framework { get; set; }
 108:   
 109:          /// <summary/>
 110:          [NotMapped]
 111:          public Staff Head { get; set; }
 112:   
 113:          /// <summary/>
 114:          [NotMapped]
 115:          public List<Staff> Heads { get; set; }
 116:   
 117:          /// <summary/>
 118:          [NotMapped]
 119:          public List<Staff> Colleagues  { get; set; }
 120:   
 121:          /// <summary/>
 122:          [NotMapped]
 123:          public List<Staff> Subordinates  { get; set; }
 124:   
 125:          /// <summary/>
 126:          [NotMapped]
 127:          public Ia.Cl.Model.Identity.User User  { get; set; }
 128:   
 129:          ////////////////////////////////////////////////////////////////////////////
 130:   
 131:          /// <summary>
 132:          ///
 133:          /// </summary>
 134:          public static bool Create(Staff newStaff, out string result)
 135:          {
 136:              bool b;
 137:   
 138:              b = false;
 139:              result = "";
 140:   
 141:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 142:              {
 143:                  newStaff.Created = newStaff.Updated = DateTime.UtcNow.AddHours(3);
 144:   
 145:                  db.Staff.Add(newStaff);
 146:                  db.SaveChanges();
 147:   
 148:                  b = true;
 149:              }
 150:   
 151:              return b;
 152:          }
 153:   
 154:          ////////////////////////////////////////////////////////////////////////////
 155:   
 156:          /// <summary>
 157:          ///
 158:          /// </summary>
 159:          public static Staff Read(int id)
 160:          {
 161:              Staff staff;
 162:   
 163:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 164:              {
 165:                  staff = (from s in db.Staff where s.Id == id select s).SingleOrDefault();
 166:              }
 167:   
 168:              return staff;
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public static List<Staff> ReadList()
 177:          {
 178:              List<Staff> staffList;
 179:   
 180:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 181:              {
 182:                  staffList = (from s in db.Staff select s).ToList();
 183:              }
 184:   
 185:              return staffList.ToList();
 186:          }
 187:   
 188:          ////////////////////////////////////////////////////////////////////////////
 189:   
 190:          /// <summary>
 191:          ///
 192:          /// </summary>
 193:          public static bool Update(Staff updatedStaff, out string result)
 194:          {
 195:              bool b;
 196:              Staff staff;
 197:   
 198:              b = false;
 199:              result = "";
 200:   
 201:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 202:              {
 203:                  staff = (from s in db.Staff where s.Id == updatedStaff.Id select s).SingleOrDefault();
 204:   
 205:                  if (staff.Update(updatedStaff))
 206:                  {
 207:                      db.Staff.Attach(staff);
 208:                      db.Entry(staff).State = System.Data.Entity.EntityState.Modified;
 209:                  }
 210:   
 211:                  db.SaveChanges();
 212:   
 213:                  b = true;
 214:              }
 215:   
 216:              return b;
 217:          }
 218:   
 219:          ////////////////////////////////////////////////////////////////////////////
 220:   
 221:          /// <summary>
 222:          ///
 223:          /// </summary>
 224:          public bool Update(Staff updatedStaff)
 225:          {
 226:              // below: this will not update Id, Created
 227:              bool updated;
 228:   
 229:              updated = false;
 230:   
 231:              if (this.FirstName != updatedStaff.FirstName) { this.FirstName = updatedStaff.FirstName; updated = true; }
 232:              if (this.MiddleName != updatedStaff.MiddleName) { this.MiddleName = updatedStaff.MiddleName; updated = true; }
 233:              if (this.LastName != updatedStaff.LastName) { this.LastName = updatedStaff.LastName; updated = true; }
 234:              if (this.EmploymentId != updatedStaff.EmploymentId) { this.EmploymentId = updatedStaff.EmploymentId; updated = true; }
 235:              if (this.EmploymentDate != updatedStaff.EmploymentDate) { this.EmploymentDate = updatedStaff.EmploymentDate; updated = true; }
 236:              if (this.IpPbxExtension != updatedStaff.IpPbxExtension) { this.IpPbxExtension = updatedStaff.IpPbxExtension; updated = true; }
 237:              if (this.TwitterUserName != updatedStaff.TwitterUserName) { this.TwitterUserName = updatedStaff.TwitterUserName; updated = true; }
 238:              if (this.IsHead != updatedStaff.IsHead) { this.IsHead = updatedStaff.IsHead; updated = true; }
 239:              if (this.AdministrativeFrameworkId != updatedStaff.AdministrativeFrameworkId) { this.AdministrativeFrameworkId = updatedStaff.AdministrativeFrameworkId; updated = true; }
 240:              if (this.UserId != updatedStaff.UserId) { this.UserId = updatedStaff.UserId; updated = true; }
 241:   
 242:              if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
 243:   
 244:              return updated;
 245:          }
 246:   
 247:          ////////////////////////////////////////////////////////////////////////////
 248:   
 249:          /// <summary>
 250:          ///
 251:          /// </summary>
 252:          public static bool AssignUserId(int staffId, Guid userId)
 253:          {
 254:              bool b;
 255:              Staff updatedStaff;
 256:   
 257:              b = false;
 258:   
 259:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 260:              {
 261:                  updatedStaff = (from s in db.Staff where s.Id == staffId select s).SingleOrDefault();
 262:   
 263:                  if (updatedStaff != null)
 264:                  {
 265:                      updatedStaff.UserId = userId;
 266:                      updatedStaff.Updated = DateTime.UtcNow.AddHours(3);
 267:   
 268:                      db.Staff.Attach(updatedStaff);
 269:   
 270:                      var v = db.Entry(updatedStaff);
 271:                      v.State = System.Data.Entity.EntityState.Modified;
 272:                      db.SaveChanges();
 273:   
 274:                      b = true;
 275:                  }
 276:                  else
 277:                  {
 278:                      b = false;
 279:                  }
 280:              }
 281:   
 282:              return b;
 283:          }
 284:   
 285:          ////////////////////////////////////////////////////////////////////////////
 286:   
 287:          /// <summary>
 288:          ///
 289:          /// </summary>
 290:          public static bool Delete(int id, out string result)
 291:          {
 292:              bool b;
 293:   
 294:              b = false;
 295:   
 296:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 297:              {
 298:                  var v = (from s in db.Staff where s.Id == id select s).FirstOrDefault();
 299:   
 300:                  db.Staff.Remove(v);
 301:                  db.SaveChanges();
 302:   
 303:                  b = true;
 304:                  result = "Staff record deleted. ";
 305:              }
 306:   
 307:              return b;
 308:          }
 309:   
 310:          ////////////////////////////////////////////////////////////////////////////
 311:          ////////////////////////////////////////////////////////////////////////////
 312:      }
 313:   
 314:      ////////////////////////////////////////////////////////////////////////////
 315:      ////////////////////////////////////////////////////////////////////////////
 316:  }