public IEnumerable <FieldForFieldProperties> GetFor([FromBody] FieldPropertiesGetForParams getForParams)
        {
            var roleId = string.IsNullOrEmpty(getForParams.RoleId)
                ? (Guid?)null
                : Guid.Parse(getForParams.RoleId);

            return(fieldPropertiesService.GetFor(getForParams.ForEntity, roleId, null));
        }
Exemplo n.º 2
0
        public bool Import(Stream stream, FieldPropertiesGetForParams props)
        {
            stream.Seek(0, SeekOrigin.Begin);
            byte[] bytes          = new byte[stream.Length];
            int    numBytesToRead = (int)stream.Length;
            int    numBytesRead   = 0;

            while (numBytesToRead > 0)
            {
                int n = stream.Read(bytes, numBytesRead, numBytesToRead);
                if (n == 0)
                {
                    break;
                }
                numBytesRead   += n;
                numBytesToRead -= n;
            }

            var res = Encoding.UTF8.GetString(bytes);

            try
            {
                var fieldProperties = JsonConvert.DeserializeObject <IEnumerable <FieldForFieldProperties> >(res);
                foreach (var prop in fieldProperties)
                {
                    SetHiddenState(new FieldPropertyDto()
                    {
                        ForEntity = props.ForEntity,
                        FieldName = prop.FieldName,
                        RoleId    = props.RoleId
                    }, prop.isHidden);
                    foreach (var accessType in prop.AccessTypes)
                    {
                        Save(new FieldPropertyDto
                        {
                            ForEntity  = props.ForEntity,
                            FieldName  = prop.FieldName,
                            RoleId     = props.RoleId,
                            AccessType = accessType.Value,
                            State      = accessType.Key
                        });
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }