public async Task <IHttpActionResult> Createemail_template() { ResponseDataDTO <email_template> response = new ResponseDataDTO <email_template>(); try { var path = Path.GetTempPath(); if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType)); } MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path); await Request.Content.ReadAsMultipartAsync(streamProvider); // get data from formdata EmailTemplateCreateViewModel email_templateCreateViewModel = new EmailTemplateCreateViewModel { emt_code = Convert.ToString(streamProvider.FormData["emt_code"]), emt_name = Convert.ToString(streamProvider.FormData["emt_name"]), emt_content = Convert.ToString(streamProvider.FormData["emt_content"]), staff_id = Convert.ToInt32(streamProvider.FormData["staff_id"]), emt_create_date = Convert.ToDateTime(streamProvider.FormData["emt_create_date"]), }; // mapping view model to entity var createdemail_template = _mapper.Map <email_template>(email_templateCreateViewModel); // save new email_template _email_templateservice.Create(createdemail_template); // return response response.Code = HttpCode.OK; response.Message = MessageResponse.SUCCESS; response.Data = createdemail_template; return(Ok(response)); } catch (Exception ex) { response.Code = HttpCode.INTERNAL_SERVER_ERROR; response.Message = ex.Message; response.Data = null; Console.WriteLine(ex.ToString()); return(Ok(response)); } }