コード例 #1
0
 public static void UserRemove(ref CalendarContext db, string userName, string hashedPassword)
 {
     try
     {
         db.Users.Remove(new User
         {
             Username = userName,
             Password = hashedPassword,
         });
         db.SaveChanges();
         db.Calendars.Remove(new Calendar
         {
             CalendarId = db.GetCalendarId(userName)
         });
         db.SaveChanges();
     }
     catch (DbUpdateException)
     {
         Console.WriteLine("Username not found!");
         Console.WriteLine("Press enter to try again.");
         Console.ReadLine();
         db.DetachAllEntities();
         UserDeletion(ref db);
     }
 }
コード例 #2
0
 public static void UserAdd(ref CalendarContext db, string userName, string hashedPassword)
 {
     try
     {
         db.Users.Add(new User {
             Username = userName,
             Password = hashedPassword,
             Calendar = new Calendar {
                 Username = userName
             }
         });
         db.SaveChanges();
     }
     catch (DbUpdateException)
     {
         Console.WriteLine("Username already taken!");
         Console.WriteLine("Press enter to try again.");
         Console.ReadLine();
         db.DetachAllEntities();
         UserCreation(ref db);
     }
 }