Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
        public static void PlanRemove(ref CalendarContext db, string userName)
        {
            bool remove = true;

            while (remove)
            {
                Console.Clear();
                Console.WriteLine("When is the plan you would like to remove?");
                string removeDate = Console.ReadLine();
                Console.WriteLine("Which plan would you like to remove?");
                string activity = Console.ReadLine();
                ValidateRemoveDateFormat(ref db, removeDate, activity, userName);
                db.RemovePlanEntry(removeDate, activity, userName);
                db.SaveChanges();
                Console.WriteLine("Are you done removing plans?(y/n)");
                string response = Console.ReadLine();
                if (response == "n")
                {
                    remove = true;
                    Console.Clear();
                }
                else if (response == "y")
                {
                    remove = false;
                }
            }
        }
Ejemplo n.º 3
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);
     }
 }