Esempio n. 1
0
        public async Task <ActionResult> Post(CreateProduct command)
        {
            await _busPublisher.PublishCommandAsync(command,
                                                    CorrelationContext.Empty);

            return(CreatedAtAction(nameof(Get), new { id = command.Id }, null));
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] AddCity command)
        {
            // await _cityService.AddAsync(command.Name);
            await _busPublisher.PublishCommandAsync(command);

            return(Created("cities", null));
        }
Esempio n. 3
0
        protected async Task <IActionResult> PublishAsync <T>(T command, Guid?resourceId = null, string resource = "") where T : class, ICommand
        {
            // todo: publish context also
            var context = GetContext <T>(resourceId, resource);
            await _busPublisher.PublishCommandAsync(command);

            return(Accepted(context));
        }
Esempio n. 4
0
        //protected IActionResult Collection<T>(PagedResult<T> pagedResult, Func<PagedResult<T>, bool> criteria = null)
        //{
        //    if (pagedResult == null)
        //    {
        //        return NotFound();
        //    }
        //    var isValid = criteria == null || criteria(pagedResult);
        //    if (!isValid)
        //    {
        //        return NotFound();
        //    }
        //    if (pagedResult.IsEmpty)
        //    {
        //        return Ok(Enumerable.Empty<T>());
        //    }
        //    Response.Headers.Add("Link", GetLinkHeader(pagedResult));
        //    Response.Headers.Add("X-Total-Count", pagedResult.TotalResults.ToString());

        //    return Ok(pagedResult.Items);
        //}

        protected async Task <IActionResult> SendAsync <T>(T command,
                                                           Guid?resourceId = null, string resource = "") where T : ICommand
        {
            var context = GetContext <T>(resourceId, resource);
            await _busPublisher.PublishCommandAsync(command, context);

            return(Accepted(context));
        }