public TEContact Post(TEContact value) { TEContact result = value; if (!(value.Uniqueid + "".Length > 0)) { //Create result.CreatedOn = System.DateTime.UtcNow; result.LastModifiedOn = System.DateTime.UtcNow; result = db.TEContacts.Add(value); } else { //Edit db.TEContacts.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.UtcNow; db.Entry(value).Property(x => x.LastModifiedOn).IsModified = true; } db.SaveChanges(); //CRUD Mobile //CRUD Email //CRUD Address return(db.TEContacts.Find(value.Uniqueid)); }
public object SendContact(TEUnit_Onboarding value) { TEUnit_Onboarding unit = db.TEUnit_Onboarding.Where(x => x.Uniqueid == value.Uniqueid).ToList().First(); UserProfile userinfo = db.UserProfiles.Where(x => x.UserId == unit.UserID).ToList().First(); if (userinfo != null) { int?tower = 0; try { TEProjects_UNIT projectunit = db.TEProjects_UNIT.Where(x => (x.PROJECT_ID == value.Project) && (x.AREA == value.Unit)).ToList().First(); if (projectunit != null) { tower = projectunit.TOWERID; } } catch (Exception ex) { ex.Message.ToString(); } TEContact contact = new TEContact { ApprovedBy = userinfo.CallName, ApprovedOn = System.DateTime.Now, CreatedBy = userinfo.CallName, CreatedOn = System.DateTime.Now, //Have to be dynamic... IsDeleted = false, LastModifiedBy = userinfo.CallName, LastModifiedOn = System.DateTime.UtcNow, Projectid = value.Project, Towerid = tower, Unitid = value.Unit, Mobile = userinfo.Phone, Emailid = userinfo.email, DOB = System.DateTime.Now, DOM = System.DateTime.Now, Type = "", PrefferedContact = "", PrefferedMode = "", ISProfileSPublic = false, IsAdvertise = false, Photo = userinfo.photo, Salutation = "", FirstName = "", MiddleName = "", LastName = "", CallName = userinfo.CallName, ContactType = "", Nationality = "", CountryOfBirth = "", Age = 0, Gender = "", MaritalStatus = "", Category = "", Importance = "", PrefferedSaleConsultant = "", TEOrganisation = 0, Status = value.Status, //Type }; return(db.TEContacts.Add(contact)); } return("Success"); }
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)); }