Ejemplo n.º 1
0
        private void CreateOrEditDataTypeParameterValues(Member member)
        {
            IDataTypeParameterValueRepository dataTypeParameterValueRepository = this.Storage.GetRepository <IDataTypeParameterValueRepository>();

            foreach (string key in this.Request.Form.Keys)
            {
                if (key.StartsWith("dataTypeParameter"))
                {
                    int dataTypeParameterId = int.Parse(key.Replace("dataTypeParameter", string.Empty));
                    DataTypeParameterValue dataTypeParameterValue = dataTypeParameterValueRepository.WithDataTypeParameterIdAndMemberId(dataTypeParameterId, member.Id);

                    if (dataTypeParameterValue == null)
                    {
                        dataTypeParameterValue = new DataTypeParameterValue();
                        dataTypeParameterValue.DataTypeParameterId = dataTypeParameterId;
                        dataTypeParameterValue.MemberId            = member.Id;
                        dataTypeParameterValue.Value = this.Request.Form[key];
                        dataTypeParameterValueRepository.Create(dataTypeParameterValue);
                    }

                    else
                    {
                        dataTypeParameterValue.Value = this.Request.Form[key];
                        dataTypeParameterValueRepository.Edit(dataTypeParameterValue);
                    }
                }
            }

            this.Storage.Save();
        }
        private async Task <string> GetParametersAsync(HttpContext httpContext, int?memberId)
        {
            if (memberId == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            IEnumerable <DataType> dataTypes = await httpContext.GetStorage().GetRepository <int, DataType, DataTypeFilter>().GetAllAsync(
                inclusions: new Inclusion <DataType>("DataTypeParameters.DataTypeParameterValues")
                );

            foreach (DataType dataType in dataTypes)
            {
                foreach (DataTypeParameter dataTypeParameter in dataType.DataTypeParameters)
                {
                    DataTypeParameterValue dataTypeParameterValue = dataTypeParameter.DataTypeParameterValues.FirstOrDefault(dtpv => dtpv.MemberId == memberId);

                    if (dataTypeParameterValue != null)
                    {
                        if (sb.Length != 0)
                        {
                            sb.Append(';');
                        }

                        sb.Append($"{dataTypeParameter.Code}={dataTypeParameterValue.Value}");
                    }
                }
            }


            return(sb.ToString());
        }
        private string GetParameters(int?memberId)
        {
            if (memberId == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            foreach (DataType dataType in this.RequestHandler.Storage.GetRepository <IDataTypeRepository>().All().ToList())
            {
                foreach (DataTypeParameter dataTypeParameter in this.RequestHandler.Storage.GetRepository <IDataTypeParameterRepository>().FilteredByDataTypeId(dataType.Id).ToList())
                {
                    DataTypeParameterValue dataTypeParameterValue = this.RequestHandler.Storage.GetRepository <IDataTypeParameterValueRepository>().WithDataTypeParameterIdAndMemberId(dataTypeParameter.Id, (int)memberId);

                    if (dataTypeParameterValue != null)
                    {
                        if (sb.Length != 0)
                        {
                            sb.Append(';');
                        }

                        sb.Append($"{dataTypeParameter.Code}={dataTypeParameterValue.Value}");
                    }
                }
            }


            return(sb.ToString());
        }
Ejemplo n.º 4
0
        private void CreateOrEditDataTypeParameterValues(Member member, string parameters)
        {
            if (member.PropertyDataTypeId == null || string.IsNullOrEmpty(parameters))
            {
                return;
            }

            IDataTypeParameterRepository      dataTypeParameterRepository      = this.Storage.GetRepository <IDataTypeParameterRepository>();
            IDataTypeParameterValueRepository dataTypeParameterValueRepository = this.Storage.GetRepository <IDataTypeParameterValueRepository>();

            foreach (KeyValuePair <string, string> valueByCode in ParametersParser.Parse(parameters))
            {
                DataTypeParameter      dataTypeParameter      = dataTypeParameterRepository.WithDataTypeIdAndCode((int)member.PropertyDataTypeId, valueByCode.Key);
                DataTypeParameterValue dataTypeParameterValue = dataTypeParameterValueRepository.WithDataTypeParameterIdAndMemberId(dataTypeParameter.Id, member.Id);

                if (dataTypeParameterValue == null)
                {
                    dataTypeParameterValue = new DataTypeParameterValue();
                    dataTypeParameterValue.DataTypeParameterId = dataTypeParameter.Id;
                    dataTypeParameterValue.MemberId            = member.Id;
                    dataTypeParameterValue.Value = valueByCode.Value;
                    dataTypeParameterValueRepository.Create(dataTypeParameterValue);
                }

                else
                {
                    dataTypeParameterValue.Value = valueByCode.Value;
                    dataTypeParameterValueRepository.Edit(dataTypeParameterValue);
                }
            }

            this.Storage.Save();
        }