public void TestCascadeInsert() { Entity.Applicant app = new Entity.Applicant(); app.FName = "Abebe"; app.LName = "Kebede"; Entity.Contact c = new Entity.Contact(); c.FName = "Aster"; c.LName = "Chala"; c.Address = new Entity.Address(); c.Address.Email = "*****@*****.**"; // app.Contacts.Add(c); UnitOfWork uw = new UnitOfWork(new Entity.K_12Entities()); //IApplicantService app_servie = new ApplicantService(uw.Applicants); // app_servie.Insert(app); uw.Contacts.Add(c); uw.Save(); //Entity.Applicant a2 = app_servie.Find(1); Assert.AreEqual(uw.Contacts.Find(c.ID).Address.Email, c.Address.Email); }
private Entity.Applicant GetApplicant() { if (Session["applicant"] == null) { Entity.Applicant app = new Entity.Applicant(); //Entity.Address address = new Entity.Address(); //address.PhoneBooks.Add(new Entity.PhoneBook() { Type = "Mobile" }); //address.PhoneBooks.Add(new Entity.PhoneBook() { Type = "Office" }); //app.Contacts.Add(new Entity.Contact() { Address = address }); Session["applicant"] = app; } return((Entity.Applicant)Session["applicant"]); }
public ActionResult GradeSelection(Models.GradeViewModel grade, string ButtonType) { if (ButtonType == "Next") { if (ModelState.IsValid) { Entity.Applicant currentApplicant = GetApplicant(); SelectedGrade.ID = grade.ID; Models.ApplicantBasicViewModel appViewModel = new Models.ApplicantBasicViewModel(); //if(currentApplicant.Contacts.Count!=0) appViewModel = AutoMapper.Mapper.Map <Entity.Applicant, Models.ApplicantBasicViewModel>(currentApplicant); //ModelState.Clear(); return(View("ApplicationForm", appViewModel)); } } return(View()); }
public ActionResult DocumentUpload(string ButtonType) { // return PartialView("Confirmation", app); Entity.Applicant currentApplicant = GetApplicant(); if (ButtonType == "Back") { Models.ApplicantBasicViewModel applicantViewModel = AutoMapper.Mapper.Map <Entity.Applicant, Models.ApplicantBasicViewModel>(currentApplicant); return(View("ApplicationForm", applicantViewModel)); } if (ButtonType == "Next") { return(View("Confirmation", currentApplicant)); } return(View()); }
public ActionResult Confirmation(Models.FileUploadViewModel files, string ButtonType) { // return PartialView("Confirmation", app); Entity.Applicant currentApplicant = GetApplicant(); if (ButtonType == "Back") { return(View("DocumentUpload", GetDocuments())); } if (ButtonType == "Next") { ICollection <Models.FileUploadViewModel> applicantDocuments = GetDocuments(); //// The files are not actually saved in this demo //file.SaveAs(physicalPath); //TODO save to db try { _service.Insert(currentApplicant); _unitOfWork.Save(); //to get the autogenerated id Entity.Application currentApplication = new Entity.Application() { application_date = DateTime.Today, grade_applying_id = SelectedGrade.ID }; foreach (var doc in applicantDocuments) { if (doc.FileName != null) { string localPath = Path.Combine(currentApplicant.ID.ToString(), currentApplication.application_date.Value.ToString("dd-MM-yyyy")); string physicalPath = Path.Combine(Server.MapPath("~/App_Data"), localPath); Directory.CreateDirectory(physicalPath); string tempPath = Path.Combine(Server.MapPath("~/App_Data/Temp"), doc.FileName); physicalPath += "\\" + doc.Type + doc.Extention; System.IO.File.Move(tempPath, physicalPath); string localFilePath = localPath + "\\" + doc.Type + doc.Extention; currentApplication.Documents.Add(new Entity.Document() { type = doc.Type, Doc_path = localFilePath, IsVerified = false }); } } currentApplication.app_status = BLL.Constants.ApplicationStatuses.PENDING; currentApplicant.Applications.Add(currentApplication); _service.Update(currentApplicant); //to update documet path _unitOfWork.Save(); } catch (DbUpdateConcurrencyException) { //TO-DO catch db eror } Entity.Application app = currentApplicant.Applications.Last(); if (BLL.BLL.Configuration.AdmisssionMethod == BLL.Constants.AdmissionMethods.FIFO) { //if a place is available app.app_status = BLL.Constants.ApplicationStatuses.ACCEPTED; _unitOfWork.Applications.Update(app); _unitOfWork.Save(); return(ApplicationResult(app.ID)); } ViewBag.appId = app.ID; return(View("FinishPage")); } return(View()); }
public ActionResult ApplicationForm(Models.ApplicantBasicViewModel applicantData, string ButtonType) { // return PartialView("Confirmation", app); Entity.Applicant currentApplicant = GetApplicant(); if (ButtonType == "Reset") { var NewModel = new Models.ApplicantBasicViewModel(); ModelState.Clear(); return(View(NewModel)); } if (ButtonType == "Back") { Models.GradeViewModel grade = new Models.GradeViewModel(); grade.ID = SelectedGrade.ID; // grade.Grade = _unitOfWork.Grade_Infos.Find(grade.ID).Grade; return(View("GradeSelection", grade)); } if (ButtonType == "Next") { if (ModelState.IsValid) { currentApplicant.FName = applicantData.FName; //To-Do use automapper currentApplicant.MName = applicantData.MName; currentApplicant.LName = applicantData.LName; currentApplicant.DOB = applicantData.DOB; currentApplicant.Gender = applicantData.Gender; Entity.Address address = new Entity.Address(); address.Email = applicantData.Contact_Email; address.PhoneBooks.Add(new Entity.PhoneBook() { Type = "Mobile", Phone = applicantData.Contact_MobilePhone }); address.PhoneBooks.Add(new Entity.PhoneBook() { Type = "Office", Phone = applicantData.Contact_OfficePhone }); Entity.Contact contact = new Entity.Contact() { FName = applicantData.Contact_FName, MName = applicantData.Contact_MName, Address = address }; currentApplicant.Contacts.Add(contact); return(View("DocumentUpload", GetDocuments())); } } return(View()); }