CYQ MAction,子表 新增,删除,修改 集合
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZDWorkflow.Model;
using ZDWorkflow.Common;
using ZDWorkflow.Common.Extensions;
using CYQ.Data;
using CYQ.Data.Orm;
using CYQ.Data.Table;
namespace ZDWorkflow.BLL
{
/// <summary>
/// GroupRole(角色组与角色关系表)
/// </summary>
public class GroupRoleBLL
{
/// <summary>
/// 分组列表操作角色
/// </summary>
/// <param name="jsonRoles"></param>
/// <param name="user"></param>
/// <returns></returns>
public ResultModel EditGroupRole(string jsonRoles, long GroupId, LoginUserInfo user)
{
ResultModel result = new ResultModel();
using (MAction mc = new MAction(TableNames.GroupRole))
{
mc.BeginTransation();
try
{
//传到过来
List<GroupRole> grlistnew = new List<GroupRole>();
grlistnew = jsonRoles.ToObject<List<GroupRole>>();
// List<long> idsnew = new List<long>();
var idsnew = grlistnew.Select(s => s.RoleId).ToList();
//原数据库
List<GroupRole> grlistold = new List<GroupRole>();
MDataTable dt = mc.Select("GroupId=" + GroupId);
grlistold = dt.ToList<GroupRole>();
//List<long> idsold = new List<long>();
var idsold = grlistold.Select(s => s.RoleId).ToList();
#region 注释
//foreach (GroupRole item in grlistnew) {
// GroupRole ditem = grlistold.FirstOrDefault(s => s.RoleId == item.RoleId);
// if (ditem != null)
// {
// //新增
// }
// else
// {
// //修改
// item.GroupId = GroupId;
// }
//}
//删除
//var del= idsold.Where(w => !idsnew.Contains(w)).ToList();
#endregion
var a = idsnew.Intersect(idsold); // to modify
var b = idsnew.Except(idsold); // to add
var c = idsold.Except(idsnew); // to delete
List<GroupRole> toAddList = new List<GroupRole>();
List<GroupRole> toDeleteList = new List<GroupRole>();
List<GroupRole> toModifyList = new List<GroupRole>();
// set addList
foreach (var bitem in b)
{
var bModel = grlistnew.Find(p => p.RoleId == bitem);
bModel.GroupId = GroupId;
toAddList.Add(bModel);
}
//toAddList = grlistnew.Where(w => b.Contains(w.RoleId)).ToList();
// set delete querymodel
toDeleteList = grlistold.Where(w => c.Contains(w.RoleId)).ToList();
// set modify querymodel
toModifyList = grlistold.Where(w => a.Contains(w.RoleId)).ToList();
//新增
mc.Data.LoadFrom(toAddList);
mc.Insert();
//删除
foreach (GroupRole item in toDeleteList)
{
mc.SetPara("GroupId", item.GroupId);
mc.SetPara("RoleId", item.RoleId);
mc.Delete("GroupId=@GroupId and RoleId=@RoleId");
}
mc.EndTransation();
result.Status = (int)EStatus.Success;
result.Msg = "提交成功!";
}
catch (Exception ex)
{
mc.RollBack();
result = ex;
}
}
return result;
}
}
}
CYQ MAction,子表 新增,删除,修改 集合的更多相关文章
- oracle触发器,一个表新增、修改的同时同步另一张表
oracle创建触发器,把本地新增.修改数据过程同步到另一个服务器上去. 如果是本地,加数据库名即可.如果是远程服务器,不是一台机器,做一个db_link操作即可. ----------------- ...
- 将表A的数据复制到表B,以及关于主表和子表的删除办法
如果表A的数据结构和表B的数据结构是一样的,字段名字可以不用相同,但是对应的数据类型是一样的 这样的情况下可以用如下的方式实现将表A的数据复制到表B INSERT INTO #TEMP2 SELECT ...
- JavaScript学习笔记-商品管理新增/删除/修改功能
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- Javascript-商品管理新增/删除/修改功能
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- asp.net(C#)html无限分类树 可新增 删除 修改
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ProductSort.aspx ...
- DB2 alter 新增/删除/修改列
SQL语句 增加列.修改列.删除列 1 添加字段 语法 : alter table 表名称 add 字段名称 类型 demo: alter table tableName add columnName ...
- Oracle Delete inner的方式,级联删除子表的数据方式。
例子1: from table2 b where a.id=b.id) 例子2: rebatepolicy表是主表,rebatepolicyitems是从表,从表有主表的主键,现在对于主表一些条件的数 ...
- c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)
c#封装DBHelper类 public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...
- Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法
一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Orac ...
随机推荐
- Failed to create the part's controls解决方法
今早打开eclipse,所有的文件均打不开,如下所示: 因为项目从tomcat迁移到weblogic,JDK版本从1.8降到了1.6,EL表达式有些也解析不了,猜想是这其中出现了问题. 解决方法: F ...
- PHP中empty、isset和is_null的使用区别
关于PHP中empty().isset() 和 is_null() 这三个函数的区别,之前记得专门总结过,上次又被问到,网上已经很多,就用几个例子来说明: 测试用例选取: <?php $a;$b ...
- #学习tips——写给自己的语录
用编程证明自己的观点! "我以为我懂了?"-- 花1/3的时间去学去记,剩下的时间应用做记忆实战. 记录一个转变 2018.6.7 (英文字幕-->无字幕!)good job ...
- idea打jar包
昨天碰到个问题:使用idea打成jar包,但是在测试环境一直报错.参考: http://blog.csdn.net/aotian16/article/details/52198378 之后发现原来的j ...
- 使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏 A UIScreenEdgePanGestureRecognizer looks for panning (dra ...
- C++ 的编译过程
Recall that g++ is not actually the C++ compiler – it is a driver program that hides a lot of the co ...
- 为什么要使用base64编码,有哪些情景需求?
Base64编码原理与应用 Java实现BASE64编解码 公钥证书也好,电子邮件数据也好,经常要用到Base64编码,那么为什么要作一下这样的编码呢? 我们知道在计算机中任何数据都是按ascii码存 ...
- luogu P3950 部落冲突
嘟嘟嘟 树剖板子题. #include<cstdio> #include<iostream> #include<algorithm> #include<cma ...
- 刷题防止Time Limit Exceeded(TLE)技巧
1.C++ 不要使用cin,cout,该使用scanf和printf 2.Java 不要使用Scanner,改用BufferedReader 3.Python 在文件开始的地方加入 import ps ...
- SSH 与 SSL
关于 ssh 有人已经总结得非常好了,这里推荐大家看下 阮一峰 写的 ssh原理与应用 写得简单易懂,非常赞. 关于 ssl 这里有一篇博文写得也不错,ssl协议详解 好了,那 ssh 和 ssl ...