控制器代码:
publicActionResult DeleteUser(int userID)
{
ReturnJsonVo RtJson = newReturnJsonVo();
//用户ID在借书记录表中作为外键存在
//要删除用户信息,需要线判断在借书记录表中是否正在使用
int countUser =Mymodel.B_Record.Count(m => m.userId == userID);
if (countUser == 0)
{
try
{
//根据ID查询用户信息
S_User dbUser =Mymodel.S_User.Single(o => o.userId == userID);
//判断是否保存了图片
if (System.IO.File.Exists(Server.MapPath("~/Document/UserPicture/") + dbUser.userPicture))
{
System.IO.File.Delete(Server.MapPath("~/Document/UserPicture/") +dbUser.userPicture);
}
//删除用户数据
Mymodel.S_User.Remove(dbUser);
if(Mymodel.SaveChanges() > 0)
{
RtJson.Text