public bool ChangePassword(string userName, string oldPassword, string newPassword)
{
if (String.IsNullOrEmpty(userName))
{
throw new ArgumentException("Value cannot be null or empty.", "userName");
}
if (String.IsNullOrEmpty(oldPassword))
{
throw new ArgumentException("Value cannot be null or empty.", "oldPassword");
}
if (String.IsNullOrEmpty(newPassword))
{
throw new ArgumentException("Value cannot be null or empty.", "newPassword");
}
try
{
User user = DBEntities.UserSet.Single(u => u.Username == userName);
if (user.CheckPassword(oldPassword))
{
user.ChangePassword(newPassword);
DBEntities.SaveChanges();
return(true);
}
else
{
return(false);
}
}
catch (InvalidOperationException)
{
return(false);
}
}