Esempio n. 1
0
 public DialogMessage(MessageSendViewModel model, int authorId, int dialogId)
 {
     AuthorId           = authorId;
     DialogId           = dialogId;
     TargetId           = model.TargetId;
     DateOfSending      = DateTime.Now;
     Text               = model.Text;
     ReplyId            = model.ReplyId;
     Status             = 0;
     IsVisibleForAuthor = true;
     IsVisibleForOther  = true;
 }
Esempio n. 2
0
        public async Task <ActionResult <ServiceResult> > SendDialogMessage([FromBody] MessageSendViewModel model)
        {
            // сделать проверку replyid
            ServiceResult result;

            if (ModelState.IsValid)
            {
                result = await dialServ.SendDialogMessageAsync(model);
            }
            else
            {
                result = new ServiceResult(ModelState);
            }
            return(result);
        }
Esempio n. 3
0
        public async Task <ServiceResult> SendDialogMessageAsync(MessageSendViewModel model)
        {
            ServiceResult result = new ServiceResult();
            Dialog        dialog = await GetOrCreateDialogAsync(model.TargetId);

            if (dialog != null)
            {
                if (!dialog.IsClosed)
                {
                    string text = ValidateMessageText(model.Text);
                    if (text != null)
                    {
                        model.Text = text;
                        DialogMessage message = new DialogMessage(model, userId, dialog.Id);
                        context.DialogMessages.Add(message);
                        dialog.LastActive = message.DateOfSending;
                        await context.SaveChangesAsync();

                        MessageDeliveredViewModel confirm = new MessageDeliveredViewModel()
                        {
                            Id     = message.Id,
                            BindId = model.BindId,
                            SentAt = message.DateOfSending
                        };
                        result.Data = JsonConvert.SerializeObject(confirm, serializerSettings);
                        await NewMessagePush(message);
                    }
                }
                else
                {
                    result.SetFail("Диалог заблокирован");
                    logger.LogWarning($"Trying to send message in closed dialog. AuthorId: {userId} To: {model.TargetId}");
                }
            }
            else
            {
                result.SetFail("Диалог не существует");
                logger.LogWarning($"Trying to send message in dialog that doesn't exist. AuthorId: {userId} To: {model.TargetId}");
            }
            return(result);
        }