public async Task <IActionResult> PutConversation( Guid id, FullConversationDto conversationDto) { if (id != conversationDto.Id) { return(BadRequest()); } var conversation = _messagingDomainMapper .ToConversation(conversationDto); _context.Entry(conversation).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConversationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult <FullConversationDto> PostConversation([FromBody] FullConversationDto conversationDto) { var conversation = _messagingDomainMapper .ToConversation(conversationDto); _context.Conversations.Add(conversation); _context.SaveChanges(); return(CreatedAtAction( "GetConversation", new { id = conversationDto.Id }, conversationDto)); }
public Conversation ToConversation(FullConversationDto fullConversationDto) { if (fullConversationDto.Id == null) { fullConversationDto.Id = new Guid(); } var messages = new List <Message>(); foreach (var messageDto in fullConversationDto.Messages) { messages.Add(ToMessage(messageDto)); } var participants = new List <ConversationParticipant>(); foreach (var userId in fullConversationDto.Participants) { participants.Add(new ConversationParticipant { ConversationId = fullConversationDto.Id.Value, ParticipantId = userId }); } var statusHistory = new List <ConversationStatus> { new ConversationStatus { Id = new Guid(), ConversationId = fullConversationDto.Id.Value, ConversationStatusEnum = ConversationStatusEnum.New, SetOn = DateTime.UtcNow } }; return(new Conversation { Id = fullConversationDto.Id.Value, Title = fullConversationDto.Title, InternalReference = fullConversationDto.SalesforceId, StartedOn = fullConversationDto.StartedOn == null ? DateTime.UtcNow : fullConversationDto.StartedOn.Value, ConversationStatusHistory = statusHistory, Messages = messages, Participants = participants }); }