public IHttpActionResult UploadRequirementListFile(UploadRequirementListFileDTO model) { if (!Request.Headers.Contains("apiKey")) { return(Unauthorized()); } string apiKey = Request.Headers.GetValues("apiKey").First(); if (!ApiHelper.CheckKey(apiKey)) { return(Unauthorized()); } try { var serviceResult = _parameterService.UploadRequirementListFile(model); return(Ok(serviceResult)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected void buttonInvite_Click(object sender, EventArgs e) { if (uplFileUploader.HasFile) { try { string strTestFilePath = uplFileUploader.PostedFile.FileName; // This gets the full file path on the client's machine ie: c:\test\myfile.txt string strTestFileName = Path.GetFileName(strTestFilePath); // use the System.IO Path.GetFileName method to get specifics about the file without needing to parse the path as a string Int32 intFileSize = uplFileUploader.PostedFile.ContentLength; string strContentType = uplFileUploader.PostedFile.ContentType; // Convert the uploaded file to a byte stream to save to your database. This could be a database table field of type Image in SQL Server Stream strmStream = uplFileUploader.PostedFile.InputStream; Int32 intFileLength = (Int32)strmStream.Length; byte[] bytUpfile = new byte[intFileLength + 1]; strmStream.Read(bytUpfile, 0, intFileLength); strmStream.Close(); //saveFileToDb(strTestFileName, intFileSize, strContentType, bytUpfile); // or use uplFileUploader.SaveAs(Server.MapPath(".") + "filename") to save to the server's filesystem. try { var newFile = new UploadRequirementListFileDTO(); newFile.Name = strTestFileName; newFile.FileSize = intFileSize; newFile.ContentType = strContentType; newFile.AttachedFile = bytUpfile; ServiceResult <long> serviceResult = new ServiceResult <long>(); var queryString = new Dictionary <string, string>(); var response = ApiHelper.CallSendApiMethod(ApiKeys.ParameterApiUrl, "UploadRequirementListFile", queryString, newFile); if (!response.IsSuccessStatusCode) { throw new Exception("Hata oluştu!"); } var data = response.Content.ReadAsStringAsync().Result; serviceResult = JsonConvert.DeserializeObject <ServiceResult <long> >(data); if (serviceResult.ServiceResultType != EnumServiceResultType.Success) { throw new Exception(serviceResult.ErrorMessage); } var requirementListId = serviceResult.Result; try { CreateNGOInvitationDTO newNGOInvitation = new CreateNGOInvitationDTO() { SchoolmasterId = UserHelper.CurrentUser.Id, NumberOfStudent = Convert.ToInt32(TextBoxNumberOfStudent.Text), RequirementListId = requirementListId, StatusId = (int)EnumNGOInvitationStatusType.Beklemede }; ServiceResult <long> serviceResult2 = new ServiceResult <long>(); var queryString2 = new Dictionary <string, string>(); var response2 = ApiHelper.CallSendApiMethod(ApiKeys.ProjectApiUrl, "CreateNGOInvitation", queryString2, newNGOInvitation); if (!response2.IsSuccessStatusCode) { throw new Exception("Hata oluştu!"); } var data2 = response2.Content.ReadAsStringAsync().Result; serviceResult2 = JsonConvert.DeserializeObject <ServiceResult <long> >(data2); if (serviceResult2.ServiceResultType != EnumServiceResultType.Success) { throw new Exception(serviceResult2.ErrorMessage); } labelErrorMessage.Text = "ILKYAR davet edildi."; labelErrorMessage.Visible = true; } catch (Exception ex) { labelErrorMessage.Text = ex.Message; labelErrorMessage.Visible = true; } } catch (Exception ex) { labelErrorMessage.Text = ex.Message; labelErrorMessage.Visible = true; } } catch (Exception err) { labelErrorMessage.Text = "Dosya yüklenemedi."; } } else { labelErrorMessage.Text = "İhtiyaç Listesi seçmediniz."; } }