public static Restaurant.Restaurant GetRestaurant(int id, string name = "")
        {
            var connection     = DatabaseHandler.GetLocalDbConnection();
            var command        = new SqlCommand();
            var restaurantName = name;

            if (!name.Equals(""))
            {
                if (restaurantName.Contains("'"))
                {
                    restaurantName = restaurantName.Replace("'", "''");
                }
                command.CommandText =
                    $"SELECT TOP 1 * FROM [dbo].[Restaurants] WHERE [Name] = '{restaurantName}' AND [Deleted] = 0";
            }
            else
            {
                command.CommandText = $"SELECT * FROM [dbo].[Restaurants] WHERE [Id] = {id} AND [Deleted] = 0";
            }
            command.Connection = connection;
            var reader     = command.ExecuteReader();
            var restaurant = new Restaurant.Restaurant();

            if (reader.Read())
            {
                restaurant = new Restaurant.Restaurant(reader.GetInt32(0), reader.GetString(1), reader.GetString(2),
                                                       reader.GetInt32(3), reader.GetString(4),
                                                       reader.GetString(5), reader.GetString(6), reader.GetString(7), reader.GetString(8),
                                                       reader.GetString(9), Convert.ToDouble(reader[10]), reader.GetBoolean(11));
            }
            connection.Close();
            return(restaurant);
        }
Example #2
0
        public void testAdaugareRestaurant()
        {
            RestaurantBL.RestauranteBusinessLogic restaurante = new RestaurantBL.RestauranteBusinessLogic();
            Restaurant.Restaurant restaurant = new Restaurant.Restaurant();
            restaurante.AdaugareRestaurante(restaurant);
            List <Restaurant.Restaurant> test = restaurante.getRestaurante();

            Assert.Equal(1, test.Count);
        }
Example #3
0
        public void testModificareRestaurant()
        {
            RestaurantBL.RestauranteBusinessLogic restaurante = new RestaurantBL.RestauranteBusinessLogic();
            Restaurant.Restaurant restaurant = new Restaurant.Restaurant();
            restaurant.setNrMese(5);
            restaurant.setNume("nume1");
            restaurante.AdaugareRestaurante(restaurant);
            Restaurant.Restaurant r = new Restaurant.Restaurant();
            r.setNrMese(8);
            restaurant.setNume("nume1");
            restaurante.ModificareRestaurant(r);
            List <Restaurant.Restaurant> test = restaurante.getRestaurante();

            Assert.Equal(test[0].getNrMese(), r.getNrMese());
        }
        public static List <Restaurant.Restaurant> GetRestaurants()
        {
            var connection = DatabaseHandler.GetLocalDbConnection();
            var command    = new SqlCommand();

            command.CommandText = "SELECT * FROM [dbo].[Restaurants] WHERE [Deleted] = 0";
            command.Connection  = connection;
            var reader      = command.ExecuteReader();
            var restaurants = new List <Restaurant.Restaurant>();

            while (reader.Read())
            {
                var restaurant = new Restaurant.Restaurant(reader.GetInt32(0), reader.GetString(1), reader.GetString(2),
                                                           reader.GetInt32(3), reader.GetString(4),
                                                           reader.GetString(5), reader.GetString(6), reader.GetString(7), reader.GetString(8),
                                                           reader.GetString(9), Convert.ToDouble(reader[10]), reader.GetBoolean(11));
                restaurants.Add(restaurant);
            }
            connection.Close();
            return(restaurants);
        }
