Example #1
0
 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");
         }
     }
 }
Example #2
0
 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");
         }
     }
 }