public ActionResult Create(Contacts contacts) { var user = db.Accounts.FirstOrDefault(x => x.AccountName == HttpContext.User.Identity.Name); contacts.ContactUserId = user.AccountId; if (ModelState.IsValid) { db.Contacts.Add(contacts); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contacts)); }
public ActionResult Registration(RegisterModel model) { try { using (ContactBookDb db = new ContactBookDb()) { Accounts account = new Accounts() { AccountName = model.UserName, AccountPassword = model.UserPassword, AccountActive = true, AccountRole = "Normal" }; db.Accounts.Add(account); db.SaveChanges(); } } catch (Exception) { return(HttpNotFound()); } return(View()); }