private static RequestBodyBuilder PopulateRequestParameters(StaffGroupRequest staffGroup, RequestTypes requestType) { staffGroup.EnsureValidData(requestType); RequestBodyBuilder parameters = new RequestBodyBuilder(); if (!String.IsNullOrEmpty(staffGroup.Title)) { parameters.AppendRequestData("title", staffGroup.Title); } parameters.AppendRequestData("isadmin", Convert.ToInt32(staffGroup.IsAdmin)); return(parameters); }
/// <summary> /// Update the staff group identified by its internal identifer /// </summary> /// <param name="staffGroup">Data representing the staff group to update. Staff Group Id and Title must be supplied</param> /// <returns></returns> public StaffGroup UpdateStaffGroup(StaffGroupRequest staffGroup) { string apiMethod = String.Format("/Base/StaffGroup/{0}", staffGroup.Id); RequestBodyBuilder parameters = PopulateRequestParameters(staffGroup, RequestTypes.Update); StaffGroupCollection staffGroups = Connector.ExecutePut <StaffGroupCollection>(apiMethod, parameters.ToString()); if (staffGroups != null && staffGroups.Count > 0) { return(staffGroups[0]); } return(null); }
/// <summary> /// Create a staff group /// </summary> /// <param name="staffGroup">Data representing the staff group to create</param> /// <returns>Data representing the staff group created</returns> public StaffGroup CreateStaffGroup(StaffGroupRequest staffGroup) { const string apiMethod = "/Base/StaffGroup"; var parameters = PopulateRequestParameters(staffGroup, RequestTypes.Create); var staffGroups = this.Connector.ExecutePost <StaffGroupCollection>(apiMethod, parameters.ToString()); if (staffGroups != null && staffGroups.Count > 0) { return(staffGroups[0]); } return(null); }
public void CreateUpdateDeleteStaffGroup() { StaffGroup dummyStaffGroup = TestData; StaffGroup createdStaffGroup = TestSetup.KayakoApiService.Staff.CreateStaffGroup(StaffGroupRequest.FromResponseData(dummyStaffGroup)); Assert.IsNotNull(createdStaffGroup); dummyStaffGroup.Id = createdStaffGroup.Id; CompareStaffGroups(dummyStaffGroup, createdStaffGroup); dummyStaffGroup.IsAdmin = true; dummyStaffGroup.Title = "UPDATED: Staff Group Test"; StaffGroup updatedStaffGroup = TestSetup.KayakoApiService.Staff.UpdateStaffGroup(StaffGroupRequest.FromResponseData(dummyStaffGroup)); Assert.IsNotNull(updatedStaffGroup); CompareStaffGroups(dummyStaffGroup, updatedStaffGroup); bool success = TestSetup.KayakoApiService.Staff.DeleteStaffGroup(updatedStaffGroup.Id); Assert.IsTrue(success); }