Ejemplo n.º 1
0
        public async Task <IActionResult> PostPartner([FromBody] DtoPartners dto)
        {
            var entity = Mapper.Map <Partners>(dto);

            _context.Partners.Add(entity);

            await _context
            .SaveChangesAsync()
            .ConfigureAwait(false);

            dto.Id = entity.Id;
            var @event = new PartnersChanged()
            {
                Created = new List <DtoPartners> {
                    dto
                }
            };

            _eventBus.Publish(@event);

            return(Ok(entity.Id));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdatePartner([FromBody] DtoPartners dto, [FromRoute] long id)
        {
            var template = Mapper.Map <Partners>(dto);

            template.Id = id;

            await _context.Partners
            .Where(x => x.Id == id)
            .UpdateFromQueryAsync(_ => template)
            .ConfigureAwait(false);

            dto.Id = id;
            var @event = new PartnersChanged()
            {
                Updated = new List <DtoPartners> {
                    dto
                }
            };

            _eventBus.Publish(@event);

            return(Ok(id));
        }