public int AddMember(Member m,byte[] picData) { YogaEntities ye = new YogaEntities(); var mmm = ye.Member.FirstOrDefault((mm) =>mm.CardNo == m.CardNo); if (mmm != null) return -2;//已经存在卡号 ye.AddToMember(m); int id = ye.SaveChanges()==1 ? m.Id : -1; if (id > 0&& picData!=null) { FileStream fs = null; try { fs = new FileStream(Server.MapPath(string.Format("Images/{0}.jpg", m.Id)), FileMode.Create, FileAccess.Write); fs.Write(picData, 0, picData.Length); } finally { if (fs != null) fs.Close(); } } return id; }