示例#1
0
        /// <summary>
        /// Used to Edit an existing user account
        /// </summary>
        public static UserConfiguration EditUser(EditUserInfo info, string note = "")
        {
            string json = JSON.FromObject(info);

            if (!string.IsNullOrEmpty(json))
            {
                UserConfiguration result = null;

                string url = new Uri(ApiConfiguration.AuthenticationApiHost, "users/edit/index.php").ToString();

                var postDatas = new NameValueCollection();
                postDatas["user"]      = json;
                postDatas["token"]     = info.SessionToken;
                postDatas["sender_id"] = SenderId.Get();
                postDatas["note"]      = note;

                string response = HTTP.POST(url, postDatas);
                if (response != null)
                {
                    var success = ApiError.ProcessResponse(response, "Edit User");
                    if (success)
                    {
                        result = UserConfiguration.Get(response);

                        return(result);
                    }
                }
            }

            return(null);
        }
        void UploadProfileImage(EditUserInfo info, string path)
        {
            if (path != null)
            {
                // Crop and Resize image
                System.Drawing.Image img = ProcessImage(path);
                if (img != null)
                {
                    // Generate random file name for processed/temp image (to be saved in temp folder)
                    string newFilename = String_Functions.RandomString(20);

                    // Get file extension of original file
                    string ext = Path.GetExtension(path);

                    // Make sure Temp directory exists
                    FileLocations.CreateTempDirectory();

                    // Create new full path of temp file
                    string localPath = Path.Combine(FileLocations.TrakHoundTemp, newFilename);
                    //if (ext != null) localPath += "." + ext;
                    if (ext != null) localPath = Path.ChangeExtension(localPath, ext);

                    // Save the processed image to the new temp path
                    img.Save(localPath);

                    // Create a temp UserConfiguration object to pass the current SessionToken to the Files.Upload() method
                    var userConfig = new UserConfiguration();
                    userConfig.SessionToken = info.SessionToken;

                    // Set the HTTP Content Type based on the type of image
                    string contentType = null;
                    if (ext == "jpg") contentType = "image/jpeg";
                    else if (ext == "png") contentType = "image/png";
                    else if (ext == "gif") contentType = "image/gif";

                    var fileData = new HTTP.FileContentData("uploadimage", localPath, contentType);

                    // Upload File
                    var uploadInfos = TrakHound.API.Files.Upload(userConfig, fileData);
                    if (uploadInfos != null && uploadInfos.Length > 0)
                    {
                        string fileId = uploadInfos[0].Id;

                        info.ImageUrl = fileId;
                    }
                }
            }
        }
        EditUserInfo NewEditUserInfo()
        {
            var info = new EditUserInfo();

            info.SessionToken = CurrentUser.SessionToken;

            info.FirstName = FirstName;
            info.LastName = LastName;

            if (ShowChangePassword) info.Password = password_TXT.PasswordText;

            info.Company = Company;

            info.Email = Email;
            info.Phone = Phone;

            info.Address1 = Address1;
            info.Address2 = Address2;
            info.City = City;

            if (country_COMBO.SelectedItem != null) info.Country = country_COMBO.SelectedItem.ToString();
            else info.Country = "";

            if (state_COMBO.SelectedItem != null) info.State = state_COMBO.SelectedItem.ToString();
            else info.State = "";

            info.Zipcode = ZipCode;

            return info;
        }
        void EditUser(EditUserInfo info)
        {
            Saving = true;

            ThreadPool.QueueUserWorkItem(new WaitCallback(EditUser_Worker), info);
        }
        /// <summary>
        /// Used to Edit an existing user account
        /// </summary>
        public static UserConfiguration EditUser(EditUserInfo info, string note = "")
        {
            string json = JSON.FromObject(info);
            if (!string.IsNullOrEmpty(json))
            {
                UserConfiguration result = null;

                string url = new Uri(ApiConfiguration.AuthenticationApiHost, "users/edit/index.php").ToString();

                var postDatas = new NameValueCollection();
                postDatas["user"] = json;
                postDatas["token"] = info.SessionToken;
                postDatas["sender_id"] = SenderId.Get();
                postDatas["note"] = note;

                string response = HTTP.POST(url, postDatas);
                if (response != null)
                {
                    var success = ApiError.ProcessResponse(response, "Edit User");
                    if (success)
                    {
                        result = UserConfiguration.Get(response);

                        return result;
                    }
                }
            }

            return null;
        }