public ActionResult AddorEdit(Account newacc) { using (Accountcontext acc = new Accountcontext()) { try { newacc.Type = "Sale"; if (newacc.Personid == 0) { acc.Accounts.Add(newacc); acc.SaveChanges(); return(RedirectToAction("Details", "Account")); } else { acc.Entry(newacc).State = EntityState.Modified; acc.SaveChanges(); return(RedirectToAction("Details", "Account")); } } catch (Exception ex) { return(Content("<script>alert('" + ex.Message.Replace("\'", " ") + "')</script>")); // HttpContext.Response.Write("<script>alert('" + ex.Message.Replace("\'", " ") + "')</script>"); //return RedirectToAction("Details", "Account"); } } }
public ActionResult Delete(int Personid) { using (Accountcontext acc = new Accountcontext()) { try { Account person = acc.Accounts.Where(x => x.Personid == Personid).FirstOrDefault <Account>(); acc.Accounts.Remove(person); acc.SaveChanges(); return(RedirectToAction("Details", "Account")); } catch (Exception ex) { return(Content("<script>alert('" + ex.Message.Replace("\'", " ") + "')</script>")); // HttpContext.Response.Write("<script>alert('" + ex.Message.Replace("\'", " ") + "')</script>"); //return RedirectToAction("Details", "Account"); } } }