Ejemplo n.º 1
0
        public GetUserGroupResponse Any(GetUserGroupRequest request)
        {
            GetUserGroupResponse resp = new GetUserGroupResponse();

            using (var con = this.TenantDbFactory.ObjectsDB.GetNewConnection())
            {
                con.Open();
                string sql = "";
                if (request.id > 0)
                {
                    sql = @"SELECT id,name,description FROM eb_usergroup WHERE id = @id;
                           SELECT id,firstname FROM eb_users WHERE id IN(SELECT userid FROM eb_user2usergroup WHERE groupid = @id AND eb_del = FALSE)";


                    DbParameter[] parameters = { this.TenantDbFactory.ObjectsDB.GetNewParameter("id", System.Data.DbType.Int32, request.id) };

                    var ds = this.TenantDbFactory.ObjectsDB.DoQueries(sql, parameters);
                    Dictionary <string, object> result = new Dictionary <string, object>();
                    foreach (var dr in ds.Tables[0].Rows)
                    {
                        result.Add("name", dr[1].ToString());
                        result.Add("description", dr[2].ToString());
                    }
                    List <int> users = new List <int>();
                    if (ds.Tables.Count > 1)
                    {
                        foreach (EbDataRow dr in ds.Tables[1].Rows)
                        {
                            users.Add(Convert.ToInt32(dr[0]));
                            result.Add(dr[0].ToString(), dr[1]);
                        }
                        result.Add("userslist", users);
                    }
                    resp.Data = result;
                }
                else
                {
                    sql = "SELECT id,name FROM eb_usergroup";
                    var dt = this.TenantDbFactory.ObjectsDB.DoQueries(sql);

                    Dictionary <string, object> returndata = new Dictionary <string, object>();
                    foreach (EbDataRow dr in dt.Tables[0].Rows)
                    {
                        returndata[dr[0].ToString()] = dr[1].ToString();
                    }
                    resp.Data = returndata;
                }
            }
            return(resp);
        }
        public GetUserGroupResponse Get(Guid id)
        {
            IUserGroupRepository  repository = IoC.Container.Resolve <IUserGroupRepository>();
            IPermissionRepository perRepo    = IoC.Container.Resolve <IPermissionRepository>();
            UserGroup             userGroup  = repository.GetById(id.ToString(), "Permissions");
            GetUserGroupResponse  response   = ObjectHelper.Convert <GetUserGroupResponse>(userGroup);

            response.PermissionIds = new List <Guid>();
            foreach (Permission per in userGroup.Permissions)
            {
                response.PermissionIds.Add(per.Id);
            }
            return(response);
        }
        public IResponseData <GetUserGroupResponse> GetRole(Guid id)
        {
            IResponseData <GetUserGroupResponse> response = new ResponseData <GetUserGroupResponse>();

            try
            {
                IUserGroupService    service = IoC.Container.Resolve <IUserGroupService>();
                GetUserGroupResponse role    = service.Get(id);
                response.SetData(role);
            }
            catch (ValidationException ex)
            {
                response.SetErrors(ex.Errors);
                response.SetStatus(System.Net.HttpStatusCode.PreconditionFailed);
            }
            return(response);
        }