Advertisement
LYSoft

Untitled

May 8th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. public void Update()
  2. {
  3.     int count = db.users.Count(u => u.userid == userid);
  4.  
  5.     if (count == 0) // no user found
  6.     {
  7.         throw new Exception(String.Format("User not found for id {0}.", userid));
  8.     }
  9.     else if (count > 1) // more than 1 user found
  10.     {
  11.         throw new Exception(String.Format("Multiple users found for id {0}.", userid));
  12.     }
  13.  
  14.     var user = db.users.FirstOrDefault(u => u.userid == userid);
  15.  
  16.     user.emailaddress = emailaddress;
  17.  
  18.     if (!String.IsNullOrEmpty(password))
  19.     {
  20.         user.password = password;
  21.     }
  22.     user.storeid = storeid;
  23.     user.role = role;
  24.  
  25.     db.SaveChanges();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement