public async Task <Comment> ToNewSpecialComment(IStandardComment comment) { var author = comment.Author == null ? null : await _dbService.GetEasyAccessUserFrom(comment.Author.UserMap[_configSettings.UserColumnName]); var projectId = await ProjectIdProvider.GetProjectId(comment.Identifiers, await _dbService.GetAllProjectMappings()); return(new Comment() { Content = "[" + comment.MessageOrigin.Split('_')[0] + "] | " + comment.Content, AuthorId = author?.Id, AuthorEmail = author?.Email, AuthorName = author?.Name, ProjectId = projectId, TopicGuid = comment.Identifiers[InstanceKeyNames.EASY_ACCESS_TOPIC].Id, Date = comment.Created }); }
public async Task <Topic> ToNewSpecialObject(IStandardInstance instance) { string projectId = await ProjectIdProvider.GetProjectId(instance.Identifiers, await _dbService.GetAllProjectMappings()); var author = instance.Author == null ? null : await _dbService.GetEasyAccessUserFrom(instance.Author.UserMap[_configSettings.UserColumnName]); var assignee = instance.Assignee == null ? null : await _dbService.GetEasyAccessUserFrom(instance.Assignee.UserMap[_configSettings.UserColumnName]); var newTopic = new Topic() { Status = instance.Status, Priority = instance.Priority, AuthorId = author?.Id, AuthorName = author?.Name, AuthorEmail = author?.Email, AssignedToId = assignee?.Id, AssignedToEmail = assignee?.Email, AssignedToName = assignee?.Name, CreationDate = instance.Created, Title = "[" + instance.MessageOrigin.Split('_')[0] + "] | " + instance.Summary, TopicType = instance.Type, ProjectId = projectId, Labels = instance.Labels }; return(newTopic); }
public async Task <IStandardInstance> UpdateInstanceAsync(IStandardInstance instance) { try { string projectId = await ProjectIdProvider.GetProjectId(instance.Identifiers, await _dbService.GetAllProjectMappings()); string requestUri = "projects/" + projectId + "/topics/" + instance.Identifiers[InstanceKeyNames.EASY_ACCESS_TOPIC].Id; //fetch the old topic first var oldTopicResponse = await _resourceClient.RestClient.GetAsync(requestUri); if (!oldTopicResponse.IsSuccessStatusCode) { throw new ResourceException("Error getting instance at " + requestUri + ". StatusCode=" + oldTopicResponse.StatusCode); } var oldTopic = await oldTopicResponse.Content.ReadAsAsync <Topic>(); //map the instance and merge it into the old topic var topicToBeUpdated = await _instanceMapper.ToUpdatedSpecialObject(instance, oldTopic); string json = topicToBeUpdated.ToJson(); Debug.WriteLine("Topic to be updated: id=" + topicToBeUpdated.Id + ", projectId=" + topicToBeUpdated.ProjectId + ", title=" + topicToBeUpdated.Title); //update the topic var updatedTopicResponse = await _resourceClient.RestClient.PutAsync(requestUri, new StringContent(json, Encoding.UTF8, "application/json")); if (!updatedTopicResponse.IsSuccessStatusCode) { throw new ResourceException("Error updating instance with id=" + topicToBeUpdated.Id + ". StatusCode=" + updatedTopicResponse.StatusCode); } var updatedTopic = await updatedTopicResponse.Content.ReadAsAsync <Topic>(); //EasyAccess status and priority is updated via comments. await UpdateStatusAndPriority(instance, updatedTopic); Debug.WriteLine("Topic was updated."); } catch (Exception e) { Debug.WriteLine("Error updating topic..."); Debug.WriteLine(e.Message, e.StackTrace); } return(instance); }