public async Task <bool> SendInterUserMessage(MessageParticipant from, MessageParticipant to, string message, int?jobId) { var interUserMessageRequest = new InterUserMessageRequest { From = from, To = to, Content = message, JobId = jobId, }; string json = JsonConvert.SerializeObject(interUserMessageRequest); StringContent data = new StringContent(json, Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await Client.PostAsync("/api/InterUserMessage", data)) { string jsonResponse = await response.Content.ReadAsStringAsync(); var interUserMessageResponse = JsonConvert.DeserializeObject <ResponseWrapper <bool, CommunicationServiceErrorCode> >(jsonResponse); if (interUserMessageResponse.HasContent && interUserMessageResponse.IsSuccessful) { return(interUserMessageResponse.Content); } } return(false); }
private async Task <List <int> > GetPartipantDetailsFromGroup(MessageParticipant messageParticipant) { if (messageParticipant.GroupRoleType != null && messageParticipant.GroupRoleType.GroupId.HasValue) { var users = await _connectGroupService.GetGroupMembersForGivenRole ( messageParticipant.GroupRoleType.GroupId.Value, messageParticipant.GroupRoleType.GroupRoles ); return(users); } else { return(null); } }
private MessageParticipant GetToBlock(GetJobDetailsResponse job, RequestRoles requestRole) { MessageParticipant to = new MessageParticipant { RequestRoleType = new RequestRoleType { RequestRole = requestRole } }; switch (requestRole) { case RequestRoles.Recipient: to.EmailDetails = new EmailDetails { DisplayName = string.IsNullOrEmpty(job.JobSummary.RecipientOrganisation) ? job.Recipient.FirstName : job.JobSummary.RecipientOrganisation, EmailAddress = job.Recipient.EmailAddress }; break; case RequestRoles.Requestor: to.EmailDetails = new EmailDetails { DisplayName = job.Requestor.FirstName, EmailAddress = job.Requestor.EmailAddress }; break; case RequestRoles.Volunteer: to.UserId = job.JobSummary.VolunteerUserID; break; case RequestRoles.GroupAdmin: to.GroupRoleType = new GroupRoleType() { GroupId = job.JobSummary.ReferringGroupID, GroupRoles = GroupRoles.Owner }; break; default: throw new ArgumentException(message: $"Unexpected RequestRoles value: {requestRole}", paramName: nameof(requestRole)); } return(to); }
private MessageParticipant GetFromBlock(User user, RequestRoles requestRole, GetJobDetailsResponse job) { MessageParticipant from = new MessageParticipant { RequestRoleType = new RequestRoleType { RequestRole = requestRole } }; switch (requestRole) { case RequestRoles.GroupAdmin: from.GroupRoleType = new GroupRoleType { GroupId = job.JobSummary.ReferringGroupID, GroupRoles = GroupRoles.Owner }; break; case RequestRoles.Volunteer: from.UserId = user.ID; break; case RequestRoles.Recipient: from.EmailDetails = new EmailDetails { DisplayName = string.IsNullOrEmpty(job.JobSummary.RecipientOrganisation) ? job.Recipient.FirstName : job.JobSummary.RecipientOrganisation }; break; case RequestRoles.Requestor: from.EmailDetails = new EmailDetails { DisplayName = job.Requestor.FirstName }; break; default: throw new ArgumentException(message: $"Unexpected RequestRoles value: {requestRole}", paramName: nameof(requestRole)); } return(from); }
private async Task <string> GetGroupName(MessageParticipant participant) { string returnValue = string.Empty; if (participant.GroupRoleType != null && participant.GroupRoleType.GroupId.HasValue) { var group = await _connectGroupService.GetGroup(participant.GroupRoleType.GroupId.Value); if (group != null) { returnValue = group.Group.GroupName; } else { throw new Exception($"Unable to find group name for { participant.GroupRoleType.GroupId.Value }"); } } return(returnValue); }
private async Task <List <int> > IdentifyUserIDs(MessageParticipant messageParticipant) { var result = new List <int>(); if (messageParticipant.UserId.HasValue) { result.Add(messageParticipant.UserId.Value); return(result); } if (messageParticipant.EmailDetails != null) { return(result); } if (messageParticipant.GroupRoleType != null) { return(await GetPartipantDetailsFromGroup(messageParticipant)); } throw new Exception("Unable to get IdentifyUserIds"); }
public async Task <Result> PostRecordFeedback(User user, CapturedFeedback feedback) { var job = await _requestHelpRepository.GetJobDetailsAsync(feedback.JobId, -1); if (job == null || job.JobSummary == null) { throw new Exception($"Attempt to submit feedback for job {feedback.JobId} which could not be found"); } if (job.JobSummary.JobStatus.Incomplete()) { return(Result.Failure_IncorrectJobStatus); } bool success = await _feedbackRepository.PostRecordFeedback(feedback.JobId, feedback.RoleSubmittingFeedback, user?.ID, feedback.FeedbackRating); if (!success) { if (await _feedbackRepository.GetFeedbackExists(feedback.JobId, feedback.RoleSubmittingFeedback, user?.ID)) { return(Result.Failure_FeedbackAlreadyRecorded); } else { return(Result.Failure_ServerError); } } MessageParticipant from = GetFromBlock(user, feedback.RoleSubmittingFeedback, job); if (!string.IsNullOrEmpty(feedback.RecipientMessage)) { var to = GetToBlock(job, RequestRoles.Recipient); success &= await _communicationService.SendInterUserMessage(from, to, feedback.RecipientMessage, feedback.JobId); } if (!string.IsNullOrEmpty(feedback.RequestorMessage)) { var to = GetToBlock(job, RequestRoles.Requestor); success &= await _communicationService.SendInterUserMessage(from, to, feedback.RequestorMessage, feedback.JobId); } if (!string.IsNullOrEmpty(feedback.VolunteerMessage)) { var to = GetToBlock(job, RequestRoles.Volunteer); success &= await _communicationService.SendInterUserMessage(from, to, feedback.VolunteerMessage, feedback.JobId); } if (!string.IsNullOrEmpty(feedback.GroupMessage)) { var to = GetToBlock(job, RequestRoles.GroupAdmin); success &= await _communicationService.SendInterUserMessage(from, to, feedback.GroupMessage, feedback.JobId); } if (!string.IsNullOrEmpty(feedback.HMSMessage)) { var to = new MessageParticipant { GroupRoleType = new GroupRoleType { GroupId = (int)HelpMyStreet.Utils.Enums.Groups.Generic, GroupRoles = GroupRoles.Owner }, RequestRoleType = new RequestRoleType { RequestRole = RequestRoles.GroupAdmin } }; success &= await _communicationService.SendInterUserMessage(from, to, feedback.HMSMessage, feedback.JobId); } return(success ? Result.Success : Result.Failure_ServerError); }