Exemple #1
0
        public List <RolesEntity> GetAllRoles()
        {
            string             strSql = @"SELECT *
                              FROM [Roles]
                              WHERE [Status]=0 OR [Status]=1
                              ORDER BY  [RoleID] DESC";
            List <RolesEntity> list   = new List <RolesEntity>();
            Database           db     = DatabaseFactory.CreateDatabase();

            using (DbCommand dbCommand = db.GetSqlStringCommand(strSql))
            {
                try
                {
                    using (IDataReader dataReader = db.ExecuteReader(dbCommand))
                        while (dataReader.Read())
                        {
                            list.Add(RolesEntity.ReaderBind(dataReader));
                        }
                }
                catch (Exception ex)
                {
                    WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]"
                                                    , strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message));
                    return(null);
                }
            }
            return(list);
        }
Exemple #2
0
        public async Task <RoleViewModel> Post(JObject json)
        {
            _invillaContext = new InvillaContext();

            try
            {
                var model = JsonConvert.DeserializeObject <RoleViewModel>(json.ToString());
                model.RegistrationDate = DateTime.Now;
                var role = new RolesEntity
                {
                    Role             = model.Role,
                    RegistrationDate = model.RegistrationDate
                };
                _invillaContext.Add(role);
                _invillaContext.SaveChanges();

                return(model);
            }
            catch (Exception ex)
            {
                return(new RoleViewModel
                {
                });
            }
        }
Exemple #3
0
        public JObject AddRolesInfo([FromBody] RolesEntity _userRoleEntity)
        {
            DataResult result = new DataResult()
            {
                Verifiaction = false
            };

            try
            {
                if (_rolesRepsonsityService.IsExists(x => x.RolesName == _userRoleEntity.RolesName))
                {
                    result.Message = "角色名称已经存在!";
                    return(JObject.FromObject(result));
                }


                RolesEntity userRoleEntity = new RolesEntity
                {
                    ID         = Guid.NewGuid().ToString(),
                    RolesName  = _userRoleEntity.RolesName,
                    CreateDate = DateTime.Now.ToString(),
                    Remark     = _userRoleEntity.Remark
                };
                _rolesRepsonsityService.Insert(userRoleEntity);

                result.Verifiaction = true;
                result.Message      = "写入成功!";
            }
            finally
            {
            }

            return(JObject.FromObject(result));
        }
