Esempio n. 1
0
        public static void assignOption(string[] input)
        {
            using (AmbulanceStaffContext db = new AmbulanceStaffContext())
            {
                try
                {
                    string officer_id = input[0];
                    int    n;
                    bool   isNumeric = int.TryParse(officer_id, out n);
                    if (isNumeric == true & officer_id.Length == 6)
                    {
                        int to_index = Array.FindIndex(input, to => to.Equals("to", StringComparison.InvariantCultureIgnoreCase));
                        var found    = db.StaffMember.Any(i => i.officer_ID == officer_id);
                        if (found == true)
                        {
                            if (input.Length == 3 & to_index == 1)
                            {
                                string ambulance_id = input[2];
                                var    exist        = db.Ambulance.Any(i => i.ambulance_ID == ambulance_id);
                                if (exist == true)
                                {
                                    foreach (Ambulance a in db.Ambulance.Where(i => i.ambulance_ID == ambulance_id))
                                    {
                                        var staff = db.StaffMember.Where(s => s.officer_ID == officer_id);
                                        foreach (StaffMember s in staff)
                                        {
                                            s.ambulance_ID = ambulance_id.ToUpperInvariant();
                                            db.SaveChanges();
                                            Console.WriteLine("The ambulance officer has been assigned to {0} at {1}", a.ambulance_ID, a.station);
                                        }
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Ambulance ID is missing or not found");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Ambulance ID is missing or not found");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Officer ID not found");
                        }
                    }

                    else
                    {
                        Console.WriteLine("An officer must have a six digit ID number");
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    Console.WriteLine("Please enter a six digit officer ID number."); //if user has only typed in the command and no other values, input is empty
                }
            }
        }
Esempio n. 2
0
 public static void unassignOption(string[] input)
 {
     using (AmbulanceStaffContext db = new AmbulanceStaffContext())
     {
         try
         {
             string officer_id = input[0];
             int    n;
             bool   isNumeric = int.TryParse(officer_id, out n);
             if ((isNumeric == true & officer_id.Length == 6) & input.Length == 1)
             {
                 var found = db.StaffMember.Any(i => i.officer_ID == officer_id);
                 if (found == true)
                 {
                     var staff = db.StaffMember.Where(s => s.officer_ID == officer_id);
                     foreach (StaffMember s in staff)
                     {
                         if (s.ambulance_ID != null)
                         {
                             var station = db.Ambulance.Where(a => a.ambulance_ID == s.ambulance_ID);
                             foreach (Ambulance a in station)
                             {
                                 string ambulance_id = s.ambulance_ID; //need to be printed so save in a variable
                                 s.ambulance_ID = null;
                                 Console.WriteLine("The ambulance officer has been removed from {0} at {1}", ambulance_id, a.station);
                                 db.SaveChanges();
                             }
                         }
                         else
                         {
                             Console.WriteLine("Officer is not assigned to an ambulance");
                         }
                     }
                 }
                 else
                 {
                     Console.WriteLine("Officer ID not found");
                 }
             }
             else
             {
                 Console.WriteLine("An officer must have a six digit ID number");
             }
         }
         catch (IndexOutOfRangeException)
         {
             Console.WriteLine("Please enter a six digit officer ID number."); //if user has only typed in the command and no other values, input is empty
         }
     }
 }
Esempio n. 3
0
 public static void removeOption(string[] list)
 {
     using (AmbulanceStaffContext db = new AmbulanceStaffContext())
     {
         try
         {
             string officer_id = list[0];
             int    n;
             bool   isNumeric = int.TryParse(officer_id, out n);
             if (isNumeric == true & officer_id.Length == 6)
             {
                 var found = db.StaffMember.Any(i => i.officer_ID == officer_id);
                 if (found == true)
                 {
                     var staff = db.StaffMember.Where(s => s.officer_ID == officer_id);
                     foreach (StaffMember s in staff)
                     {
                         db.StaffMember.Remove(s);
                         db.SaveChanges();
                         var removed = db.StaffMember.Any(i => i.officer_ID == officer_id);
                         if (removed != true)
                         {
                             Console.WriteLine("Officer {0} {1} ({2}) has been removed", s.first_names, s.surname, s.skill_level);
                         }
                         else
                         {
                             Console.WriteLine("The officer {0} has not been removed successfully. Please try again.", officer_id);
                             Main();
                         }
                     }
                 }
                 else
                 {
                     Console.WriteLine("Officer ID not found");
                 }
             }
             else
             {
                 Console.WriteLine("Please enter a six digit officer ID number.");
             }
         }
         catch (IndexOutOfRangeException)
         {
             Console.WriteLine("Please enter a six digit officer ID number.");
         }
     }
 }
Esempio n. 4
0
 public static void addToDataBase(string[] input)
 {
     using (AmbulanceStaffContext db = new AmbulanceStaffContext())
     {
         string      officer_ID  = input[0];
         string      first_names = input[1];
         string      surname     = input[2];
         string      skill_level = input[3];
         StaffMember staff       = new StaffMember {
             officer_ID = officer_ID, first_names = first_names, surname = surname, skill_level = skill_level, ambulance_ID = null
         };
         db.StaffMember.Add(staff);
         db.SaveChanges();
         var added = db.StaffMember.Any(i => i.officer_ID == officer_ID);
         if (added == true)
         {
             Console.WriteLine("The ambulance officer has been added");
         }
         else
         {
             Console.WriteLine("The ambulance officer has not been added successfully. Please try again.");
         }
     }
 }