public async Task <IHttpActionResult> PutFileAllocationAsync(Guid id, FileAllocation fileAllocation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != fileAllocation.Id) { return(BadRequest()); } try { _fileAllocationService.Update(fileAllocation); await _fileAllocationService.CommitAsync(); } catch (DbUpdateConcurrencyException) { if (!await FileAllocationExistsAsync(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
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)); }