public ActionResult PreviousBoardExam(int id) { StudentInfoViewModel model = new StudentInfoViewModel(); model.PreviousInstitutionList = new List <StudentInfoPreviousInstitutionViewModel>(); model.Id = id; //var entity = db.StudentInfoPreviousInstitution.Where(m=>m.StudentInfo_FK == id); var p = db.StudentInfoPreviousInstitution.Any(m => m.StudentInfo_FK == id); if (p == false) { using (var _sdb = new JamiyahDBEntities()) { foreach (var item in _sdb.BoardExamination) { StudentInfoPreviousInstitutionViewModel _institutionObj = new StudentInfoPreviousInstitutionViewModel(); _institutionObj.ExamName = item.ExminationName; StudentInfoPreviousInstitution _studentInfoPreviousInstitutionEntity = new StudentInfoPreviousInstitution(); _studentInfoPreviousInstitutionEntity.ExamName = _institutionObj.ExamName; _studentInfoPreviousInstitutionEntity.StudentInfo_FK = id; _sdb.StudentInfoPreviousInstitution.Add(_studentInfoPreviousInstitutionEntity); // db.SaveChanges(); } //save at the end _sdb.SaveChanges(); } } IQueryable <StudentInfoPreviousInstitution> query = db.StudentInfoPreviousInstitution.Where(m => m.StudentInfo_FK == id); var data = query.Select(asset => new StudentInfoPreviousInstitutionViewModel() { Id = asset.Id, StudentInfo_FK = asset.StudentInfo_FK, ExamName = asset.ExamName, ExamYear = asset.ExamYear, InstitutionName = asset.InstitutionName, InstitutionCode = asset.InstitutionCode, InstitutionDistrict = asset.InstitutionDistrict, RegiNo = asset.RegiNo, RollNo = asset.RollNo, Grade = asset.Grade }).ToList(); model.PreviousInstitutionList = data; return(View(model)); }
public ActionResult Create(StudentInfoViewModel model, HttpPostedFileBase PostedLogo) { if (ModelState.IsValid) { StudentInfo entity = new StudentInfo(); if (PostedLogo != null) { byte[] imgBinaryData = new byte[PostedLogo.ContentLength]; int readresult = PostedLogo.InputStream.Read(imgBinaryData, 0, PostedLogo.ContentLength); entity.StudentPhoto = imgBinaryData; } entity.StudentNameBangla = model.StudentNameBangla; entity.StudentNameEnglish = model.StudentNameEnglish; entity.StudentNameArabic = model.StudentNameArabic; entity.StudentDateOfBirth = model.StudentDateOfBirth; entity.GenderId = model.GenderId; entity.Nationality = model.Nationality; entity.FatherNameBangla = model.FatherNameBangla; entity.FatherNameEnglish = model.FatherNameEnglish; entity.FatherIsAlive = model.FatherIsAlive; entity.FatherOccupation = model.FatherOccupation; entity.MotherNameBangla = model.MotherNameBangla; entity.MotherNameEnglish = model.MotherNameEnglish; entity.MotherIsAlive = model.MotherIsAlive; entity.MotherMobile = model.MotherMobile; entity.GuardianName = model.GuardianName; entity.GuardianOccupation = model.GuardianOccupation; entity.GuardianHouseNo = model.GuardianHouseNo; entity.GuardianVillage = model.GuardianVillage; entity.GuardianPostOffice = model.GuardianPostOffice; entity.GuardianThana = model.GuardianThana; entity.GuardianDistrict = model.GuardianDistrict; entity.RelationWithGuardian = model.RelationWithGuardian; entity.YearlyIncomeGuardian = model.YearlyIncomeGuardian; entity.PermanentAddressHouse = model.PermanentAddressHouse; entity.PermanentAddressVillage = model.PermanentAddressVillage; entity.PermanentAddressPostOffice = model.PermanentAddressPostOffice; entity.PermanentAddressThana = model.PermanentAddressThana; entity.PermanentAddressDistrict = model.PermanentAddressDistrict; entity.HonarablePersonNameInArea = model.HonarablePersonNameInArea; entity.PreviousInstitutionName = model.PreviousInstitutionName; entity.PreviousInstitutionAddress = model.PreviousInstitutionAddress; entity.PreviousInstitutionClass = model.PreviousInstitutionClass; entity.PreviousInstitutionClearanceNo = model.PreviousInstitutionClearanceNo; entity.PreviousInstitutionClearanceDate = model.PreviousInstitutionClearanceDate; entity.AdmittedDepartmentId = model.AdmittedDepartmentId; entity.Brach = model.AdmittedBranchId; entity.IsAssign = false; db.StudentInfo.Add(entity); db.SaveChanges(); model.Id = entity.Id; // var entity = db.BoardExamination.All(); var p = db.StudentInfoPreviousInstitution.Any(m => m.StudentInfo_FK == model.Id); if (p == false) { using (var _sdb = new JamiyahDBEntities()) { foreach (var item in _sdb.BoardExamination) { StudentInfoPreviousInstitutionViewModel _institutionObj = new StudentInfoPreviousInstitutionViewModel(); _institutionObj.ExamName = item.ExminationName; StudentInfoPreviousInstitution _studentInfoPreviousInstitutionEntity = new StudentInfoPreviousInstitution(); _studentInfoPreviousInstitutionEntity.ExamName = _institutionObj.ExamName; _studentInfoPreviousInstitutionEntity.StudentInfo_FK = model.Id; _sdb.StudentInfoPreviousInstitution.Add(_studentInfoPreviousInstitutionEntity); // db.SaveChanges(); } //save at the end _sdb.SaveChanges(); } } return(RedirectToAction("Edit", new { id = model.Id })); } ViewBag.GenderId = new SelectList(db.Gender.OrderBy(m => m.GenderName), "Id", "GenderName"); ViewBag.AdmittedDepartmentId = new SelectList(db.Department.OrderBy(m => m.Name), "Id", "Name"); ViewBag.BranchId = new SelectList(db.Company.OrderBy(m => m.CompanyName), "CompanyKey", "CompanyName"); return(View(model)); }