Exemplo n.º 1
0
        //---------------保存CRMRoleDep---------------------------
        public CRMRoleDep Save(CRMRoleDep entity)
        {
            if (this.dataCtx.Connection != null)
            {
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                {
                    this.dataCtx.Connection.Open();
                }
            }
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();

            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMRoleDeps
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMRoleDeps.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Exemplo n.º 2
0
        //---------------保存CRMRole---------------------------
        public CRMRole Save(CRMRole entity, IList<CRMProduct> prodList,IList<CRMRoleModule> ModuleRights,
            IList<CRMDepartment> depList, IList<CRMProvince> ProvinceList)
        {
            if (this.dataCtx.Connection != null)
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                    this.dataCtx.Connection.Open();
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();
            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMRoles
                          where t.RoleID == entity.RoleID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMRoles.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                //delete Role relationship with product
                var qryDel = from t in CRMRoleProds
                             where t.RoleID == entity.RoleID
                             select t;
                foreach (var item in qryDel.ToList())
                {
                    this.CRMRoleProds.DeleteOnSubmit(item);
                }
                //add new
                foreach (var prod in prodList)
                {
                    //insert sub product
                    var subList = GetSubProds(prod.ProdID);
                    foreach (var sub in subList)
                    {
                        var p = new CRMRoleProd();
                        p.RoleID = entity.RoleID;
                        p.ProdID = sub;
                        this.CRMRoleProds.InsertOnSubmit(p);
                    }
                }

                this.dataCtx.SubmitChanges();

                //delete Role relationship with module
                var qryDelM = from t in CRMRoleModules
                             where t.RoleID == entity.RoleID
                             select t;
                foreach (var item in qryDelM.ToList())
                {
                    this.CRMRoleModules.DeleteOnSubmit(item);
                }
                //add new
                foreach (var Module in ModuleRights)
                {
                    if (Module!=null)
                    {
                        var p = new CRMRoleModule();
                        p.RoleID = entity.RoleID;
                        p.ModuleID = Module.ModuleID;
                        p.ReadOnly = Module.ReadOnly;
                        p.New = Module.New;
                        p.Edit = Module.Edit;
                        p.Del = Module.Del;
                        this.CRMRoleModules.InsertOnSubmit(p);
                    }

                }
                this.dataCtx.SubmitChanges();

                //delete Role relationship with Department
                var qryDelDep = from t in CRMRoleDeps
                              where t.RoleID == entity.RoleID
                              select t;
                foreach (var item in qryDelDep.ToList())
                {
                    this.CRMRoleDeps.DeleteOnSubmit(item);
                }
                //add new
                foreach (var dep in depList)
                {
                    if (dep != null)
                    {
                        var p = new CRMRoleDep();
                        p.RoleID = entity.RoleID;
                        p.DepID = dep.DepID;
                        this.CRMRoleDeps.InsertOnSubmit(p);
                    }

                }
                this.dataCtx.SubmitChanges();

                //delete Role relationship with province
                var qryDelProvince = from t in CRMRoleProvinces
                             where t.RoleID == entity.RoleID
                             select t;
                foreach (var item in qryDelProvince.ToList())
                {
                    this.CRMRoleProvinces.DeleteOnSubmit(item);
                }
                //add new
                foreach (var prov in ProvinceList)
                {
                    if (prov != null)
                    {
                        var p = new CRMRoleProvince();
                        p.RoleID = entity.RoleID;
                        p.ProvinceID = prov.ProvinceID;
                        this.CRMRoleProvinces.InsertOnSubmit(p);
                    }
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Exemplo n.º 3
0
        //---------------保存CRMRoleDep---------------------------
        public CRMRoleDep Save(CRMRoleDep entity)
        {
            if (this.dataCtx.Connection != null)
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                    this.dataCtx.Connection.Open();
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();
            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMRoleDeps
                          where t.ID == entity.ID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                    this.CopyEntity(obj, entity);
                else
                    this.CRMRoleDeps.InsertOnSubmit(entity);

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return entity;
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }
Exemplo n.º 4
0
        //---------------保存CRMRole---------------------------
        public CRMRole Save(CRMRole entity, IList <CRMProduct> prodList, IList <CRMRoleModule> ModuleRights,
                            IList <CRMDepartment> depList, IList <CRMProvince> ProvinceList)
        {
            if (this.dataCtx.Connection != null)
            {
                if (this.dataCtx.Connection.State == ConnectionState.Closed)
                {
                    this.dataCtx.Connection.Open();
                }
            }
            DbTransaction tran = this.dataCtx.Connection.BeginTransaction();

            dataCtx.Transaction = tran;

            try
            {
                var qry = from t in CRMRoles
                          where t.RoleID == entity.RoleID
                          select t;
                var obj = qry.SingleOrDefault();
                if (obj != null)
                {
                    this.CopyEntity(obj, entity);
                }
                else
                {
                    this.CRMRoles.InsertOnSubmit(entity);
                }

                this.dataCtx.SubmitChanges();
                //delete Role relationship with product
                var qryDel = from t in CRMRoleProds
                             where t.RoleID == entity.RoleID
                             select t;
                foreach (var item in qryDel.ToList())
                {
                    this.CRMRoleProds.DeleteOnSubmit(item);
                }
                //add new
                foreach (var prod in prodList)
                {
                    //insert sub product
                    var subList = GetSubProds(prod.ProdID);
                    foreach (var sub in subList)
                    {
                        var p = new CRMRoleProd();
                        p.RoleID = entity.RoleID;
                        p.ProdID = sub;
                        this.CRMRoleProds.InsertOnSubmit(p);
                    }
                }

                this.dataCtx.SubmitChanges();

                //delete Role relationship with module
                var qryDelM = from t in CRMRoleModules
                              where t.RoleID == entity.RoleID
                              select t;
                foreach (var item in qryDelM.ToList())
                {
                    this.CRMRoleModules.DeleteOnSubmit(item);
                }
                //add new
                foreach (var Module in ModuleRights)
                {
                    if (Module != null)
                    {
                        var p = new CRMRoleModule();
                        p.RoleID   = entity.RoleID;
                        p.ModuleID = Module.ModuleID;
                        p.ReadOnly = Module.ReadOnly;
                        p.New      = Module.New;
                        p.Edit     = Module.Edit;
                        p.Del      = Module.Del;
                        this.CRMRoleModules.InsertOnSubmit(p);
                    }
                }
                this.dataCtx.SubmitChanges();

                //delete Role relationship with Department
                var qryDelDep = from t in CRMRoleDeps
                                where t.RoleID == entity.RoleID
                                select t;
                foreach (var item in qryDelDep.ToList())
                {
                    this.CRMRoleDeps.DeleteOnSubmit(item);
                }
                //add new
                foreach (var dep in depList)
                {
                    if (dep != null)
                    {
                        var p = new CRMRoleDep();
                        p.RoleID = entity.RoleID;
                        p.DepID  = dep.DepID;
                        this.CRMRoleDeps.InsertOnSubmit(p);
                    }
                }
                this.dataCtx.SubmitChanges();

                //delete Role relationship with province
                var qryDelProvince = from t in CRMRoleProvinces
                                     where t.RoleID == entity.RoleID
                                     select t;
                foreach (var item in qryDelProvince.ToList())
                {
                    this.CRMRoleProvinces.DeleteOnSubmit(item);
                }
                //add new
                foreach (var prov in ProvinceList)
                {
                    if (prov != null)
                    {
                        var p = new CRMRoleProvince();
                        p.RoleID     = entity.RoleID;
                        p.ProvinceID = prov.ProvinceID;
                        this.CRMRoleProvinces.InsertOnSubmit(p);
                    }
                }

                this.dataCtx.SubmitChanges();
                tran.Commit();
                return(entity);
            }
            catch (Exception ex)
            {
                tran.Rollback();
                throw ex;
            }
            finally
            {
                dataCtx.Connection.Close();
            }
        }