Exemple #1
0
        public async Task <IIndexResponse> UpdateAsync(OtherDto otherDto)
        {
            // Adds an analayzer to the name property in FermentableDto object.
            await _client.MapAsync <OtherDto>(d => d.Properties(p => p.String(s => s.Name(n => n.Name).Analyzer("autocomplete"))));

            return(await _client.IndexAsync <OtherDto>(otherDto));
        }
Exemple #2
0
        public async Task UpdateAsync(OtherDto otherDto)
        {
            var other = Mapper.Map <OtherDto, Other>(otherDto);
            await _otherRepository.UpdateAsync(other);

            var result = await _otherRepository.GetSingleAsync(otherDto.Id);

            var mappedResult = Mapper.Map <Other, OtherDto>(result);
            await _otherElasticsearch.UpdateAsync(mappedResult);
        }
        public async Task <IActionResult> PostOther([FromBody] OtherDto otherDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _otherService.AddAsync(otherDto);

            return(CreatedAtRoute(new { controller = "others", }, result));
        }
Exemple #4
0
        //Not async
        public OtherDto Add(OtherDto otherDto)
        {
            var other = Mapper.Map <OtherDto, Other>(otherDto);

            _otherRepository.Add(other);
            var result       = _otherRepository.GetSingle(other.OtherId);
            var mappedResult = Mapper.Map <Other, OtherDto>(result);

            _otherElasticsearch.Update(mappedResult);
            return(mappedResult);
        }
Exemple #5
0
        public async Task <OtherDto> AddAsync(OtherDto otherDto)
        {
            var other = AutoMapper.Mapper.Map <OtherDto, Other>(otherDto);
            await _otherRepository.AddAsync(other);

            var result = await _otherRepository.GetSingleAsync(other.OtherId);

            var mappedResult = AutoMapper.Mapper.Map <Other, OtherDto>(result);
            await _otherElasticsearch.UpdateAsync(mappedResult);

            return(mappedResult);
        }
        public async Task <IActionResult> PutOther(int id, [FromBody] OtherDto otherDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != otherDto.Id)
            {
                return(BadRequest());
            }
            await _otherService.UpdateAsync(otherDto);

            return(new StatusCodeResult((int)HttpStatusCode.NoContent));
        }
Exemple #7
0
        public void included_mapping_should_not_inherit_base_mappings_for_other()
        {
            Mapper.CreateMap <ModelObject, DtoObject>()
            .ForMember(d => d.BaseString, m => m.MapFrom(s => s.DifferentBaseString))
            .Include <ModelSubObject, DtoSubObject>();

            Mapper.CreateMap <ModelSubObject, OtherDto>();

            var modelSubObject = new ModelSubObject
            {
                DifferentBaseString = "123",
                SubString           = "456"
            };
            OtherDto dto = Mapper.Map <ModelSubObject, OtherDto>(modelSubObject);

            Assert.Equal("456", dto.SubString);
        }
        private OtherStepDto GetOthersStepDto(Misc misc)
        {
            var otherDto = _otherElasticsearch.Search(misc.Name, 0, 1).FirstOrDefault();

            if (otherDto == null)
            {
                otherDto = new OtherDto
                {
                    Name   = misc.Name,
                    Custom = true,
                };
                otherDto = _otherService.Add(otherDto);
            }
            ;
            var    otherStepDto = Mapper.Map <OtherDto, OtherStepDto>(otherDto);
            double amount       = string.IsNullOrEmpty(misc.Amount) ? 0 : double.Parse(misc.Amount, CultureInfo.InvariantCulture);

            otherStepDto.Amount = (int)Math.Round(amount * 1000, 0);
            return(otherStepDto);
        }
Exemple #9
0
 /// <summary>
 /// 构造注入
 /// </summary>
 /// <param name="myDto1"></param>
 /// <param name="myDto2"></param>
 public Test05Controller(MyDto myDto1,
                         OtherDto otherDto)
 {
     _myDto1   = myDto1;
     _otherDto = otherDto;
 }
Exemple #10
0
 public void Update(OtherDto otherDto)
 {
     // Adds an analayzer to the name property in FermentableDto object.
     _client.Map <OtherDto>(d => d.Properties(p => p.String(s => s.Name(n => n.Name).Analyzer("autocomplete"))));
     _client.Index <OtherDto>(otherDto);
 }
 /// <summary>
 /// 构造注入
 /// </summary>
 /// <param name="otherDto"></param>
 public Test05Controller(OtherDto otherDto)
 {
     _otherDto = otherDto;
 }