public async Task AddTagToProjectAsync(string projectId, AddProjectTagAssociationRequest addProjectTagAssociationRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (addProjectTagAssociationRequest == null)
            {
                throw new ArgumentNullException(nameof(addProjectTagAssociationRequest), $"{nameof(addProjectTagAssociationRequest)} can not be null.");
            }

            if (string.IsNullOrWhiteSpace(addProjectTagAssociationRequest.TagId))
            {
                throw new ArgumentNullException(nameof(addProjectTagAssociationRequest), $"{nameof(addProjectTagAssociationRequest.TagId)} can not be null, empty or whitespace.");
            }

            var requestRoute = ProjectApiEndpoints.Tag.AddToProject(projectId);

            var requestString  = JsonConvert.SerializeObject(addProjectTagAssociationRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not add tag with id '{addProjectTagAssociationRequest.TagId}' to project with id '{projectId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }
        }
示例#2
0
        public async Task <AddPackageWriteRightsForUserResponse> GrantPackageWriteRightsToUserAsync(
            string projectId,
            string packageId,
            AddPackageWriteRightsForUserRequest addPackageWriteRightsForUserRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId), $"{nameof(packageId)} can not be null, empty or whitespace.");
            }

            if (addPackageWriteRightsForUserRequest == null)
            {
                throw new ArgumentNullException(nameof(addPackageWriteRightsForUserRequest), $"{nameof(addPackageWriteRightsForUserRequest)} can not be null.");
            }

            if (string.IsNullOrWhiteSpace(addPackageWriteRightsForUserRequest.EmployeeId))
            {
                throw new ArgumentNullException(nameof(addPackageWriteRightsForUserRequest), $"{nameof(addPackageWriteRightsForUserRequest.EmployeeId)} can not be null, empty or whitespace.");
            }

            var requestRoute = PackageApiEndpoints.AccessRights.GrantWriteRights(projectId, packageId);

            var requestString  = JsonConvert.SerializeObject(addPackageWriteRightsForUserRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not grant read rights to employee with id '{addPackageWriteRightsForUserRequest.EmployeeId}' for package with id '{packageId}' of project with id '{projectId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }

            var responseContentString = await response.Content.ReadAsStringAsync();

            var result =
                JsonConvert.DeserializeObject <AddPackageWriteRightsForUserResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
示例#3
0
        public async Task <CreatePackageCommentResponse> CreatePackageCommentAsync(string projectId, string packageId, CreatePackageCommentRequest createPackageCommentRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId), $"{nameof(packageId)} can not be null, empty or whitespace.");
            }

            if (createPackageCommentRequest == null)
            {
                throw new ArgumentNullException(nameof(createPackageCommentRequest), $"{nameof(createPackageCommentRequest)} can not be null.");
            }

            if (createPackageCommentRequest.Text == null)
            {
                throw new ArgumentNullException(nameof(createPackageCommentRequest), $"{nameof(createPackageCommentRequest.Text)} can not be null.");
            }

            var requestRoute = PackageApiEndpoints.Comment.Create(projectId, packageId);

            var requestString  = JsonConvert.SerializeObject(createPackageCommentRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PostAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not create comment in package with id '{packageId}' of project with id '{projectId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }

            var responseContentString = await response.Content.ReadAsStringAsync();

            var result =
                JsonConvert.DeserializeObject <CreatePackageCommentResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
示例#4
0
        public async Task <CreateContactResponse> CreateContactAsync(CreateContactRequest createContactRequest)
        {
            if (createContactRequest == null)
            {
                throw new ArgumentNullException(nameof(createContactRequest), $"{nameof(createContactRequest)} can not be null.");
            }

            if (createContactRequest.FirstName == null)
            {
                throw new ArgumentNullException(nameof(createContactRequest), $"{nameof(createContactRequest.FirstName)} can not be null.");
            }

            if (createContactRequest.LastName == null)
            {
                throw new ArgumentNullException(nameof(createContactRequest), $"{nameof(createContactRequest.LastName)} can not be null.");
            }

            var requestRoute = ContactApiEndpoints.Base.Create();

            var requestString  = JsonConvert.SerializeObject(createContactRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PostAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          "Could not create contact.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }

            var responseContentString = await response.Content.ReadAsStringAsync();

            var result =
                JsonConvert.DeserializeObject <CreateContactResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
示例#5
0
        public async Task MovePackageIntoPackageAsync(string projectId, string packageId, SetPackageAssociationRequest setPackageAssociationRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId), $"{nameof(packageId)} can not be null, empty or whitespace.");
            }

            if (setPackageAssociationRequest == null)
            {
                throw new ArgumentNullException(nameof(setPackageAssociationRequest), $"{nameof(setPackageAssociationRequest)} can not be null.");
            }

            if (string.IsNullOrWhiteSpace(setPackageAssociationRequest.ParentPackageId))
            {
                throw new ArgumentNullException(nameof(setPackageAssociationRequest), $"{nameof(setPackageAssociationRequest.ParentPackageId)} can not be null, empty or whitespace.");
            }

            var requestRoute = PackageApiEndpoints.Association.MoveIntoPackage(projectId, packageId);

            var requestString  = JsonConvert.SerializeObject(setPackageAssociationRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not move package with id '{packageId}' of project with id '{projectId}' into package with id '{setPackageAssociationRequest.ParentPackageId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }
        }
        public async Task <UpdateCompanyResponse> UpdateCompanyAsync(string companyId, UpdateCompanyRequest updateCompanyRequest)
        {
            if (string.IsNullOrWhiteSpace(companyId))
            {
                throw new ArgumentNullException(nameof(companyId), $"{nameof(companyId)} can not be null, empty or whitespace.");
            }

            if (updateCompanyRequest == null)
            {
                throw new ArgumentNullException(nameof(updateCompanyRequest), $"{nameof(updateCompanyRequest)} can not be null.");
            }

            var requestRoute = CompanyApiEndpoints.Base.Update(companyId);

            var requestString  = JsonConvert.SerializeObject(updateCompanyRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PutAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not update company with id '{companyId}'.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }

            var responseContentString = await response.Content.ReadAsStringAsync();

            var result =
                JsonConvert.DeserializeObject <UpdateCompanyResponse>(
                    responseContentString,
                    this.jsonSerializerSettings);

            return(result);
        }
示例#7
0
        public async Task ShiftTasksOfPackageAsync(
            string projectId,
            string packageId,
            ShiftPackageWithSuccessorsRequest shiftPackageWithSuccessorsRequest)
        {
            if (string.IsNullOrWhiteSpace(projectId))
            {
                throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace.");
            }

            if (string.IsNullOrWhiteSpace(packageId))
            {
                throw new ArgumentNullException(nameof(packageId), $"{nameof(packageId)} can not be null, empty or whitespace.");
            }

            if (shiftPackageWithSuccessorsRequest == null)
            {
                throw new ArgumentNullException(nameof(shiftPackageWithSuccessorsRequest), $"{nameof(shiftPackageWithSuccessorsRequest)} can not be null.");
            }

            var requestRoute = PackageApiEndpoints.ShiftTasksOfPackage.ShiftTasksWithSuccessors(projectId, packageId);

            var requestString  = JsonConvert.SerializeObject(shiftPackageWithSuccessorsRequest, this.jsonSerializerSettings);
            var requestContent = ApiHelpers.GetStringContent(requestString);

            var response = await this.httpClient.PostAsync(requestRoute, requestContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new FactroApiException(
                          $"Could not shift package with id '{packageId}' of project with id '{projectId}' by '{shiftPackageWithSuccessorsRequest.DaysDelta.ToString(CultureInfo.InvariantCulture)}' days.",
                          response.RequestMessage.RequestUri.ToString(),
                          response.StatusCode,
                          response.Content == null ? null : await response.Content.ReadAsStringAsync());
            }
        }