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

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