We want to update user informations by providing user id and new username and password we want to update . We need to define all the methods can do the update operations.
private static void Update()
{
Console.WriteLine("Plase Enter the Following Details");
int id;
string username;
string password;
User user = new User();
Console.WriteLine("\nEnter The Username ID:");
id = Convert.ToInt32(Console.ReadLine());
user.Id = id;
Console.WriteLine("\nEnter The Username:");
username = Console.ReadLine();
user.username = username;
Console.WriteLine("\nEnter The Password:");
password = Convert.ToString(Console.ReadLine());
user.password = password;
User ua= Setinfromation(id,username,password);
UpdateUserDetails(user);
Console.WriteLine("\n The Information is updated:");
Console.ReadLine();
}
public static User Setinfromation(int User_Id, string userame, string password)
{
User ca = new User();
ca.Id = User_Id;
ca.username = userame;
ca.password = password;
return ca;
}
private static void UpdateUserDetails( User user)
{
using (ModelContainer model = new ModelContainer())
{
User ua = model.Users.Where(x => x.Id == user.Id).Select(x => x).FirstOrDefault();
ua.username = user.username;
ua.password = user.password;
model.SaveChanges();
}
}
Here is the when you run the application .
No comments:
Post a Comment