public IHttpActionResult PutSubjectDocument(int id, SubjectDocument subjectDocument) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != subjectDocument.Id) { return BadRequest(); } db.Entry(subjectDocument).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SubjectDocumentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostSubjectDocument() { if (HttpContext.Current.Request.Files.AllKeys.Any()) { //Get the uploaded image from the Files collection var httpPostedFile = HttpContext.Current.Request.Files["UploadedFile"]; if (httpPostedFile != null) { SubjectDocument document = new SubjectDocument(); int length = httpPostedFile.ContentLength; byte[] Filedata = new byte[length]; httpPostedFile.InputStream.Read(Filedata, 0, length); document.SubjectDocumentDescription = Path.GetFileName(httpPostedFile.FileName); var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName); if (System.IO.File.Exists(fileSavePath)) { return Ok("File Already Exist"); } document.SubjectDocumentPath = fileSavePath; document.SubjectId = 5; document.LocationId = 1; document.CompanyId = 1; document.Createdby = 1; document.CreatedDate = System.DateTime.Today; db.SubjectDocuments.Add(document); db.SaveChanges(); //var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName); // Save the uploaded file to "UploadedFiles" folder httpPostedFile.SaveAs(fileSavePath); return Ok("File Uploaded"); } } return Ok("File is not Uploaded"); }