Beispiel #1
0
        //public IActionResult OnPost()
        //{
        //    return Content("fds");
        //}
        public async Task <IActionResult> OnPostNewDicValue(DictionaryValue_Dto dicValue, Guid valueTypeId)
        {
            dicValue.Id = guidGenerator.Create();

            dicValue.ValueType = null;
            try
            {
                DictionaryValueType valueType = dictionaryValueTypeAppService.Repository.WithDetails(x => x.Values).First(x => x.Id == valueTypeId);
                int curCount = valueType.Values.Count;

                dicValue.ValueTypeId = valueTypeId;
                string paddedCode    = $"{valueType.ValueTypeCode}{(curCount + 1).ToString().PadLeft(3, '0')}";
                int    curRetryIndex = 2;
                while (dictionaryValueAppService.Repository.Any(x => x.Key == paddedCode))
                {
                    paddedCode = $"{valueType.ValueTypeCode}{(curCount + curRetryIndex).ToString().PadLeft(3, '0')}";
                    curRetryIndex++;
                }
                dicValue.Key = $"{paddedCode}";

                //valueType.Values.Add(ObjectMapper.Map<DictionaryValue_Dto, DictionaryValue>(dicValue));

                var value = await dictionaryValueAppService.CreateAsync(dicValue);

                value.ValueType = ObjectMapper.Map <DictionaryValueType, DictionaryValueType_Dto>(valueType);
                return(new OkObjectResult(value));
            }
            catch (Exception ex)
            {
                return(new StatusCodeResult(500));
            }
        }
        public void TestIDictionaryValueType_Success()
        {
            var serializer = this.CreateTarget <DictionaryValueType <int, int> >(GetSerializationContext());

            using (var stream = new MemoryStream())
            {
                var value = new DictionaryValueType <int, int>(3)
                {
                    { 1, 1 }, { 2, 2 }, { 3, 3 }
                };
                serializer.Pack(stream, value);
                stream.Position = 0;
                var result = serializer.Unpack(stream);
                Assert.That(result.ToArray(), Is.EquivalentTo(Enumerable.Range(1, 3).Select(i => new KeyValuePair <int, int>(i, i)).ToArray()));
            }
        }