public async Task <SetValues> GetByID(int valId) { SetValues item = new SetValues(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("Id", valId.ToString()); //################# IEnumerable <Claim> claims = await APIResult.getList("setValues/GetByID", parameters); foreach (Claim c in claims) { if (c.Type == "scopes") { item = JsonConvert.DeserializeObject <SetValues>(c.Value, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } return(item); //SetValues Object = new SetValues(); //// ... Use HttpClient. //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; //using (var client = new HttpClient()) //{ // ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; // client.BaseAddress = new Uri(Global.APIUri); // client.DefaultRequestHeaders.Clear(); // client.DefaultRequestHeaders.Add("Connection", "Keep-Alive"); // client.DefaultRequestHeaders.Add("Keep-Alive", "3600"); // HttpRequestMessage request = new HttpRequestMessage(); // request.RequestUri = new Uri(Global.APIUri + "setValues/GetByID"); // request.Headers.Add("Id", valId.ToString()); // request.Headers.Add("APIKey", Global.APIKey); // request.Method = HttpMethod.Get; // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // var response = await client.SendAsync(request); // if (response.IsSuccessStatusCode) // { // var jsonString = await response.Content.ReadAsStringAsync(); // Object = JsonConvert.DeserializeObject<SetValues>(jsonString); // return Object; // } // return Object; //} }
public async Task <int> updateImage(SetValues setValues) { Dictionary <string, string> parameters = new Dictionary <string, string>(); string method = "setValues/UpdateImage"; var myContent = JsonConvert.SerializeObject(setValues); parameters.Add("Object", myContent); return(await APIResult.post(method, parameters)); //string message = ""; //// ... Use HttpClient. //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; //string myContent = JsonConvert.SerializeObject(setValues); //using (var client = new HttpClient()) //{ // ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; // client.BaseAddress = new Uri(Global.APIUri); // client.DefaultRequestHeaders.Clear(); // client.DefaultRequestHeaders.Add("Connection", "Keep-Alive"); // client.DefaultRequestHeaders.Add("Keep-Alive", "3600"); // HttpRequestMessage request = new HttpRequestMessage(); // // encoding parameter to get special characters // myContent = HttpUtility.UrlEncode(myContent); // request.RequestUri = new Uri(Global.APIUri + "setValues/UpdateImage?SetValuesObject=" + myContent); // request.Headers.Add("APIKey", Global.APIKey); // request.Method = HttpMethod.Post; // //set content type // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // var response = await client.SendAsync(request); // if (response.IsSuccessStatusCode) // { // message = await response.Content.ReadAsStringAsync(); // message = JsonConvert.DeserializeObject<string>(message); // } // return message; //} }
public async Task <SetValues> getactivesite() { SetValues item = new SetValues(); //################# IEnumerable <Claim> claims = await APIResult.getList("Activate/getactivesite"); foreach (Claim c in claims) { if (c.Type == "scopes") { item = JsonConvert.DeserializeObject <SetValues>(c.Value, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" }); break; } } return(item); }
// get is exist //image part #region image public async Task <string> uploadImage(string imagePath, string imageName, int valId) { if (imagePath != "") { //string imageName = userId.ToString(); MultipartFormDataContent form = new MultipartFormDataContent(); // get file extension var ext = imagePath.Substring(imagePath.LastIndexOf('.')); var extension = ext.ToLower(); string fileName = imageName + extension; try { // configure trmporery path string dir = Directory.GetCurrentDirectory(); string tmpPath = Path.Combine(dir, Global.TMPSettingFolder); string[] files = System.IO.Directory.GetFiles(tmpPath, imageName + ".*"); foreach (string f in files) { System.IO.File.Delete(f); } tmpPath = Path.Combine(tmpPath, imageName + extension); if (imagePath != tmpPath) // edit mode { // resize image ImageProcess imageP = new ImageProcess(150, imagePath); imageP.ScaleImage(tmpPath); // read image file var stream = new FileStream(tmpPath, FileMode.Open, FileAccess.Read); // create http client request using (var client = new HttpClient()) { client.BaseAddress = new Uri(Global.APIUri); client.Timeout = System.TimeSpan.FromSeconds(3600); string boundary = string.Format("----WebKitFormBoundary{0}", DateTime.Now.Ticks.ToString("x")); HttpContent content = new StreamContent(stream); content.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data"); content.Headers.Add("client", "true"); content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = imageName, FileName = fileName }; form.Add(content, "fileToUpload"); var response = await client.PostAsync(@"setValues/PostImage", form); //if (response.IsSuccessStatusCode) //{ // // save image name in DB // SetValues setValues = new SetValues(); // setValues.valId = valId; // setValues.value = fileName; // await updateImage(setValues); // return fileName; //} } stream.Dispose(); } // save image name in DB SetValues setValues = new SetValues(); setValues.valId = valId; setValues.value = fileName; await updateImage(setValues); return(fileName); } catch { return(""); } } return(""); }