Exemplo n.º 1
0
        public ActionResult EditMessage(EditMessageModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // get message
                    var message = db.Messages.Where(r => r.messageId == model.MessageId).FirstOrDefault();
                    if (message != null)
                    {
                        message.title   = model.Title;
                        message.message = model.Message;
                        message.status  = (int)Message.Status.UNREAD;
                        db.SaveChanges();
                        return(RedirectToAction("ListMessages"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.ToString());

                EventWriter.WriteEventLog("MessageController - EditMessage: " + ex.ToString());
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult EditMessage(int id)
        {
            var model = new EditMessageModel();

            try
            {
                var message = db.Messages.Where(r => r.messageId == id).FirstOrDefault();
                if (message != null)
                {
                    model.MessageId = message.messageId;
                    model.Title     = message.title;
                    model.Message   = message.message;
                }
                else
                {
                    ModelState.AddModelError("", "Thông báo mã #" + id + " không tồn tại trong hệ thống");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.ToString());

                EventWriter.WriteEventLog("MessageController - EditMessage: " + ex.ToString());
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public void Edit(EditMessageModel model)
        {
            DATA.Message message = _context.Messages.FirstOrDefault(m => m.Id == model.Id);

            message.Content = model.MessageContent;

            _context.SaveChanges();
        }
        public async Task A_new_message_with_edited_body_is_sent()
        {
            var context = await Define <EditMessageContext>()
                          .WithEndpoint <EditedMessageReceiver>(e => e
                                                                .DoNotFailOnErrorMessages()
                                                                .When(c => c.SendLocal(new EditMessage {
                SomeProperty = "StarTrek rocks"
            })))
                          .Done(async ctx =>
            {
                if (string.IsNullOrWhiteSpace(ctx.UniqueMessageId))
                {
                    return(false);
                }

                if (!ctx.EditedMessage)
                {
                    var failedMessage = await this.TryGet <FailedMessage>($"/api/errors/{ctx.UniqueMessageId}");
                    if (!failedMessage.HasResult)
                    {
                        return(false);
                    }

                    ctx.EditedMessage = true;
                    var editedMessage = JsonConvert.SerializeObject(new EditMessage
                    {
                        SomeProperty = "StarWars rocks"
                    });
                    var editModel = new EditMessageModel
                    {
                        MessageBody    = editedMessage,
                        MessageHeaders = EditMessageHelper.TryRestoreOriginalHeaderKeys(failedMessage.Item.ProcessingAttempts.Last().Headers)
                    };
                    await this.Post($"/api/edit/{ctx.UniqueMessageId}", editModel);
                    return(false);
                }

                if (ctx.EditedMessageProperty == null)
                {
                    return(false);
                }

                ctx.OriginalMessageFailure = (await this.TryGet <FailedMessage>($"/api/errors/{ctx.UniqueMessageId}")).Item;
                return(true);
            })
                          .Run();

            Assert.AreEqual("StarWars rocks", context.EditedMessageProperty);
            Assert.AreNotEqual(context.OriginalMessageId, context.EditedMessageId);
            Assert.AreEqual(FailedMessageStatus.Resolved, context.OriginalMessageFailure.Status);
            CollectionAssert.DoesNotContain(context.EditedMessageHeaders, "NServiceBus.ExceptionInfo.StackTrace");
        }
Exemplo n.º 5
0
        public async void OnSendClickAsync()
        {
            _messageText = _messageText.TrimEnd();
            if (string.IsNullOrWhiteSpace(_messageText) || string.IsNullOrEmpty(_messageText))
            {
                return;
            }

            if (_edit != null)
            {
                var model = new EditMessageModel()
                {
                    ContentType = ContentType.Text,
                    Id          = _edit.Id,
                    Content     = _messageText
                };

                var response = await Api.EditMessage(model);

                if (!response.IsSuccessStatusCode)
                {
                    Toaster.Add("Error occured while trying edit message", MatToastType.Danger);
                }

                _edit        = null;
                _messageText = string.Empty;
            }
            else
            {
                var message = new MessageModel()
                {
                    Content     = _messageText,
                    ContentType = ContentType.Text,
                    ReplyTo     = _replyTo?.Id
                };

                var result = await Api.SendMessage(message, ChatId);

                if (!result.IsSuccessStatusCode)
                {
                    Toaster.Add("Error occured while trying send message", MatToastType.Danger);
                }

                _replyTo     = null;
                _messageText = string.Empty;
            }

            StateHasChanged();

            await Js.InvokeAsync <string>("resize", _textarea);
        }
        public IActionResult Edit(EditMessageViewModel viewModel)
        {
            var model = new EditMessageModel
            {
                Id             = viewModel.Id,
                MessageContent = viewModel.MessageContent
            };

            int id = _messageService.GetById(viewModel.Id).TicketId;

            _messageService.Edit(model);

            return(RedirectToAction($"{nameof(TicketController.View)}", "Ticket", new { id }));
        }
Exemplo n.º 7
0
        public async Task A_new_message_with_edited_headers_is_sent()
        {
            var context = await Define <EditMessageContext>()
                          .WithEndpoint <EditedMessageReceiver>(e => e
                                                                .DoNotFailOnErrorMessages()
                                                                .When(c => c.SendLocal(new EditMessage())))
                          .Done(async ctx =>
            {
                if (string.IsNullOrWhiteSpace(ctx.UniqueMessageId))
                {
                    return(false);
                }

                if (!ctx.EditedMessage)
                {
                    var failedMessage = await this.TryGet <FailedMessage>($"/api/errors/{ctx.UniqueMessageId}");
                    if (!failedMessage.HasResult)
                    {
                        return(false);
                    }

                    ctx.EditedMessage = true;
                    var newHeaders    = EditMessageHelper.TryRestoreOriginalHeaderKeys(failedMessage.Item.ProcessingAttempts.Last().Headers);
                    newHeaders.Add(new KeyValuePair <string, string>("AcceptanceTest.NewHeader", "42"));
                    var editModel = new EditMessageModel
                    {
                        MessageBody    = JsonConvert.SerializeObject(new EditMessage()),
                        MessageHeaders = newHeaders
                    };

                    await this.Post($"/api/edit/{ctx.UniqueMessageId}", editModel);
                    return(false);
                }

                if (ctx.EditedMessageHeaders == null)
                {
                    return(false);
                }

                ctx.OriginalMessageFailure = (await this.TryGet <FailedMessage>($"/api/errors/{ctx.UniqueMessageId}")).Item;
                return(true);
            })
                          .Run();

            Assert.AreNotEqual(context.OriginalMessageId, context.EditedMessageId);
            Assert.AreEqual(FailedMessageStatus.Resolved, context.OriginalMessageFailure.Status);
            CollectionAssert.AreEqual("42", context.EditedMessageHeaders["AcceptanceTest.NewHeader"]);
            CollectionAssert.AreEqual(context.UniqueMessageId, context.EditedMessageHeaders["ServiceControl.EditOf"]);
        }
Exemplo n.º 8
0
        public ActionResult EditMessage([FromBody] EditMessageModel model)
        {
            if (!_chatService.IsMessageAuthor(model.Id, User.Identity.Name))
            {
                return(Unauthorized());
            }

            var newContent = _mapper.Map <MessageContent>(model);
            var edited     = _chatService.EditMessage(model.Id, newContent);

            var chatId = _chatService.GetChatByMessageId(model.Id).Id;
            var subIds = _subscriptionManager.GetActiveChatMembers(chatId);

            _hub.Clients.Clients(subIds.ToList()).MessageEdited(_mapper.Map <MessageViewModel>(edited), chatId);

            return(Ok());
        }
        public async Task A_new_message_failure_is_created()
        {
            var context = await Define <EditMessageFailureContext>()
                          .WithEndpoint <FailingEditedMessageReceiver>(e => e
                                                                       .When(c => c.SendLocal(new FailingMessage()))
                                                                       .DoNotFailOnErrorMessages())
                          .Done(async ctx =>
            {
                if (ctx.OriginalMessageFailureId == null)
                {
                    return(false);
                }

                if (!ctx.EditedMessage)
                {
                    var failedMessage = await this.TryGet <FailedMessage>($"/api/errors/{ctx.OriginalMessageFailureId}");
                    if (!failedMessage.HasResult)
                    {
                        return(false);
                    }

                    ctx.EditedMessage = true;
                    var editedMessage = JsonConvert.SerializeObject(new FailingMessage
                    {
                        HasBeenEdited = true
                    });
                    var editModel = new EditMessageModel
                    {
                        MessageBody    = editedMessage,
                        MessageHeaders = EditMessageHelper.TryRestoreOriginalHeaderKeys(failedMessage.Item.ProcessingAttempts.Last().Headers)
                    };
                    await this.Post($"/api/edit/{ctx.OriginalMessageFailureId}", editModel);

                    return(false);
                }

                if (ctx.EditedMessageFailureId == null)
                {
                    return(false);
                }

                var failedEditedMessage = await this.TryGet <FailedMessage>($"/api/errors/{ctx.EditedMessageFailureId}");
                if (!failedEditedMessage.HasResult)
                {
                    return(false);
                }

                ctx.OriginalMessageFailure = (await this.TryGet <FailedMessage>($"/api/errors/{ctx.OriginalMessageFailureId}")).Item;
                ctx.EditedMessageFailure   = (await this.TryGet <FailedMessage>($"/api/errors/{ctx.EditedMessageFailureId}")).Item;
                return(true);
            })
                          .Run();

            Assert.AreNotEqual(context.EditedMessageFailure.Id, context.OriginalMessageFailure.Id);
            Assert.AreNotEqual(context.EditedMessageFailure.UniqueMessageId, context.OriginalMessageFailure.UniqueMessageId);
            Assert.AreEqual(FailedMessageStatus.Resolved, context.OriginalMessageFailure.Status);
            Assert.AreEqual(FailedMessageStatus.Unresolved, context.EditedMessageFailure.Status);
            Assert.AreEqual(
                context.OriginalMessageFailure.Id,
                "FailedMessages/" + context.EditedMessageFailure.ProcessingAttempts.Last().Headers["service_control.edit_of"]);
        }