public ActionResult Create([Bind(Include = "address_id,address1,primary_address")] Address address) { if (ModelState.IsValid) { db.Addresses.Add(address); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(address)); }
public ActionResult Create([Bind(Include = "person_id,address_id,record_id")] Person_Address person_Address) { if (ModelState.IsValid) { db.Person_Address.Add(person_Address); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.address_id = new SelectList(db.Addresses, "address_id", "address1", person_Address.address_id); ViewBag.person_id = new SelectList(db.Persons, "person_id", "first_name", person_Address.person_id); return(View(person_Address)); }
public ActionResult Mer([Bind(Include = "person_id,spouse_id, first_name")] Person person, FormCollection fc, int?id, MainViewModel model) { //SpouseViewModel model = new SpouseViewModel(); int?sp_id = model.spouseModel.spouse_id; int?p_id = person.person_id; if (sp_id == p_id) { ViewBag.Message = "can not marry yourself!"; return(PartialView("_Mer")); } if (ModelState.IsValid) { Person per = db.Persons.Find(p_id); if (per == null) { return(HttpNotFound()); } Person spouseNew = db.Persons.Find(sp_id); if (spouseNew.single_married == null) { per.Spouse = spouseNew; per.single_married = "Married"; } else { ViewBag.Message = "Person is married!"; return(PartialView("_Mer")); } per.Spouse = spouseNew; per.single_married = "Married"; spouseNew.Spouse = per; spouseNew.single_married = "Married"; db.Entry(per).State = EntityState.Modified; db.SaveChanges(); return(View("Person", "Index")); } return(PartialView("_Mer", model)); }
public ActionResult Create([Bind(Include = "person_id,first_name,last_name,dob,single_married,spouse_id,primary_address,phone_number,address_id, address, primary_address, record_id")] Person person, MainViewModel mainViewModel, FormCollection fc) { MainViewModel model = new MainViewModel(); // ViewData["status"] = "create started!"; List <Address> al = mainViewModel.allAddresses; // PersonModel personModel = model; //List<Address> al = model.allAddresses; string selectedRadio = fc["primary"]; int radio = Convert.ToInt32(selectedRadio); //person.primary_address = al[radio].address1; //Person newPerson = new Person(); //newPerson.first_name = model.first_name; //newPerson.last_name = model.last_name; //newPerson.dob = model.dob; //newPerson.phone_number = model.phone_number; Person newPerson = new Person(); newPerson.first_name = fc["personModel.first_name"]; newPerson.last_name = fc["personModel.last_name"]; newPerson.dob = Convert.ToDateTime(fc["personModel.dob"]); newPerson.phone_number = fc["personModel.phone_number"]; newPerson.primary_address = al[radio].address1; if (newPerson.primary_address == null) { ViewBag.Message = "Please select primary address!"; return(PartialView("_AddPerson")); } if (ModelState.IsValid) { db.Persons.Add(newPerson); foreach (var a in al) { db.Addresses.Add(a); } for (int i = 0; i < al.Count(); i++) { var personAddress = new Person_Address(); personAddress.Person = newPerson; personAddress.Address = al[i]; db.Person_Address.Add(personAddress); } db.SaveChanges(); ModelState.Clear(); return(JavaScript("success()")); } //change to person if not working! return(View(model)); }