شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

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.ComponentModel.DataAnnotations.Schema;
   4:  using System.Linq;
   5:   
   6:  namespace Ia.Ngn.Cl.Model
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Staff Entity Framework class for Next Generation Network (NGN) entity model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public partial class Staff
  28:      {
  29:          /// <summary/>
  30:          public Staff() { }
  31:   
  32:          /// <summary/>
  33:          public int Id { get; set; }
  34:   
  35:          /// <summary/>
  36:          public bool IsHead { get; set; }
  37:   
  38:          /// <summary/>
  39:          public int AdministrativeFrameworkId { get; set; }
  40:   
  41:          /// <summary/>
  42:          public string FirstName { get; set; }
  43:   
  44:          /// <summary/>
  45:          public string MiddleName { get; set; }
  46:   
  47:          /// <summary/>
  48:          public string LastName { get; set; }
  49:   
  50:          /// <summary/>
  51:          public int EmploymentId { get; set; }
  52:   
  53:          /// <summary/>
  54:          public DateTime? EmploymentDate { get; set; }
  55:   
  56:          /// <summary/>
  57:          public string IpPbxExtension { get; set; }
  58:   
  59:          /// <summary/>
  60:          public DateTime Created { get; set; }
  61:   
  62:          /// <summary/>
  63:          public DateTime Updated { get; set; }
  64:   
  65:          /// <summary/>
  66:          public System.Guid UserId { get; set; }
  67:   
  68:          /// <summary/>
  69:          [NotMapped]
  70:          public string FullName
  71:          {
  72:              get
  73:              {
  74:                  string fullName;
  75:   
  76:                  fullName = FirstName + " " + MiddleName + " " + LastName;
  77:   
  78:                  fullName = fullName.Replace("  ", " ");
  79:   
  80:                  return fullName;
  81:              }
  82:          }
  83:   
  84:          /// <summary/>
  85:          [NotMapped]
  86:          public string FirstAndMiddleName
  87:          {
  88:              get
  89:              {
  90:                  string firstAndMiddleName;
  91:   
  92:                  firstAndMiddleName = FirstName + " " + MiddleName;
  93:   
  94:                  firstAndMiddleName = firstAndMiddleName.Replace("  ", " ");
  95:   
  96:                  return firstAndMiddleName;
  97:              }
  98:          }
  99:   
 100:          /// <summary/>
 101:          [NotMapped]
 102:          public virtual Ia.Ngn.Cl.Model.Business.Administration.Framework Framework { get; set; }
 103:   
 104:          /// <summary/>
 105:          [NotMapped]
 106:          public Staff Head { get; set; }
 107:   
 108:          /// <summary/>
 109:          [NotMapped]
 110:          public List<Staff> Heads { get; set; }
 111:   
 112:          /// <summary/>
 113:          [NotMapped]
 114:          public List<Staff> Colleagues { get; set; }
 115:   
 116:          /// <summary/>
 117:          [NotMapped]
 118:          public List<Staff> Subordinates { get; set; }
 119:   
 120:          /// <summary/>
 121:          [NotMapped]
 122:          public Ia.Cl.Model.Identity.User User { get; set; }
 123:   
 124:          ////////////////////////////////////////////////////////////////////////////
 125:   
 126:          /// <summary>
 127:          ///
 128:          /// </summary>
 129:          public static bool Create(Staff newStaff, out string result)
 130:          {
 131:              bool b;
 132:   
 133:              b = false;
 134:              result = string.Empty;
 135:   
 136:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 137:              {
 138:                  newStaff.Created = newStaff.Updated = DateTime.UtcNow.AddHours(3);
 139:   
 140:                  db.Staff.Add(newStaff);
 141:                  db.SaveChanges();
 142:   
 143:                  b = true;
 144:              }
 145:   
 146:              return b;
 147:          }
 148:   
 149:          ////////////////////////////////////////////////////////////////////////////
 150:   
 151:          /// <summary>
 152:          ///
 153:          /// </summary>
 154:          public static Staff Read(int id)
 155:          {
 156:              Staff staff;
 157:   
 158:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 159:              {
 160:                  staff = (from s in db.Staff where s.Id == id select s).SingleOrDefault();
 161:              }
 162:   
 163:              return staff;
 164:          }
 165:   
 166:          ////////////////////////////////////////////////////////////////////////////
 167:   
 168:          /// <summary>
 169:          ///
 170:          /// </summary>
 171:          public static List<Staff> ReadList()
 172:          {
 173:              List<Staff> staffList;
 174:   
 175:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 176:              {
 177:                  staffList = (from s in db.Staff select s).ToList();
 178:              }
 179:   
 180:              return staffList.ToList();
 181:          }
 182:   
 183:          ////////////////////////////////////////////////////////////////////////////
 184:   
 185:          /// <summary>
 186:          ///
 187:          /// </summary>
 188:          public static bool Update(Staff updatedStaff, out string result)
 189:          {
 190:              bool b;
 191:              Staff staff;
 192:   
 193:              b = false;
 194:              result = string.Empty;
 195:   
 196:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 197:              {
 198:                  staff = (from s in db.Staff where s.Id == updatedStaff.Id select s).SingleOrDefault();
 199:   
 200:                  if (staff.Update(updatedStaff))
 201:                  {
 202:                      db.Staff.Attach(staff);
 203:                      db.Entry(staff).State = System.Data.Entity.EntityState.Modified;
 204:                  }
 205:   
 206:                  db.SaveChanges();
 207:   
 208:                  b = true;
 209:              }
 210:   
 211:              return b;
 212:          }
 213:   
 214:          ////////////////////////////////////////////////////////////////////////////
 215:   
 216:          /// <summary>
 217:          ///
 218:          /// </summary>
 219:          public bool Update(Staff updatedStaff)
 220:          {
 221:              // below: this will not update Id, Created
 222:              bool updated;
 223:   
 224:              updated = false;
 225:   
 226:              if (this.FirstName != updatedStaff.FirstName) { this.FirstName = updatedStaff.FirstName; updated = true; }
 227:              if (this.MiddleName != updatedStaff.MiddleName) { this.MiddleName = updatedStaff.MiddleName; updated = true; }
 228:              if (this.LastName != updatedStaff.LastName) { this.LastName = updatedStaff.LastName; updated = true; }
 229:              if (this.EmploymentId != updatedStaff.EmploymentId) { this.EmploymentId = updatedStaff.EmploymentId; updated = true; }
 230:              if (this.EmploymentDate != updatedStaff.EmploymentDate) { this.EmploymentDate = updatedStaff.EmploymentDate; updated = true; }
 231:              if (this.IpPbxExtension != updatedStaff.IpPbxExtension) { this.IpPbxExtension = updatedStaff.IpPbxExtension; updated = true; }
 232:              if (this.IsHead != updatedStaff.IsHead) { this.IsHead = updatedStaff.IsHead; updated = true; }
 233:              if (this.AdministrativeFrameworkId != updatedStaff.AdministrativeFrameworkId) { this.AdministrativeFrameworkId = updatedStaff.AdministrativeFrameworkId; updated = true; }
 234:              if (this.UserId != updatedStaff.UserId) { this.UserId = updatedStaff.UserId; updated = true; }
 235:   
 236:              if (updated) this.Updated = DateTime.UtcNow.AddHours(3);
 237:   
 238:              return updated;
 239:          }
 240:   
 241:          ////////////////////////////////////////////////////////////////////////////
 242:   
 243:          /// <summary>
 244:          ///
 245:          /// </summary>
 246:          public static bool AssignUserId(int staffId, Guid userId)
 247:          {
 248:              bool b;
 249:              Staff updatedStaff;
 250:   
 251:              b = false;
 252:   
 253:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 254:              {
 255:                  updatedStaff = (from s in db.Staff where s.Id == staffId select s).SingleOrDefault();
 256:   
 257:                  if (updatedStaff != null)
 258:                  {
 259:                      updatedStaff.UserId = userId;
 260:                      updatedStaff.Updated = DateTime.UtcNow.AddHours(3);
 261:   
 262:                      db.Staff.Attach(updatedStaff);
 263:   
 264:                      var v = db.Entry(updatedStaff);
 265:                      v.State = System.Data.Entity.EntityState.Modified;
 266:                      db.SaveChanges();
 267:   
 268:                      b = true;
 269:                  }
 270:                  else
 271:                  {
 272:                      b = false;
 273:                  }
 274:              }
 275:   
 276:              return b;
 277:          }
 278:   
 279:          ////////////////////////////////////////////////////////////////////////////
 280:   
 281:          /// <summary>
 282:          ///
 283:          /// </summary>
 284:          public static bool Delete(int id, out string result)
 285:          {
 286:              bool b;
 287:   
 288:              b = false;
 289:   
 290:              using (var db = new Ia.Ngn.Cl.Model.Ngn())
 291:              {
 292:                  var v = (from s in db.Staff where s.Id == id select s).FirstOrDefault();
 293:   
 294:                  db.Staff.Remove(v);
 295:                  db.SaveChanges();
 296:   
 297:                  b = true;
 298:                  result = "Staff record deleted. ";
 299:              }
 300:   
 301:              return b;
 302:          }
 303:   
 304:          ////////////////////////////////////////////////////////////////////////////
 305:          ////////////////////////////////////////////////////////////////////////////
 306:      }
 307:   
 308:      ////////////////////////////////////////////////////////////////////////////
 309:      ////////////////////////////////////////////////////////////////////////////
 310:  }