示例#1
0
        public async Task <RedirectToActionResult> StartConversation(StartConversationViewModel viewModel, int id)
        {
            if (ModelState.IsValid)
            {
                string  username = User.Identity.Name;
                AppUser user     = await _userManager.FindByNameAsync(username);

                Message message = new Message();
                message.MessageText = viewModel.Message.MessageText;
                message.Sender      = user;
                message.Date        = DateTime.Now;
                Conversation conversation = convoRepo.AddConversation(bookRepo.GetBookById(id), viewModel.Subject);
                repo.AddMessageToConversation(message, conversation);
                return(RedirectToAction("Conversation", new { id = conversation.ConversationId }));
            }
            return(RedirectToAction("StartConversation"));
        }
示例#2
0
        public async Task <object> AddConversation([FromBody] AddConversationViewModel addConversationViewModel)
        {
            try
            {
                bool   result = true;
                string error  = string.Empty;

                ConversationViewModel conversation = new ConversationViewModel();
                addConversationViewModel.Timestamp = DateTimeOffset.Now;

                try
                {
                    conversation = _conversationRepository.AddConversation(addConversationViewModel.ConversationId, addConversationViewModel.DoctorId, addConversationViewModel.PatientId, string.Empty, addConversationViewModel.Message, addConversationViewModel.MessageType, addConversationViewModel.Category, false, addConversationViewModel.Timestamp);
                }
                catch (Exception ex)
                {
                    result = false;
                    error  = ex.Message;
                }

                return(new SingleResponse <ConversationViewModel>
                {
                    Message = error,
                    DidError = !result,
                    ErrorMessage = error,
                    Token = string.Empty,
                    Model = new ConversationViewModel()
                });
            }
            catch (Exception ex)
            {
                return(new SingleResponse <ConversationViewModel>
                {
                    Message = ex.Message,
                    DidError = true,
                    ErrorMessage = ex.InnerException.ToString(),
                    Token = string.Empty,
                    Model = new ConversationViewModel()
                });
            }
        }