public ActionResult Edit([Bind(Include = "id")] AdmissionFormViewModel admissionFormViewModel) { if (ModelState.IsValid) { db.Entry(admissionFormViewModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(admissionFormViewModel)); }
// GET: AdmissionForms/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AdmissionFormViewModel myModel = db.GetViewModel((long)id); if (myModel == null) { return(HttpNotFound()); } return(View(myModel)); }
public AdmissionFormViewModel GetViewModel(long formno) { try { NICTDbContext db = new NICTDbContext(); AdmissionFormViewModel myModel = new AdmissionFormViewModel() { AboutNICT = db.AboutNICTs.SingleOrDefault(x => x.Form_No == formno), AdmissionForm = db.AdmisionForms.SingleOrDefault(x => x.Form_No == formno), EduQualification = db.EduQualifications.SingleOrDefault(x => x.Form_No == formno), Files = db.Files.Where(x => x.Form_No == formno).ToList(), Installment = db.Installments.Where(x => x.Form_No == formno).OrderByDescending(y => y.Datetime).First(), JobExperience = db.JobExperiences.SingleOrDefault(x => x.Form_No == formno), KnowledgeOfComp = db.KnowledgeOfComps.SingleOrDefault(x => x.Form_No == formno), StudentDetail = db.StudentDetails.SingleOrDefault(x => x.Form_No == formno), }; return(myModel); } catch (Exception ex) { return(null); } }
// GET: AdmissionForms/Create public ActionResult Create() { List <SelectListItem> courses = new List <SelectListItem>(); foreach (var course in db.Courses.ToList()) { courses.Add(new SelectListItem { Value = course.Id.ToString(), Text = course.CourseName }); } List <SelectListItem> items = new List <SelectListItem>(); foreach (var center in db.Centers.ToList()) { items.Add(new SelectListItem { Value = center.CenterId.ToString(), Text = center.CenterName }); } ViewBag.Centers = items; ViewBag.Course_Applied = courses; AdmissionFormViewModel model = new AdmissionFormViewModel(); return(View(model)); }
public ActionResult Create(AdmissionFormViewModel admissionFormViewModel) { if (ModelState.IsValid) { AdmissionForm AdmissionForm = new AdmissionForm(); AdmissionForm.Dated = DateTime.UtcNow; AdmissionForm.centerId = admissionFormViewModel.StudentDetail.Center; db.AdmisionForms.Add(AdmissionForm); db.SaveChanges(); long form_no = AdmissionForm.Form_No; //update formno for all tables admissionFormViewModel.Installment.Form_No = form_no; admissionFormViewModel.AboutNICT.Form_No = form_no; admissionFormViewModel.EduQualification.Form_No = form_no; admissionFormViewModel.StudentDetail.Form_No = form_no; //check for empty model properties if (!admissionFormViewModel.JobExperience.HasAllEmptyProperties()) { admissionFormViewModel.JobExperience.Form_No = form_no; db.JobExperiences.Add(admissionFormViewModel.JobExperience); } if (!admissionFormViewModel.KnowledgeOfComp.HasAllEmptyProperties()) { admissionFormViewModel.KnowledgeOfComp.Form_No = form_no; db.KnowledgeOfComps.Add(admissionFormViewModel.KnowledgeOfComp); } //check for uploaded files if (admissionFormViewModel.Files != null) { foreach (var File in admissionFormViewModel.Files) { File.Form_No = form_no; File.Datetime = AdmissionForm.Dated; db.Files.Add(File); } } admissionFormViewModel.Installment.Duedate = DateTime.UtcNow.AddDays(10); admissionFormViewModel.Installment.Datetime = AdmissionForm.Dated; admissionFormViewModel.Installment.Balance_Due = 3000 - admissionFormViewModel.Installment.Amount_Paid; //update student reg no int regNo = db.StudentDetails.Where(y => y.Center.Equals(admissionFormViewModel.StudentDetail.Center)).OrderByDescending(x => x.Reg_No).Select(s => s.Reg_No).FirstOrDefault(); if (regNo == 0 || regNo == null) { regNo++; } //set the reg number admissionFormViewModel.StudentDetail.Reg_No = regNo; //add all the models to db db.AboutNICTs.Add(admissionFormViewModel.AboutNICT); db.EduQualifications.Add(admissionFormViewModel.EduQualification); db.StudentDetails.Add(admissionFormViewModel.StudentDetail); db.Installments.Add(admissionFormViewModel.Installment); db.SaveChanges(); return(RedirectToAction("Details", form_no)); } List <SelectListItem> items = new List <SelectListItem>(); foreach (var center in db.Centers.ToList()) { items.Add(new SelectListItem { Value = center.CenterId.ToString(), Text = center.CenterName }); } ViewBag.Centers = items; return(View(admissionFormViewModel)); }