public ActionResult AddAdminUser(AdminUserAddModel model) { if (!ModelState.IsValid) { return(Json(new AjaxResult <object> { code = 1, msg = CommonHelper.GetValidMsg(ModelState) })); } if (AdminUserService.GetByPhoneNum(model.PhoneNum) != null) { return(Json(new AjaxResult <object> { code = 1, msg = "手机号已存在" })); } try { using (TransactionScope sc = new TransactionScope()) { long?cityid = null; if (model.City != 0) { cityid = model.City; } var id = AdminUserService.AddAdminUser(model.Name, model.PhoneNum, model.Password, model.Email, cityid); AdminUserService.AddAdminUserRole(id, model.Roles); sc.Complete(); } return(Json(new AjaxResult <object> { code = 0, msg = "添加成功" })); } catch (Exception ex) { Log.ErrorFormat("添加管理员用户失败:{0}", ex.Message); return(Json(new AjaxResult <object> { code = 1, msg = ex.Message })); } }
public ActionResult Edit(AdminUserEditModel model) { if (!ModelState.IsValid) { return(Json(new AjaxResult <object> { code = 1, msg = CommonHelper.GetValidMsg(ModelState) })); } try { using (TransactionScope sc = new TransactionScope()) { long?cityId = null; if (model.CityId != 0) { cityId = model.CityId; } AdminUserService.UpdateAdminUser(model.Id, model.Name, model.PhoneNum, model.Password, model.Email, cityId); AdminUserService.AddAdminUserRole(model.Id, model.RoleIds); sc.Complete(); sc.Dispose(); } return(Json(new AjaxResult <object> { code = 0, msg = "编辑成功" })); } catch (Exception ex) { Log.ErrorFormat("编辑管理员用户失败:{0}", ex.Message); return(Json(new AjaxResult <object> { code = 1, msg = ex.Message })); } }