コード例 #1
0
        public ActionResult Create(MessageViewModel messageViewModel)
        {
            var currentUser = _uow.UserManager.FindByNameAsync(HttpContext.User?.Identity?.Name).Result;

            messageViewModel.FromUserEmail = currentUser.Email;
            MessageBL messageBL = new MessageBL(_uow, _mapper);
            Post      post      = null;

            if (_userTo.Id == 0)
            {
                var message = _uow.MessageRepository.GetByID(_message.MessageId);
                messageViewModel.ToUserEmail     = message.FromUserEmail;
                messageViewModel.MessageSentDate = DateTime.Now;
                messageViewModel.PostLink        = message.PostLink;
                var postId = int.Parse(message.PostLink.Substring(message.PostLink.LastIndexOf("/") + 1));
                post = _uow.PostRepository.GetByID(postId);
                if (messageBL.SendMessage(messageViewModel, post))
                {
                    return(RedirectToAction("Delete", new { id = message.MessageId }));
                }
            }
            else
            {
                if (_message.MessageId == -1)
                {
                    messageViewModel.ToUserEmail = "*****@*****.**";
                }
                else
                {
                    messageViewModel.ToUserEmail = _uow.UserRepository.GetByID(_userTo.Id).Email;
                }

                messageViewModel.MessageSentDate = DateTime.Now;
                post = _uow.PostRepository.GetByID(_post.PostId);
                messageViewModel.PostLink = $"https://localhost:44372/Post/PostView/{post.PostId}";

                if (messageBL.SendMessage(messageViewModel, post))
                {
                    return(RedirectToAction("AccountPage", "Account"));
                }
            }

            return(RedirectToAction("Create"));
        }
コード例 #2
0
        public void SendMessage(Message message)
        {
            _message.To   = message.To;
            _message.From = message.From;
            _message.Body = message.Body;
            var messageBL = new MessageBL(_uow.messageRepository);

            messageBL.SendMessage(new SecureChat.BLL.Models.Message
            {
                MessageID = _message.MessageID,
                From      = _message.From,
                To        = _message.To,
                Body      = _message.Body,
                SendDate  = _message.SendDate,
                Status    = _message.Status,
                IsDeleted = _message.IsDeleted
            });
        }