private ItemPriceAndCurrencyResponse MapManuallyFromDtoToModel(ItemPriceAndCurrencyResponseDTO dto)
        {
            var model = _mapper.Map <ItemPriceAndCurrencyResponse>(dto);

            model.Groups = new List <Groups>();
            foreach (var group in dto.Groups)
            {
                var mGroup = _mapper.Map <Groups>(group);
                mGroup.Currency   = model;
                mGroup.CurrencyId = model.Id;
                model.Groups.Add(mGroup);
                foreach (var item in group.Items)
                {
                    var mItem = _mapper.Map <Item>(item);
                    mItem.Group   = mGroup;
                    mItem.GroupId = mGroup.Id;
                    mGroup.Item.Add(mItem);
                    foreach (var itemDay in item.ItemDays)
                    {
                        var mItemDay = _mapper.Map <ItemDay>(itemDay);
                        mItemDay.Item   = mItem;
                        mItemDay.ItemId = mItem.Id;
                        mItem.ItemDay.Add(mItemDay);
                    }
                }
            }
            return(model);
        }
        public async Task <ServiceResponse <ItemPriceAndCurrencyResponseDTO> > Add(ItemPriceAndCurrencyResponseDTO dto)
        {
            var serviceResponse = new ServiceResponse <ItemPriceAndCurrencyResponseDTO>();
            var cmd             = this.MapManuallyFromDtoToModel(dto);
            await _context.ItemPriceAndCurrencyResponse.AddAsync(cmd);

            await _context.SaveChangesAsync();

            serviceResponse.Data = dto;
            _logger.Information("PriceService - added itempriceandcurrencyresponse with currency: {Currency}", dto.Currency);
            return(serviceResponse);
        }
Пример #3
0
 public async Task <IActionResult> Update(ItemPriceAndCurrencyResponseDTO cmd)
 {
     return(Ok(await _service.Update(cmd)));
 }
Пример #4
0
 public async Task <IActionResult> Add(ItemPriceAndCurrencyResponseDTO dto)
 {
     return(Ok(await _service.Add(dto)));
 }
        public async Task <ServiceResponse <ItemPriceAndCurrencyResponseDTO> > Update(ItemPriceAndCurrencyResponseDTO dto)
        {
            var serviceResponse = new ServiceResponse <ItemPriceAndCurrencyResponseDTO>();
            var cmd             = this.MapManuallyFromDtoToModel(dto);

            _context.ItemPriceAndCurrencyResponse.Update(cmd);
            await _context.SaveChangesAsync();

            serviceResponse.Data = dto;
            _logger.Information("PriceService - updated itempriceandcurrencyresponse with currency: {Currency} and Id: {Id]"
                                , cmd.Currency, cmd.Id);
            return(serviceResponse);
        }