Example #5
0
        public void testStergereRestaurant()
        {
            RestaurantBL.RestauranteBusinessLogic restaurante = new RestaurantBL.RestauranteBusinessLogic();
            Restaurant.Restaurant restaurant = new Restaurant.Restaurant();
            restaurant.setNume("nume1");
            restaurante.AdaugareRestaurante(restaurant);
            Restaurant.Restaurant restaurant1 = new Restaurant.Restaurant();
            restaurant.setNume("nume2");
            restaurante.AdaugareRestaurante(restaurant1);
            Restaurant.Restaurant restaurant2 = new Restaurant.Restaurant();
            restaurant.setNume("nume3");
            restaurante.AdaugareRestaurante(restaurant2);
            List <Restaurant.Restaurant> test = restaurante.getRestaurante();

            Assert.Equal(3, test.Count);
            Assert.Equal("nume2", test[1].getNume());
            restaurante.StergereRestaurant("Nume2");
            List <Restaurant.Restaurant> test1 = restaurante.getRestaurante();

            Assert.Equal(2, test1.Count);
            Assert.Equal("nume3", test1[1].getNume());
        }
        public static void InsertRestaurant(Restaurant.Restaurant restaurant)
        {
            var connection     = DatabaseHandler.GetLocalDbConnection();
            var command        = new SqlCommand();
            var restaurantName = restaurant.Name;

            if (restaurantName.Contains("'"))
            {
                restaurantName = restaurantName.Replace("'", "''");
            }
            command.CommandText = string.Format(
                "INSERT INTO [dbo].[Restaurants] VALUES ('{0}', '{1}', {2}, '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', {9}, {10})",
                restaurantName, restaurant.Address, restaurant.OwnerId, restaurant.Phone, restaurant.Email,
                restaurant.OpeningHours,
                restaurant.ClosingHours, restaurant.Days, restaurant.Type, restaurant.Delivery,
                restaurant.Deleted ? "1" : "0");
            command.Connection = connection;
            var result = command.ExecuteNonQuery();

            connection.Close();
            Console.WriteLine($@"({result} row(s) affected)");
        }
        public static void UpdateRestaurant(Restaurant.Restaurant restaurant)
        {
            var connection     = DatabaseHandler.GetLocalDbConnection();
            var command        = new SqlCommand();
            var restaurantName = restaurant.Name;

            if (restaurantName.Contains("'"))
            {
                restaurantName = restaurantName.Replace("'", "''");
            }
            command.CommandText = string.Format(
                "UPDATE [dbo].[Restaurants] SET [Name] = '{1}', [Address] = '{2}', [OwnerId] = {3}, [Phone] = '{4}', [Email] = '{5}', " +
                "[OpeningHours] = '{6}', [ClosingHours] = '{7}', [Days] = '{8}', [Type] = '{9}', [Delivery] = {10}, [Deleted] = {11} WHERE [Id] = {0}",
                restaurant.Id, restaurantName, restaurant.Address, restaurant.OwnerId, restaurant.Phone,
                restaurant.Email, restaurant.OpeningHours,
                restaurant.ClosingHours, restaurant.Days, restaurant.Type, restaurant.Delivery,
                restaurant.Deleted ? "1" : "0");
            command.Connection = connection;
            var result = command.ExecuteNonQuery();

            connection.Close();
            Console.WriteLine($@"({result} row(s) affected)");
        }
Example #8
0
 public void UpdateRestaurant(Restaurant.Restaurant restaurant)
 {
     RestaurantDatabaseHandler.UpdateRestaurant(restaurant);
 }
Example #9
0
 public void InsertRestaurant(Restaurant.Restaurant restaurant)
 {
     RestaurantDatabaseHandler.InsertRestaurant(restaurant);
 }
        private void SaveChangesButton_Click(object sender, EventArgs e)
        {
            var AdminInUse        = StaticAccessor.DB.GetUser(0, RestaurantOwnerUsername);
            var CurrentRestaurant = StaticAccessor.DB.GetRestaurant(RestaurantId);

            if (AdminInUse.RestaurantId != 0 && AdminInUse.RestaurantId != CurrentRestaurant.Id)
            {
                CorrectOwnerFormat      = false;
                OwnerUsernameLabel.Text = "Owner Username: Error: Admin already in use.";
            }
            else
            {
                CorrectOwnerFormat = true;
            }

            if (CorrectNameFormat && CorrectAddressFormat && CorrectOwnerFormat && CorrectPhoneNumberFormat &&
                CorrectEmailFormat && CorrectOpeningHoursFormat && CorrectClosingHoursFormat && CorrectDaysOpenFormat &&
                CorrectTypeFormat && CorrectDeliveryChargeFormat && CorrectOwnerUsernameFormat)
            {
                var previousOwner = StaticAccessor.DB.GetUser(StaticAccessor.DB.GetRestaurant(RestaurantId).OwnerId);

                var ownerId    = StaticAccessor.DB.GetUser(0, RestaurantOwnerUsername).Id;
                var restaurant = new Restaurant.Restaurant(RestaurantId, RestaurantName, RestaurantAddress, ownerId,
                                                           RestaurantPhoneNumber, RestaurantEmail, RestaurantOpeningHours, RestaurantClosingHours,
                                                           RestaurantDaysOpen, RestaurantType, double.Parse(RestaurantDeliveryCharge), false);
                if (newRestaurant)
                {
                    StaticAccessor.DB.InsertRestaurant(restaurant);
                }
                else
                {
                    StaticAccessor.DB.UpdateRestaurant(restaurant);
                }

                var newRestaurantId = StaticAccessor.DB.GetRestaurant(0, RestaurantName).Id;
                var restaurantAdmin = StaticAccessor.DB.GetUser(ownerId);
                restaurantAdmin.RestaurantId = newRestaurantId;
                StaticAccessor.DB.UpdateUser(restaurantAdmin);

                if (previousOwner.Username != null && !previousOwner.Username.Equals(RestaurantOwnerUsername))
                {
                    previousOwner.RestaurantId = 0;
                    StaticAccessor.DB.UpdateUser(previousOwner);
                }

                if (sysAdmin)
                {
                    Hide();
                    var SVR = new SysViewRestaraunt(AdminId, RestaurantId);
                    SVR.ShowDialog();
                }
                else
                {
                    Hide();
                    var RM = new RestAdminMainMenu(AdminId, RestaurantId);
                    RM.ShowDialog();
                }
            }
            else
            {
                ErrorMessageLabel.Text    = "Error Message: Please Fix Any Issues with the Restaurant's details";
                ErrorMessageLabel.Visible = true;
            }
        }