Exemple #4
0
        /// <summary>
        /// Get an object entity
        /// </summary>
        public RolesEntity Get(int RoleID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select RoleID,RoleName,Description,Status,CreatedOn,CreatedBy from Roles ");
            strSql.Append(" where RoleID=@RoleID ");
            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()))
            {
                try
                {
                    db.AddInParameter(dbCommand, "RoleID", DbType.Int32, RoleID);
                    RolesEntity model = null;
                    using (IDataReader dataReader = db.ExecuteReader(dbCommand))
                    {
                        if (dataReader.Read())
                        {
                            model = RolesEntity.ReaderBind(dataReader);
                        }
                    }
                    return(model);
                }
                catch (Exception ex)
                {
                    WebLogAgent.Write(string.Format("[SQLText:{0},{1}Messages:\r\n{2}]"
                                                    , strSql.ToString(), base.FormatParameters(dbCommand.Parameters), ex.Message));
                    return(null);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(RolesEntity entity)
        {
            if (entity.RoleID <= 0)
            {
                entity.RoleID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Roles (" +
                            "RoleID," +
                            "RoleName," +
                            "Description) " +
                            "values(" +
                            "@RoleID," +
                            "@RoleName," +
                            "@Description)";

            if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)))
            {
                return(DataConverter.CLng(entity.RoleID));
            }
            return(-1);
        }
        public bool AssignRoleToUser(ApplicationEntity application, UserEntity user, RolesEntity role)
        {
            try
            {
                using (IUnitOfWork uow = _UnitFactory.GetUnit(this))
                {
                    uow.BeginTransaction();
                    if (!uow.Query <AppUserRoleEntity>().Any(x => x.ApplicationId.Equals(application.IdApplication) && x.RoleId.Equals(role.Id) && x.UserId.Equals(user.Id)))
                    {
                        AppUserRoleEntity app = new AppUserRoleEntity();
                        app.ApplicationId = app.ApplicationId;
                        app.RoleId        = role.Id;
                        app.UserId        = user.Id;
                        uow.SaveOrUpdate(app);

                        uow.Commit();
                        return(true);
                    }
                }
            }
            catch (Exception err)
            {
                //TODO:Add log here
                return(false);
            }
            return(true);
        }
Exemple #7
0
        public static void EnsureSampleData()
        {
            List <UserEntity> userList = RepositoryContext.Current.Users.GetAll();


            if (userList == null || userList.Count == 0)
            {
                ApplicationEntity app = new ApplicationEntity();
                app.ApplicationName = "SampleApp";
                app.IsActive        = true;
                app.StartDate       = DateTime.Now;
                app.EndDate         = DateTime.Now.AddYears(1);
                app.PublicKey       = new Guid("{8C075ED0-45A7-495A-8E09-3A98FD6E8248}");
                RepositoryContext.Current.Applications.Save(app);

                // Insert admin user
                UserEntity user = new UserEntity();
                user.CreationDate = DateTime.Now;
                user.Email        = "*****@*****.**";
                user.IsAdmin      = true;
                user.IsApproved   = true;
                user.IsLockedOut  = false;
                user.Password     = UserHelper.EncodePassword("12345678");
                user.Username     = "******";

                RepositoryContext.Current.Users.Save(user);

                RolesEntity role = RepositoryContext.Current.Roles.GetRoleByName(Constants.Roles.Admin);
                RepositoryContext.Current.Applications.AssignRoleToUser(app, user, role);
            }
        }
        public int AddRole(RolesEntity role)
        {
            this.ClearBrokenRuleMessages();
            int id = mgr.AddRole(role);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(id);
        }
        public bool UpdateRole(RolesEntity role)
        {
            this.ClearBrokenRuleMessages();
            bool updated = mgr.UpdateRole(role);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(updated);
        }
        public RolesEntity GetRole(int roleID)
        {
            this.ClearBrokenRuleMessages();
            RolesEntity role = mgr.GetRole(roleID);

            this.AddBrokenRuleMessages(mgr.BrokenRuleMessages);
            return(role);
        }
Exemple #11
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static RolesEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            RolesEntity info = new RolesEntity();

            info.RoleID      = rdr.GetInt32("RoleID");
            info.RoleName    = rdr.GetString("RoleName");
            info.Description = rdr.GetString("Description");
            return(info);
        }
Exemple #12
0
        private RolesEntity GetEntity()
        {
            RolesEntity model = userApp.GetRole(QS("id", 0));

            model.RoleName    = txtRoleName.Text.NoHTML();
            model.Description = txtDesc.Text.NoHTML();
            model.Status      = int.Parse(ddlStatus.SelectedValue);

            return(model);
        }
Exemple #13
0
        private RolesEntity GetEntity()
        {
            RolesEntity model = UsersFactory.CreateRolesEntity(UserInfo.UserID, ObjectFactory.GetInstance <ISystemDateTime>());

            model.RoleName    = txtRoleName.Text.NoHTML();
            model.Description = txtDesc.Text.NoHTML();
            model.Status      = int.Parse(ddlStatus.SelectedValue);

            return(model);
        }
        public RoleDTO GetDTO(RolesEntity entity)
        {
            RoleDTO role = new RoleDTO()
            {
                Id             = entity.Id,
                Name           = entity.Name,
                CreateDateTime = entity.CreateDateTime
            };

            return(role);
        }
Exemple #15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     userApp = new UserApplication();
     if (!IsPostBack)
     {
         RolesEntity entity = userApp.GetRole(QS("id", 0));
         txtRoleName.Text        = entity.RoleName;
         txtDesc.Text            = entity.Description;
         ddlStatus.SelectedValue = entity.Status.ToString();
     }
 }
Exemple #16
0
        public static void InsertRoleIfNotExists(string Rolename)
        {
            RolesEntity role = RepositoryContext.Current.Roles.GetRoleByName(Rolename);

            if (role == null)
            {
                RepositoryContext.Current.Roles.Save(new RolesEntity()
                {
                    RoleName = Rolename
                });
            }
        }
Exemple #17
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            RolesEntity model = GetEntity();

            if (userApp.UpdateRole(model))
            {
                Redirect(EmptyPopPageUrl, false, true);
            }
            else
            {
                this.ShowFailMessageToClient(userApp.BrokenRuleMessages);
            }
        }
