public bool SetYGInfo(string USERID, string Name, string OPHONE, string StateATT) { try { using (kaoqingEntities db = new kaoqingEntities()) { var uid = Convert.ToInt32(USERID); var entity = db.USERINFO.Where(p => p.USERID == uid).FirstOrDefault(); if (entity != null) { entity.Name = Name; entity.OPHONE = OPHONE; entity.StateATT = Convert.ToInt32(StateATT); db.USERINFO.Attach(entity); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(entity); stateEntity.SetModifiedProperty("Name"); stateEntity.SetModifiedProperty("OPHONE"); stateEntity.SetModifiedProperty("StateATT"); db.SaveChanges(); return(true); } return(false); } } catch { return(false); } }
public int Up_UserInfo(object value) { try { using (kaoqingEntities db = new kaoqingEntities()) { string str = ""; string sql = ""; JArray arrayvalue = (JArray)value; foreach (var a in arrayvalue) { int uid = Convert.ToInt32(((Newtonsoft.Json.Linq.JValue)a).Value); USERINFO entity = db.USERINFO.Where(p => p.USERID == uid).FirstOrDefault(); entity.StateATT = 1; db.USERINFO.Attach(entity); var stateEntity = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(entity); stateEntity.SetModifiedProperty("StateATT"); db.SaveChanges(); str += uid.ToString(); str += ","; } if (str == "") { sql = "update USERINFO set StateATT = 0"; } else { str = str.Substring(0, str.Length - 1); sql = "update USERINFO set StateATT = 0 where USERID not in(" + str + ")"; } db.Database.ExecuteSqlCommand(sql); return(0); } } catch (Exception ex) { return(-1); } }