public ActionResult Details() { CharityRegistration reg = db.CharityRegistrations .FirstOrDefault(x => x.User.UserName == User.Identity.Name); if (reg == null) { reg = new CharityRegistration(); reg.User = db.UserProfiles.First(x => x.UserName == User.Identity.Name); } return View(reg); }
public ActionResult Details(CharityRegistration charityReg) { if (ModelState.IsValid) { if (charityReg.Id == 0) db.Entry(charityReg).State = EntityState.Added; else db.Entry(charityReg).State = EntityState.Modified; db.SaveChanges(); ViewBag.AlertSuccess = "Changes Saved!"; return View(db.CharityRegistrations .Include(x => x.User) .FirstOrDefault(x => x.UserID == charityReg.Id)); } return View(charityReg); }