public override int Update(FormM form, DFDictionary entity, ref string message) { var currentUser = Util.GetCurrentUser(); if (string.IsNullOrWhiteSpace(entity["UserId"])) { throw new ArgumentNullException("UserId"); } var list = JsonSerializeHelper.DeserializeObject <List <VM_WF_M_USERDEPT> >(Base64StringHelper.ConvertFromBase64String(entity[DFPub.GetKey_GridHiddenValue("grid1")])); if (list == null) { throw new Exception("Invalid grid data"); } WF_M_USERDEPTLoader.DeleteByUserId(entity["UserId"]); list.Where(a => a.selected).ToList().ForEach(a => { var ud = new WF_M_USERDEPT(); ud.PK_GUID = Guid.NewGuid().ToString(); ud.DeptId = a.DeptId; ud.UserId = entity["UserId"]; ud.CreateUser = currentUser.UserName; ud.CreateTime = DateTime.Now; ud.LastModifyUser = currentUser.UserName; ud.LastModifyTime = DateTime.Now; WF_M_USERDEPTLoader.Insert(ud); }); message = "保存成功".GetRes(); return(DFPub.EXECUTE_SUCCESS); }
public override int Update(FormM form, DFDictionary entity, ref string message) { try { var currentUser = Util.GetCurrentUser(); if (string.IsNullOrWhiteSpace(entity["UserId"])) { throw new ArgumentNullException("UserId"); } var list = JsonSerializeHelper.DeserializeObject <List <VM_WF_M_ROLE> >(Base64StringHelper.ConvertFromBase64String(entity[DFPub.GetKey_GridHiddenValue("grid1")])); if (list == null) { throw new Exception("Invalid grid data"); } using (var db = Pub.DB) { var sql = "DELETE FROM WF_M_USERROLE WHERE RoleId=@RoleId and UserId=@UserId"; db.Execute(sql, list.Select(a => new { RoleId = a.RoleId, UserId = entity["UserId"] })); db.Insert(list.Where(a => a.selected).Select(a => new WF_M_USERROLE() { UserRoleId = Guid.NewGuid().ToString(), RoleId = a.RoleId, UserId = entity["UserId"], CreateUser = currentUser.UserName, CreateTime = DateTime.Now, LastModifyUser = currentUser.UserName, LastModifyTime = DateTime.Now })); message = "保存成功".GetRes(); return(DFPub.EXECUTE_SUCCESS); } } catch (Exception ex) { message = ex.Message; return(DFPub.EXECUTE_ERROR); } }