Ejemplo n.º 1
0
        public List <ICustomer> GetAllCustomer(IProduct product)
        {
            var customers = new List <ICustomer>();

            if (product?.Id != null)
            {
                var sql = $"SELECT Customer.[Id], Customer.[FirstName], Customer.[LastName]" +
                          $"FROM CustomerLikesProduct " +
                          $"INNER JOIN Customer ON CustomerLikesProduct.CustomerId = Customer.Id " +
                          $"WHERE CustomerLikesProduct.ProductId = @ProductId";

                Query(sql,
                      (command) =>
                {
                    command.Parameters.Add(new SqlParameter("ProductId", product.Id));

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        customers.Add(CustomerDbManager.CreateCustomerFromSqlReader(reader));
                    }
                });
            }

            return(customers);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            MainWindow.Width  = 115;
            MainWindow.Height = 25;

            MainWindow.StartRender();

            string connectionString;
            var    input = MainWindow.GetInputWithQuestion("Vill du koppla upp mot Azure?").ToLower();

            if (input == "ja" ||
                input == "azure")
            {
                connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Kundregister"]
                                   .ConnectionString;
            }
            else
            {
                connectionString = "Server = localdb/mssqllocaldb; Database=KundregisterAndreasOVictor; Trusted Connection = true; UID = CustomerWriter; PWD = 1234test_!";
            }


            _customerDbManager =
                new CustomerDbManager(connectionString);

            _productDbManager =
                new ProductDbManager(connectionString);


            var customerGui = new CustomerGui(MainWindow);
            var productGui  = new ProductGui(MainWindow);

            var running = true;

            var mainQuestion = new Question("Vad vill du göra", "Administrera en kund,Kund", "Administrera en produkt,Produkt", "Rensa skärmen,CLS", "Avsluta,Quit,Exit");

            while (running)
            {
                try
                {
                    input = MainWindow.GetInputWithQuestion(mainQuestion);

                    if (input == "Administrera en kund")
                    {
                        customerGui.Administrate();
                    }
                    else if (input == "Administrera en produkt")
                    {
                        productGui.Administrate();
                    }
                    else if (input == "Rensa skärmen")
                    {
                        MainWindow.Clear();
                    }
                    else if (input == "Avsluta")
                    {
                        running = false;
                    }
                    MainWindow.AddSeparator();
                }
                catch (Exception e)
                {
                    MainWindow.ErrorMessage(e.Message);
                }
            }

            MainWindow.PressAnyKeyToContinue();

            MainWindow.Abort();
        }