Exemplo n.º 1
0
        public object Post(Xero_Contact_Create request)
        {
            ApiUser         hdUser         = request.ApiUser;
            Instance_Config instanceConfig = new Instance_Config(hdUser);

            CheckXeroIntegration(instanceConfig);
            int user_id    = 0;
            int account_id = 0;

            if (request.user_id.HasValue)
            {
                user_id = request.user_id.Value;
            }
            if (request.account_id.HasValue)
            {
                account_id = request.account_id.Value;
            }
            try
            {
                XeroContact xeroContact;
                string      result = Xero.CreateContact(hdUser.OrganizationId, hdUser.DepartmentId, instanceConfig, instanceConfig.XeroAuthConsumerKey, user_id, account_id, out xeroContact,
                                                        instanceConfig.XeroRSAPrivateKey);
                if (result == "ok")
                {
                    return(xeroContact);
                }
                else
                {
                    throw new HttpError(HttpStatusCode.NotFound, Utils.ClearString(result));
                }
            }
            catch (Exception ex)
            {
                throw new HttpError(Utils.ClearString(ex.Message));
            }
        }