public async Task <LoginCommandResponseDto> HandleCommand(LoginCommand cmd) { string loginFailureReason = ""; var user = _applicationUserRepository.GetActiveUserByUsername(cmd.Username); //this username is no good... if (user == null) { loginFailureReason = "User doesn't exist in our records"; return(new LoginCommandResponseDto { LoginSuccess = false, FailureReason = loginFailureReason }); } var response = user.Authenticates(cmd.Password, out loginFailureReason); _applicationUserRepository.Save(); if (!response) { return new LoginCommandResponseDto { LoginSuccess = false, FailureReason = loginFailureReason } } ; //fire event here... await _messageProducer.ProduceEventAsync <UserLoggedInEvent>(new UserLoggedInEvent { CorrelationId = (cmd.CommandId == null) ? Guid.NewGuid() : (Guid)cmd.CommandId, EntityId = user.Id, UserName = user.UserName, TimeStamp = user.LastLogin }); return(new LoginCommandResponseDto { LoginSuccess = true, IdentityUserId = user.Id }); }