//public Task<AuthenticationServiceResponse> AddConversation(ConversationModel conversationModel, string Reply) public Task <AuthenticationServiceResponse> AddConversation(ConversationModel conversationModel) { try { int CreatingUserId = GetLoginUserId(); int ProjectId = conversationModel.ProjectID.Decrypt(); Conversation conversation = new Conversation(); ConversationReply conversationReply = new ConversationReply(); //ConversationModel conversationModel = new ConversationModel(); ConversationReplyModel conversationReplyModel = new ConversationReplyModel(); // Get or Set new Conversation var getConversation = _conversationService.conversationRepository.Get(x => x.ProjectID == ProjectId && x.CreatedBy == CreatingUserId && x.IsDeleted == false).FirstOrDefault(); //if (!getConversation.Any()) if (getConversation == null) { conversation.ProjectID = ProjectId; conversation.CreatedBy = CreatingUserId; conversation.To = _unitOfWork.projectRepository.GetById(ProjectId).OwnerId; //Project Owner conversation.IsDeleted = false; conversation.UpdatedBy = CreatingUserId; conversation.CreatedDate = DateTime.UtcNow; //conversation.UpdatedDate = DateTime.UtcNow; _conversationService.conversationRepository.Insert(conversation); _conversationService.Save(); conversation = _conversationService.conversationRepository.GetById(conversation.ConversationId); } else { conversation = getConversation; conversation.UpdatedDate = DateTime.UtcNow; conversation.UpdatedBy = GetLoginUserId(); _conversationService.conversationRepository.Update(conversation); _conversationService.Save(); } // Insert Conversation Reply conversationReply.Reply = conversationModel.Message; conversationReply.CreatedBy = CreatingUserId; conversationReply.ConversationId = conversation.ConversationId; conversationReply.IsDeleted = false; //conversationReply.CreatedDate = DateTime.UtcNow; _conversationService.conversationReplyRepository.Insert(conversationReply); _conversationService.Save(); Mapper.Map(conversationReply, conversationReplyModel); //conversation.ConversationReply.Add(conversationReply); //Mapper.Map(conversation, conversationModel); ////Mapper.Map(conversa) //var user = _unitOfWork.applicationUserRepository.GetById(conversation.CreatedBy); //Mapper.Map(user, conversationModel.CreatedByUserModel); return(Task.FromResult(new AuthenticationServiceResponse { Data = conversationReplyModel, Success = true, Message = "Message sent succesfully" })); } catch (Exception ex) { return(Task.FromResult(new AuthenticationServiceResponse { Data = ex, Success = false, Message = "Something went Wrong" })); } //return Task.FromResult(new AuthenticationServiceResponse { Message = "Comment Deleted Successfully", Success = true }); }
public async Task <IHttpActionResult> AddConversationReply(ConversationReplyModel conversationReplyModel) { var result = await _conversationService.AddConversationReply(conversationReplyModel); return(Ok(result)); }