public TEUnit_Onboarding AddUnit_Onboarding(TEUnit_Onboarding value) { try { TEUnit_Onboarding result = value; if (!(value.Uniqueid + "".Length > 0)) { //Create result.CreatedOn = System.DateTime.Now; result.LastModifiedOn = System.DateTime.Now; result = db.TEUnit_Onboarding.Add(value); } else { //Edit db = new TEHRIS_DevEntities(); db.TEUnit_Onboarding.Attach(value); foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties()) { string propname = item.Name; if (propname.ToLower() == "createdon") { continue; } object propValue = item.GetValue(value); if (propValue != null || Convert.ToString(propValue).Length != 0) { db.Entry(value).Property(propname).IsModified = true; } } value.LastModifiedOn = System.DateTime.Now; db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true; } } catch (Exception ex) { db.ApplicationErrorLogs.Add( new ApplicationErrorLog { Error = ex.Message, ExceptionDateTime = System.DateTime.Now, InnerException = ex.InnerException != null ? ex.InnerException.Message : "", Source = "From TEUnitonboard| AddUnit_Onboarding | " + this.GetType().ToString(), Stacktrace = ex.StackTrace } ); } db.SaveChanges(); return(db.TEUnit_Onboarding.Find(value.Uniqueid)); }
public TEUnit_Onboarding AddTEUnitOnboarding(TEUnit_Onboarding value) { TEUnit_Onboarding result = value; if (!(value.Uniqueid + "".Length > 0)) { //Create result.CreatedOn = System.DateTime.Now; result.LastModifiedOn = System.DateTime.Now; result = db.TEUnit_Onboarding.Add(value); } else { //Edit db = new TEHRIS_DevEntities(); db.TEUnit_Onboarding.Attach(value); foreach (System.Reflection.PropertyInfo item in result.GetType().GetProperties()) { string propname = item.Name; if (propname.ToLower() == "createdon") { continue; } object propValue = item.GetValue(value); if (propValue != null || Convert.ToString(propValue).Length != 0) { db.Entry(value).Property(propname).IsModified = true; } } value.LastModifiedOn = System.DateTime.Now; db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true; if (value.Status == "Active") { db.Configuration.ProxyCreationEnabled = false; TEUnit_Onboarding unit = db.TEUnit_Onboarding.Where(x => x.Uniqueid == value.Uniqueid).ToList().First(); if (unit != null) { string email = (from teuser in db.UserProfiles where (teuser.UserId == unit.UserID) select teuser.email).ToList().First(); //string tecontact = (from teoint in db.TEContacts // where ((teoint.Emailid == email) && (teoint.Projectid == value.Project) && (teoint.Unitid == value.Unit)) // select teoint.CallName).ToList().First(); //if (tecontact == null) try { TEContact contact = db.TEContacts.Where(x => (x.Emailid == email) && (x.Projectid == value.Project) && (x.Unitid == value.Unit)).ToList().First(); if (contact != null) { SendContact(value); } } catch (Exception ex) { SendContact(value); ex.Message.ToString(); } } } } db.SaveChanges(); //CRUD Mobile //CRUD Email //CRUD Address return(db.TEUnit_Onboarding.Find(value.Uniqueid)); }