Man Down

Man Down

  • NA
  • 48
  • 3.5k

How to avoid to not add new row in DB , When i Edit User's

Feb 2 2018 6:59 AM
I have page , where i can Edit User's Email and Password not problem ,but there is  problem, when its send Data to Database , it will add new row everytime , when i just trying to edit User's Email, so how can i avoid that to not add new row in database , just send data in same row with out adding new row.
 
The code i have in my Action:
  1. public ActionResult UserEdit(string Email)  
  2. {  
  3.     return View(new user {Email = Email });  
  4. }  
  5.   
  6. [HttpPost]  
  7. [ValidateAntiForgeryToken]  
  8.   
  9. public ActionResult UserEdit(user User)  
  10. {  
  11.     var db = new DataContext();  
  12.     var u = db.PX.Where(t => t.Email_ID == User.Email).FirstOrDefault();  
  13.     if (u == null)  
  14.         db.PX.Add(new A_S_PX { Email_ID = User.Email, PS = User.Password });  
  15.     else {   
  16.     u.PS = User.Password;  
  17.     u.Email_ID = User.Email;  
  18.   
  19.     }  
  20.     db.SaveChanges();  
  21.     return View(new user { Email = User.Email });  
  22.   
  23.       
  24. }  
 

Answers (10)