public async Task <IHttpActionResult> UploadFile(Guid fileAllocationId) { var httpRequest = HttpContext.Current.Request; string fileName = ""; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var ext = Path.GetExtension(postedFile.FileName); fileName = fileAllocationId + ext; var filePath = HttpContext.Current.Server.MapPath("~/UploadedDocuments/" + fileName); postedFile.SaveAs(filePath); } var fileAllocation = await _fileAllocationService.GetByIdAsync(fileAllocationId); if (fileAllocation != null) { fileAllocation.DocumentFileName = fileName; _fileAllocationService.Update(fileAllocation); await _fileAllocationService.CommitAsync(); } } else { return(BadRequest("Please attach file.")); } return(Ok(fileName)); }
public async Task <IHttpActionResult> DeleteFileAllocationAsync(Guid id) { var fileAllocation = await _fileAllocationService.GetByIdAsync(id); if (fileAllocation == null) { return(NotFound()); } _fileAllocationService.Delete(fileAllocation); await _fileAllocationService.CommitAsync(); return(Ok(fileAllocation)); }