Example #1
0
 public bool SaveBoat(Boat newBoat)
 {
     UserDAL usrDAL = new UserDAL();
     List<User> userlist = usrDAL.GetUsers();
     if (userlist.Exists(x => x.PersonalNumber == newBoat.Personalnumber))
     {
         usrDAL.AddBoat(newBoat);
         return true;
     }
     else
     {
         return false;
     }
 }
Example #2
0
        public Boat AddNewBoat(Boat boat)
        {
            bool test;

            do
            {
                Console.Write("State boat type: ");
                boat.BoatType = Console.ReadLine();
                if (boat.BoatType.Length == 0)
                {
                    Console.Clear();
                    Console.WriteLine("You must state boat type");
                }
            } while (boat.BoatType.Length == 0);
            do
            {
                int n;
                Console.Write("State boat lenght: ");
                string s = Console.ReadLine();
                test = int.TryParse(s, out n);
                if (test)
                {
                    boat.BoatLenght = n;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Try to state a number again");
                }
            } while (test == false);
            do
            {
                int n;
                Console.Write("State personal number: ");
                string s = Console.ReadLine();
                test = int.TryParse(s, out n);
                if (test)
                {
                    boat.Personalnumber = n;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Try to state a number again");
                }
            } while (test == false);

            return boat;
        }
Example #3
0
        public void AddBoat(Boat newBoat)
        {
            try
            {
                using (SqlConnection conn = CreateConnection())
                {
                    SqlCommand sqlCmd = new SqlCommand("applicationSchema.usp_AddBoat", conn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;

                    sqlCmd.Parameters.Add("@Personalnumber", SqlDbType.Int, 4).Value = newBoat.Personalnumber;
                    sqlCmd.Parameters.Add("@BoatType", SqlDbType.VarChar, 50).Value = newBoat.BoatType;
                    sqlCmd.Parameters.Add("@BoatLenght", SqlDbType.Float, 4).Value = newBoat.BoatLenght;

                    conn.Open();
                    sqlCmd.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {

                throw new Exception("Error when the data was going to be saved");
            }
        }
Example #4
0
 public void UpdateBoat(Boat boat)
 {
     UserDAL usrDAL = new UserDAL();
     usrDAL.UpdateBoat(boat);
 }
Example #5
0
        public Boat UpdateBoat(Boat boat)
        {
            Console.WriteLine("Change boat info");

            do
            {
                Console.Write("State boatID:");
                string boatID = Console.ReadLine();
                int parsedNumber;
                int.TryParse(boatID, out parsedNumber);
                if (parsedNumber == 0 )
                {
                    Console.Clear();
                    Console.WriteLine("Try state a number again");
                }
                else
                {
                    boat.BoatID = parsedNumber;
                }
            } while (boat.BoatID == 0 );
            do
            {
                Console.Write("State boat personalnumber:");
                string personalNumber = Console.ReadLine();
                int parsedNumber;
                int.TryParse(personalNumber, out parsedNumber);
                if (parsedNumber == 0)
                {
                    Console.Clear();
                    Console.WriteLine("Try state a number again");
                }
                else
                {
                    boat.Personalnumber = parsedNumber;
                }
            } while (boat.BoatID == 0);
            do
            {
                Console.Write("State boat type:");
                boat.BoatType = Console.ReadLine();
                if (boat.BoatType == "" || boat.BoatType == null)
                {
                    Console.Clear();
                    Console.WriteLine("Try state a boat type again");
                }
            } while (boat.BoatType == "" || boat.BoatType == null);
            do
            {
                Console.Write("State boat lenght:");
                string boatID = Console.ReadLine();
                int parsedNumber;
                int.TryParse(boatID, out parsedNumber);
                if (parsedNumber == 0)
                {
                    Console.Clear();
                    Console.WriteLine("Try state a number again");
                }
                else
                {
                    boat.BoatLenght = parsedNumber;
                }
            } while (boat.BoatID == 0);
            return boat;
        }