Exemple #18
0
        /// <summary>
        /// 得到  roles 数据实体
        /// </summary>
        /// <param name="dr">dr</param>
        /// <returns>roles 数据实体</returns>
        public RolesEntity Populate_RolesEntity_FromDr(IDataReader dr)
        {
            RolesEntity Obj = new RolesEntity();

            Obj.RoleId      = ((dr["RoleId"]) == DBNull.Value)?0:Convert.ToInt32(dr["RoleId"]);
            Obj.ShopId      = ((dr["ShopId"]) == DBNull.Value)?0:Convert.ToInt32(dr["ShopId"]);
            Obj.Name        = dr["Name"].ToString();
            Obj.Permission  = ((dr["Permission"]) == DBNull.Value)?0:Convert.ToInt32(dr["Permission"]);
            Obj.price       = ((dr["price"]) == DBNull.Value)?0:Convert.ToDecimal(dr["price"]);
            Obj.Description = dr["Description"].ToString();

            return(Obj);
        }
Exemple #19
0
        public string GetModel(string id)
        {
            try
            {
                RolesEntity rolesEntity = new RolesEntity();
                rolesEntity = _rolesRepsonsityService.GetById(id);
                return(JsonConvert.SerializeObject(rolesEntity));
            }
            catch (Exception ex)
            {
            }

            return("成功");
        }
Exemple #20
0
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Update(RolesEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Roles SET " +
                            "RoleName = @RoleName," +
                            "Description = @Description" +
                            " WHERE " +

                            "RoleID = @RoleID";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Exemple #21
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(RolesEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Roles SET " +
                            "RoleName = @RoleName," +
                            "Description = @Description" +
                            " WHERE " +

                            "RoleID = @RoleID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemple #22
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual RolesEntity GetEntity(string strWhere, Dictionary <string, object> dict = null)
        {
            RolesEntity obj    = null;
            string      strSQL = "select top 1 * from Roles where 1=1 " + strWhere;

            using (NullableDataReader reader = _DB.GetDataReader(strSQL, dict))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemple #23
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <RolesEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            RolesEntity obj    = null;
            string      strSQL = "select top 1 * from Roles where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemple #24
0
        public string RolesTest1(string id)
        {
            try
            {
                RolesEntity rolesEntity = new RolesEntity();
                _rolesRepsonsityService.Delete(id);
                _rolesRepsonsityService.SaveChange();
            }
            catch (Exception ex)
            {
            }

            return("成功");
        }
        /// <summary>
        /// 账户修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            Button        btn      = sender as Button;
            RolesEntity   role     = btn.Tag as RolesEntity;
            RoleAddDialog view     = new RoleAddDialog(role);
            bool?         nullable = view.ShowDialog();
            bool          flag     = true;

            if ((nullable.GetValueOrDefault() == flag ? (nullable.HasValue ? 1 : 0) : 0) == 0)
            {
                return;
            }
            RefreshData();
        }
Exemple #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = QS("id", 0);
                if (id == 0)
                {
                    this.ShowArgumentErrorMessageToClient();
                    return;
                }
                RolesEntity role = userApp.GetRole(id);

                InitControl(id);
            }
        }
Exemple #27
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            RolesEntity model = GetEntity();

            int id = userApp.AddRole(model);

            if (id > 0)
            {
                this.ShowSuccessMessageToClient();
            }
            else
            {
                this.ShowFailMessageToClient(userApp.BrokenRuleMessages);
            }
        }
Exemple #28
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         int id = QS("id", 0);
         if (id == 0)
         {
             this.ShowArgumentErrorMessageToClient();
             return;
         }
         RolesEntity role = userApp.GetRole(id);
         ltlRole.Text = string.Format("{0}[{1}]", role.RoleName, role.Description);
         InitControl(id);
     }
 }
        /// <summary>
        /// 删除账户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            Button      btn  = sender as Button;
            RolesEntity role = btn.Tag as RolesEntity;

            //if (MessageBox.Show("确认删除该角色吗?", "提示", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
            //    return;
            if ((new RolesDB()).Delete(role) < 1)
            {
                //MessageBox.Show("删除数据过程出现错误!", "错误", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                AppContext.Current.RoleData.Remove(role);
            }
        }
Exemple #30
0
        public string RolesTest1()
        {
            try
            {
                RolesEntity rolesEntity = new RolesEntity();
                rolesEntity.ID         = "76d71a4d-daa1-4b9e-885a-be789579a4e5";
                rolesEntity.RolesName  = "李四";
                rolesEntity.CreateDate = DateTime.Now.ToString();
                _rolesRepsonsityService.Update(rolesEntity);
                _rolesRepsonsityService.SaveChange();
            }
            catch (Exception ex)
            {
            }

            return("成功");
        }