public ActionResult EditUploadedStudentRelatedDocuments() { Student_Document studentDocumentToBeEdited = new Student_Document(); long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id")); using (var dbcontext = new SchoolERPDBContext()) { if (dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).ToList().Count() > 0) { var studentDocumentId = dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).FirstOrDefault().Id; var studentDocumentToEdit = dbcontext.Student_Document.Find(studentDocumentId); if (studentDocumentToEdit.document1 != null) { ViewBag.Document1 = ConvertByteStreamToString(studentDocumentToEdit.document1); } else { ViewBag.Document1 = null; } if (studentDocumentToEdit.document2 != null) { ViewBag.Document2 = ConvertByteStreamToString(studentDocumentToEdit.document2); } else { ViewBag.Document2 = null; } if (studentDocumentToEdit.document3 != null) { ViewBag.Document3 = ConvertByteStreamToString(studentDocumentToEdit.document3); } if (studentDocumentToEdit.document4 != null) { ViewBag.Document4 = ConvertByteStreamToString(studentDocumentToEdit.document4); } if (studentDocumentToEdit.document5 != null) { ViewBag.Document5 = ConvertByteStreamToString(studentDocumentToEdit.document5); } if (studentDocumentToEdit.document6 != null) { ViewBag.Document6 = ConvertByteStreamToString(studentDocumentToEdit.document6); } return(View(studentDocumentToBeEdited)); } else { return(View()); } } }
public JsonResult UploadStudentDocuments(HttpPostedFileBase file1, HttpPostedFileBase file2, HttpPostedFileBase file3, HttpPostedFileBase file4, HttpPostedFileBase file5, HttpPostedFileBase file6) { //long nStudent_Id = // long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id")); long nStudent_Id = Convert.ToInt64(TempData.Peek("Student_Id"));; Student_Document StudentDocumentToBeAddededOrUpdated = new Student_Document(); HttpPostedFileBase[] fileBaseArr = new HttpPostedFileBase[6]; //byte[] bytes1, bytes2 , bytes3, bytes4, bytes5, bytes6; try { using (var dbcontext = new SchoolERPDBContext()) { if (file1 != null) { StudentDocumentToBeAddededOrUpdated.document1 = ConvertFiletoBYteStream(file1); } else { } if (file2 != null) { StudentDocumentToBeAddededOrUpdated.document2 = ConvertFiletoBYteStream(file2); } if (file3 != null) { StudentDocumentToBeAddededOrUpdated.document3 = ConvertFiletoBYteStream(file3); } if (file4 != null) { StudentDocumentToBeAddededOrUpdated.document4 = ConvertFiletoBYteStream(file4); } if (file5 != null) { StudentDocumentToBeAddededOrUpdated.document5 = ConvertFiletoBYteStream(file5); } if (file6 != null) { StudentDocumentToBeAddededOrUpdated.document6 = ConvertFiletoBYteStream(file6); } if (dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).ToList().Count() > 0) { var studentDocumentId = dbcontext.Student_Document.Where(x => x.Student_Id == nStudent_Id).FirstOrDefault().Id; var studentDocToBeModified = dbcontext.Student_Document.Find(studentDocumentId); studentDocToBeModified.document1 = StudentDocumentToBeAddededOrUpdated.document1 == null ? studentDocToBeModified.document1 : StudentDocumentToBeAddededOrUpdated.document1; studentDocToBeModified.document2 = StudentDocumentToBeAddededOrUpdated.document2 == null ? studentDocToBeModified.document2 : StudentDocumentToBeAddededOrUpdated.document2; studentDocToBeModified.document3 = StudentDocumentToBeAddededOrUpdated.document3 == null ? studentDocToBeModified.document3 : StudentDocumentToBeAddededOrUpdated.document3; studentDocToBeModified.document4 = StudentDocumentToBeAddededOrUpdated.document4 == null ? studentDocToBeModified.document4 : StudentDocumentToBeAddededOrUpdated.document4; studentDocToBeModified.document5 = StudentDocumentToBeAddededOrUpdated.document5 == null ? studentDocToBeModified.document5 : StudentDocumentToBeAddededOrUpdated.document5; studentDocToBeModified.document6 = StudentDocumentToBeAddededOrUpdated.document6 == null ? studentDocToBeModified.document6 : StudentDocumentToBeAddededOrUpdated.document6; dbcontext.Entry(studentDocToBeModified).CurrentValues.SetValues(studentDocToBeModified); dbcontext.SaveChanges(); } else { StudentDocumentToBeAddededOrUpdated.Student_Id = nStudent_Id; dbcontext.Student_Document.Add(StudentDocumentToBeAddededOrUpdated); dbcontext.SaveChanges(); } // } return(Json("Student Documents Successfully Uploaded", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(ex.Message.ToString(), JsonRequestBehavior.AllowGet)); } }