private static RequestBodyBuilder PopulateRequestParameters(UserRequest user, RequestTypes requestType)
        {
			user.EnsureValidData(requestType);

            RequestBodyBuilder parameters = new RequestBodyBuilder();

            if (!String.IsNullOrEmpty(user.FullName))
            {
                parameters.AppendRequestData("fullname", user.FullName);
            }

            if (user.GroupId > 0)
            {
                parameters.AppendRequestData("usergroupid", user.GroupId);
            }

            if (user.EmailAddresses != null && user.EmailAddresses.Length > 0)
            {
                parameters.AppendRequestDataArray("email[]", user.EmailAddresses);
            }

			if (user.OrganizationId != null && user.OrganizationId.HasValue && user.OrganizationId.Value > 0)
            {
                parameters.AppendRequestData("userorganizationid", user.OrganizationId.Value);
            }

            parameters.AppendRequestData("salutation", EnumUtility.ToApiString(user.Salutation));

            if(!String.IsNullOrEmpty(user.Designation))
            {
                parameters.AppendRequestData("designation", user.Designation);
            }

            if(!String.IsNullOrEmpty(user.Phone))
            {
                parameters.AppendRequestData("phone", user.Phone);
            }

            parameters.AppendRequestData("isenabled", Convert.ToInt32(user.IsEnabled));

			parameters.AppendRequestData("userrole", EnumUtility.ToApiString(user.Role));

            if(!String.IsNullOrEmpty(user.TimeZone))
            {
                parameters.AppendRequestData("timezone", user.TimeZone);
            }
            
            parameters.AppendRequestData("enabledst", Convert.ToInt32(user.EnableDst));

			if (user.SlaPlanId != null)
			{
				parameters.AppendRequestData("slaplanid", user.SlaPlanId);
			}

			if (user.SlaPlanExpiry != null)
			{
				parameters.AppendRequestData("slaplanexpiry", user.SlaPlanExpiry);
			}

			if (user.Expiry != null)
			{
				parameters.AppendRequestData("userexpiry", user.Expiry);
			}

            return parameters;
		}
        /// <summary>
        /// Create a new User record
        /// </summary>
        public User CreateUser(UserRequest user, string password, bool sendWelcomeEmail)
        {
            string apiMethod = "/Base/User/";

            RequestBodyBuilder parameters = PopulateRequestParameters(user, RequestTypes.Create);

            if (!String.IsNullOrEmpty(password))
            {
                parameters.AppendRequestData("password", password);
            }

            parameters.AppendRequestData("sendwelcomeemail", Convert.ToInt32(sendWelcomeEmail));

            UserCollection users = Connector.ExecutePost<UserCollection>(apiMethod, parameters.ToString());

            if (users != null && users.Count > 0)
            {
                return users[0];
            }

            return null;
        }
        /// <summary>
        /// Update the user identified by their unique identifier.
        /// </summary>
        public User UpdateUser(UserRequest user)
        {
            string apiMethod = String.Format("/Base/User/{0}", user.Id);

            RequestBodyBuilder parameters = PopulateRequestParameters(user, RequestTypes.Update);

            UserCollection users = Connector.ExecutePut<UserCollection>(apiMethod, parameters.ToString());

            if (users.Count > 0)
            {
                return users[0];
            }
            return null;
        }
Пример #4
0
		public static User ToResponseData(UserRequest requestData)
		{
			return UserRequest.ToResponseType<UserRequest, User>(requestData);
		}