public void ChangeMessageStatus(int status, params string[] messageIds)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                string        updateSql  = MessageService_SQL.UpdateMessageStatus;
                List <object> _sqlParams = new List <object>();

                _sqlParams.Add(status);

                string messageIdsJoin = messageIds.Length == 0 ? string.Empty : string.Join(",", messageIds);
                _sqlParams.Add(messageIdsJoin);

                dbContext.ExecuteSql(updateSql, _sqlParams.ToArray());
            }
        }
Example #2
0
        public void EditMenuForRole(string roleId, string[] hasMenuIds, string updater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Role> commonService = new CommonService <Role>(dbContext);

                bool isExist = commonService.AnyByIdNoMarkDeleted(roleId);
                if (!isExist)
                {
                    throw new PushToUserException("Current role item is not exist");
                }

                try
                {
                    dbContext.DBTransaction.Begin();

                    dbContext.ExecuteSql(RoleService_SQL.MarkDeleteAllMenuPermsOfRole, roleId);

                    foreach (string menuId in hasMenuIds)
                    {
                        var permItem = dbContext.Queryable <Permission>().Select(p => new { p.Id }).Where(p => p.DelFlag == 0 && p.MenuId == menuId).ToOne();

                        if (null == permItem)
                        {
                            throw new PushToUserException("menu item is not exist");
                        }

                        dbContext.Add(new Role_Permission
                        {
                            Id           = Utils.GetGuidStr(),
                            RoleId       = roleId,
                            PermissionId = permItem.Id,
                            Creater      = updater,
                            Updater      = updater
                        });
                    }

                    dbContext.DBTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContext.DBTransaction.Rollback();

                    throw ex;
                }
            }
        }
Example #3
0
        public void EditApiPermForRole(string roleId, string[] hasApiPermissionIds, string updater)
        {
            using (MiniSenDbContext dbContext = new MiniSenDbContext())
            {
                CommonService <Role> commonService = new CommonService <Role>(dbContext);

                bool isExist = commonService.AnyByIdNoMarkDeleted(roleId);
                if (!isExist)
                {
                    throw new PushToUserException("Current role item is not exist");
                }

                try
                {
                    dbContext.DBTransaction.Begin();

                    dbContext.ExecuteSql(RoleService_SQL.MarkDeleteAllApiPermsOfRole, roleId);

                    foreach (string apiPermissionId in hasApiPermissionIds)
                    {
                        dbContext.Add(new Role_Permission
                        {
                            Id           = Utils.GetGuidStr(),
                            RoleId       = roleId,
                            PermissionId = apiPermissionId,
                            Creater      = updater,
                            Updater      = updater
                        });
                    }

                    dbContext.DBTransaction.Commit();
                }
                catch (Exception ex)
                {
                    dbContext.DBTransaction.Rollback();

                    throw ex;
                }
            }
        }