public async Task <IActionResult> SendMessageAsync(string customerId, [FromBody] SendSupportMessage command) { try { if (!ModelState.IsValid) { return(BadRequest()); } var customer = await _dbContext.Customers.FirstOrDefaultAsync(c => c.CustomerId == customerId); if (customer == null) { return(NotFound()); } if (customer.SupportMessages == null) { customer.SupportMessages = new List <SupportMessage>(); } SupportMessage message = Mapper.Map <SupportMessage>(command); customer.SupportMessages.Add(message); await _dbContext.SaveChangesAsync(); // send event SupportMessageSent e = Mapper.Map <SupportMessageSent>(command); await _messagePublisher.PublishMessageAsync(e.MessageType, e, ""); // return result return(CreatedAtRoute("GetByCustomerId", new { customerId = customer.CustomerId }, customer)); } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
private void SendMessage(SendSupportMessage message) { chats[message.ChatId].Forward(message); }