示例#1
0
        public FieldPropertiesAccessType GetFieldAccess(
            FieldPropertiesForEntityType forEntityType,
            int state,
            string fieldName,
            Guid?roleId,
            Guid?userId)
        {
            var fieldMatrixItem = _dataService.GetDbSet <FieldPropertyItem>()
                                  .Where(x => x.ForEntity == forEntityType &&
                                         x.FieldName == fieldName &&
                                         x.State == state &&
                                         (x.RoleId == roleId || x.RoleId == null))
                                  .OrderBy(x => x)
                                  .FirstOrDefault();

            return(fieldMatrixItem?.AccessType ?? FieldPropertiesAccessType.Show);
        }
示例#2
0
        public IEnumerable <string> GetAvailableFields(
            FieldPropertiesForEntityType forEntityType,
            Guid?roleId,
            Guid?userId)
        {
            var hiddenAccessType = FieldPropertiesAccessType.Hidden.ToString().ToLowerFirstLetter();
            var fieldProperties  = GetFor(forEntityType.ToString(), roleId, userId)
                                   .Where(x => !x.isHidden);

            foreach (var prop in fieldProperties)
            {
                bool hasAccess = prop.AccessTypes.Any(x => x.Value != hiddenAccessType);
                if (hasAccess)
                {
                    yield return(prop.FieldName);
                }
            }
        }
示例#3
0
        private List <FieldInfo> GetFieldNames(FieldPropertiesForEntityType entityType)
        {
            var currentUser = _userProvider.GetCurrentUser();

            switch (entityType)
            {
            case FieldPropertiesForEntityType.Orders:
                return(ExtractFieldNamesFromDto <OrderDto>());

            case FieldPropertiesForEntityType.OrderItems:
                return(ExtractFieldNamesFromDto <OrderItemDto>());

            case FieldPropertiesForEntityType.RoutePoints:
                return(ExtractFieldNamesFromDto <RoutePointDto>());

            case FieldPropertiesForEntityType.Shippings:
                return(ExtractFieldNamesFromDto <ShippingDto>());

            default:
                return(new List <FieldInfo>());
            }
        }
示例#4
0
        public IEnumerable <string> GetReadOnlyFields(
            FieldPropertiesForEntityType forEntityType,
            string stateName,
            Guid?roleId,
            Guid?userId)
        {
            var editAccessType  = FieldPropertiesAccessType.Edit.ToString().ToLowerFirstLetter();
            var fieldProperties = GetFor(forEntityType.ToString(), roleId, userId);

            foreach (var prop in fieldProperties)
            {
                bool isReadOnly = true;
                if (prop.AccessTypes.TryGetValue(stateName, out string accessType))
                {
                    isReadOnly = accessType != editAccessType;
                }
                if (isReadOnly)
                {
                    yield return(prop.FieldName);
                }
            }
        }
示例#5
0
        private static Array GetStates(FieldPropertiesForEntityType entityType, string state = "")
        {
            Array states;

            if (string.IsNullOrEmpty(state))
            {
                states = entityType == FieldPropertiesForEntityType.Shippings ||
                         entityType == FieldPropertiesForEntityType.RoutePoints
                    ? Enum.GetValues(typeof(ShippingState))
                    : Enum.GetValues(typeof(OrderState));
            }
            else
            {
                states = new[]
                {
                    entityType == FieldPropertiesForEntityType.Shippings ||
                    entityType == FieldPropertiesForEntityType.RoutePoints
                        ? (int)Enum.Parse <ShippingState>(state, true)
                        : (int)Enum.Parse <OrderState>(state, true)
                };
            }

            return(states);
        }