public SpeakResult Speak(SpeakRequest request) { var result = new SpeakResult(); var createRequest = _requestMapper.MapFrom(request); var conversation = _conversationFactory.Create(createRequest); if(conversation.Source == Rules.Being.Unknown) { result.AddError("InvalidData", "The source of the conversation was not known. Please provide the source and try again."); return result; } var validationErrors = conversation.Validate(); if(validationErrors.Any()) { validationErrors.ForEach(err => result.AddError("InvalidData", err.ErrorMessage)); return result; } var addedConversation = _conversationRepository.Insert(conversation); if(addedConversation.IsUnknown) { result.AddError("DidNotAdd", "We were unable to add the new conversation, please try again at a later time."); return result; } result.Conversation = addedConversation; return result; }
public CreateSpeakRequest MapFrom(SpeakRequest request) { return new CreateSpeakRequest { Source = request.Source, Message = request.Message }; }