Example #1
0
        //Click Save Button
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (svr.GetActiveUserCount() >= (int)ViewState["LicenseCnt"])
            {
                this.ShowMessage("你最多能创建" + ViewState["LicenseCnt"].ToString() + "个用户");
                return;
            }

            try
            {
                var entity = GetSaveEntity();
                //----get role--------
                List <CRMRole> RList = new List <CRMRole>();
                var            r     = new CRMRole();
                r.RoleID = long.Parse(txtRole.SelectedValue);
                RList.Add(r);

                entity      = svr.Save(entity, RList);
                hidID.Value = entity.UserID.ToString();
                this.ShowSaveOK();
                Response.Redirect("frmUser.aspx");
            }
            catch (Exception ex)
            {
                this.ShowMessage(ex.Message);
            }
        }
Example #2
0
        //Click Save Button
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (svr.GetActiveUserCount() >= (int)ViewState["LicenseCnt"])
            {
                this.ShowMessage("������ܴ���" + ViewState["LicenseCnt"].ToString() + "���û�");
                return;
            }

            try
            {
                var entity = GetSaveEntity();
                //----get role--------
                List<CRMRole> RList = new List<CRMRole>();
                var r = new CRMRole();
                r.RoleID = long.Parse(txtRole.SelectedValue);
                RList.Add(r);

                entity = svr.Save(entity, RList);
                hidID.Value = entity.UserID.ToString();
                this.ShowSaveOK();
                Response.Redirect("frmUser.aspx");
            }
            catch (Exception ex)
            {
                this.ShowMessage(ex.Message);
            }
        }
Example #3
0
        private CRMRole GetSaveEntity()
        {
            var entity = new CRMRole();

            if (string.IsNullOrEmpty(hidID.Value.Trim()) == false)
            {
                entity.RoleID = int.Parse(hidID.Value.Trim());
            }
            if (string.IsNullOrEmpty(txtRole.Text.Trim()) == false)
            {
                entity.Role = txtRole.Text.Trim();
            }
            entity.RoleGrade = int.Parse(ddlGrade.SelectedValue);
            return(entity);
        }
Example #4
0
        /// <summary>
        /// Converts the marketing list into the role.
        /// </summary>
        /// <param name="marketingList">The marketing list.</param>
        /// <returns>The role.</returns>
        public CRMRole Convert(list marketingList)
        {
            Assert.ArgumentNotNull(marketingList, "marketingList");

            var role = new CRMRole(marketingList.listname, marketingList.listid.Value);

            foreach (var attribute in marketingList.GetAttributes())
            {
                if (attribute.Value is DateTime)
                {
                    role.SetPropertyValue(attribute.Key, ((DateTime)attribute.Value).ToLocalTime());
                }
                else
                {
                    role.SetPropertyValue(attribute.Key, attribute.Value);
                }
            }
            return(role);
        }
        /// <summary>
        /// Converts the marketing list into the role.
        /// </summary>
        /// <param name="marketingList">The marketing list.</param>
        /// <returns>The role.</returns>
        public CRMRole Convert(Entity marketingList)
        {
            Assert.ArgumentNotNull(marketingList, "marketingList");

            var role = new CRMRole((string)marketingList[CRMRole.AttributeListName], (Guid)marketingList[CRMRole.AttributeListId]);

            foreach (var attribute in marketingList.Attributes)
            {
                if (attribute.Value is DateTime)
                {
                    role.SetPropertyValue(attribute.Key, ((DateTime)attribute.Value).ToLocalTime());
                }
                else
                {
                    role.SetPropertyValue(attribute.Key, attribute.Value);
                }
            }
            return(role);
        }
Example #6
0
        //Click Save Button
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var entity = GetSaveEntity();
                //----get role--------
                List <CRMRole> RList = new List <CRMRole>();
                var            r     = new CRMRole();
                r.RoleID = long.Parse(txtRole.SelectedValue);
                RList.Add(r);

                entity      = svr.Save(entity, RList);
                hidID.Value = entity.UserID.ToString();
                this.ShowSaveOK();
            }
            catch (Exception ex)
            {
                this.ShowMessage(ex.Message);
            }
        }
Example #7
0
        //Click Save Button
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var entity = GetSaveEntity();
                //----get role--------
                List<CRMRole> RList = new List<CRMRole>();
                var r = new CRMRole();
                r.RoleID = long.Parse(txtRole.SelectedValue);
                RList.Add(r);

                entity = svr.Save(entity, RList);
                hidID.Value = entity.UserID.ToString();
                this.ShowSaveOK();
            }
            catch (Exception ex)
            {
                this.ShowMessage(ex.Message);
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CrmRoleProviderTest"/> class.
        /// </summary>
        public CrmRoleProviderTest()
        {
            var cacheService   = Substitute.For <ICacheService>();
            var userRepository = Substitute.For <UserRepositoryBase>(cacheService);

            this.roleRepository = Substitute.For <RoleRepositoryBase>(userRepository, cacheService);

            this.roleRepositoryFactory = Substitute.For <IRoleRepositoryFactory>();
            this.roleRepositoryFactory.GetRepository(Arg.Any <ConfigurationSettings>()).Returns(this.roleRepository);

            var config = new NameValueCollection();

            config.Add("name", "crm");
            config.Add("applicationName", "CRM security provider");
            config.Add("readOnly", "false");
            config.Add("connectionStringName", "CRMConnString");

            this.crmRoleProvider = new CRMRoleProvider(this.roleRepositoryFactory);
            this.crmRoleProvider.Initialize(config["name"], config);

            this.role = new CRMRole("test", Guid.NewGuid());
        }
        //---------------保存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();
            }
        }
Example #10
0
 private CRMRole GetSaveEntity()
 {
     var entity = new CRMRole();
     if (string.IsNullOrEmpty(hidID.Value.Trim()) == false)
         entity.RoleID = int.Parse(hidID.Value.Trim());
     if (string.IsNullOrEmpty(txtRole.Text.Trim()) == false)
         entity.Role = txtRole.Text.Trim();
     entity.RoleGrade = int.Parse(ddlGrade.SelectedValue);
     return entity;
 }
Example #11
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();
            }
        }