public async Task SendMessage(SendMessageVM data) { var connection = Connection; if (!connection.Equals(default(SignalRConnection)) && !connection.GroupId.IsNullOrEmptyGuid()) { var group = _groupCache.GetById(GetKeyForGroup(connection.GroupId.Value)); if (group.Equals(default(SignalRGroup))) { SentrySdk.CaptureException(new Exception(APIStatusCode.ERR04007)); return; } var dbResult = await _service.AddAsync(new MessageAddVM() { ChatRoomId = connection.GroupId.Value, Text = data.Text }, connection.UserId); if (dbResult.ResultIsNotTrue()) { SentrySdk.CaptureException(new Exception(APIStatusCode.ERR04008)); return; } await Clients.Group(connection.GroupId.Value.ToString()).SendAsync("ReceiveMessage", data.Text); } }
public async Task <ActionResult> AddMessageToTopic(int topicId, [FromBody] MessageModel messageModel) { try { messageModel.TopicId = topicId; messageModel.Id = await _messageService.AddAsync(messageModel, this.User); return(Created(new Uri($"{Request.Scheme}://{Request.Host}/api/messages/{messageModel.Id}", UriKind.Absolute), messageModel)); } catch (ForumException ex) { return(BadRequest(ex.Message)); } }
public async Task <ApiResult> AddMsg([FromBody] MessageInput messageInput) { messageInput.IP = HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault() ?? HttpContext.Connection.RemoteIpAddress.ToString(); var list = await _messageService.GetListAsync(m => m.IP == messageInput.IP, m => m.CreateTime, true); if (list.Count() > 3) { throw new FriendlyException("您提交的次数过多,请稍后重试!~"); } messageInput.Address = IpParse.GetAddressByIP(messageInput.IP); var model = _mapper.Map <Message>(messageInput); await _messageService.AddAsync(model); return(new ApiResult()); }
public async Task <IActionResult> SendPrivateMessage([FromBody] MessagePostDto message) { if (await _userManager.FindByIdAsync(message.ReceiverId) == null) { return(BadRequest(new { Message = $"No user with provided ID { message.ReceiverId } has been found." })); } if (!await _messageService.AddAsync(message, User.FindFirstValue(ClaimTypes.NameIdentifier))) { return(Conflict(new { Error = "Request unsuccessfull." })); } await _messageHub.SendPrivateMessage(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier), message); return(NoContent()); }
public async Task <IActionResult> AddMessage(MessageAddDto messageAddDto) { var validationResult = await _messageAddDtoValidator.ValidateAsync(messageAddDto); if (!validationResult.IsValid) { return(BadRequest(new { errorMessage = "در اعتبارسنجی مشکلی پیش آمده است" })); } var token = HttpContext.GetAuthToken(); var userJwtToken = await _jwtService.GetUserJwtTokenAsync(token); var messageGetDto = await _messageService.AddAsync(userJwtToken.UserId, messageAddDto); return(Ok(new { messageObj = messageGetDto, message = "پیام با موفقیت اضافه شد" })); }
public async Task <IActionResult> Create() { Message message = new() { Subject = "-", MessageBody = "-", Sender = await userService.GetOrCreateAsync(this.User) }; message = await messageService.AddAsync(message); MessageSendingViewModel ViewModel = new(await getSelectableList()) { Id = message.Id }; return(View(ViewModel)); }
public async Task <ActionResult> Create(MessageInputModel model) { try { if (ModelState.IsValid) { await _messageService.AddAsync(UserId, model); return(RedirectToAction(nameof(Index))); } return(View()); // TODO: Add insert logic here } catch { return(View()); } }
public async Task AddAsync_ShouldReturnIdOfAddedMessage() { var input = new MessageInput { Text = "Hello" }; var result = await _messageService.AddAsync(input, "Client1"); var result2 = await _messageService.AddAsync(input, "Client1"); Assert.IsNotNull(result); Assert.IsNotNull(result2); Assert.AreNotEqual(result.MessageId, result2.MessageId); }
public async Task NewMessage(Message message) { await service.AddAsync(message); await Clients.All.SendAsync("addMessage", message); }
public async Task AddAsync(IAddMessageViewModel model) { await _messageService.AddAsync(Mapper.Map <IMessageDTO>(model)); }
public async Task <ActionResult <MessageIdOutput> > Post([FromBody] MessageInput messageInput) { var messageIdOutput = await _messageService.AddAsync(messageInput, GetUserId()); return(Ok(messageIdOutput)); }
public async Task <IActionResult> Post(MessageInputModel createModel) { var result = await _messageService.AddAsync(UserId, createModel); return(CreatedAtAction(nameof(Get), new { result.Id }, result)); }