public async Task <HttpResponseMessage> SaveActionTaken() { ActionTakenUploadModel model = new ActionTakenUploadModel(); // Send OK Response along with saved file names to the client. var provider = await Request.Content.ReadAsMultipartAsync <InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider()); //access form data NameValueCollection formData = provider.FormData; model.ActionTaken = formData["action"]; model.ActionId = Convert.ToInt32(formData["ActionId"]); model.IsReportedAction = formData["IsReportedAction"] == "true" ? true : false; //access files IList <HttpContent> files = provider.Files; if (files != null && files.Count > 0) { HttpContent file1 = files[0]; var thisFileName = file1.Headers.ContentDisposition.FileName.Trim('\"'); model.fileName = thisFileName; string filename = String.Empty; Stream input = await file1.ReadAsStreamAsync(); string directoryName = String.Empty; string URL = String.Empty; //string tempDocUrl = WebConfigurationManager.AppSettings["DocsUrl"]; var path = HttpRuntime.AppDomainAppPath; directoryName = System.IO.Path.Combine(path, "ActionDocuments"); filename = System.IO.Path.Combine(directoryName, thisFileName); string ext = Path.GetExtension(filename); filename = System.IO.Path.Combine(directoryName, model.ActionId + ext); //Deletion exists file if (File.Exists(filename)) { File.Delete(filename); } Directory.CreateDirectory(@directoryName); using (Stream file = File.Create(filename)) { input.CopyTo(file); //close file file.Close(); } model.FilePath = "~/ActionDocuments/" + model.ActionId + ext; } this._actionRepository.UpdateActionTakenData(model, base.UserId, base.OrganizationId); var response = Request.CreateResponse(HttpStatusCode.OK); return(response); // return ""; }
public void UpdateActionTakenData(ActionTakenUploadModel model, int LoggedInUserId, int LoggedInOrganizationId) { var data = base.GetByID(model.ActionId); data.ActionTaken = model.ActionTaken; data.IsReportedAction = model.IsReportedAction; data.FilePath = model.FilePath; data.FileName = model.fileName; data.EventActionStatusID = 3; Update(data); }