mardi 20 août 2019

What pattern can I use to write CRUD functionality?

I am writing a console application. With a database. CRUD functionality.I would like to try to apply the pattern. Is it possible to apply a "state" pattern? In the AddCustomer () method at the end, the call to the InputMenu () method, I do not think that this is correct.

static void Main(string[] args)
    {
        DataFunction dataFunction = new DataFunction();
        dataFunction.InputMenu();
    }

public void InputMenu()
        {
            Console.WriteLine("Add Customer? --- 1, Remove customer? --- 2, Show All Customer? --- 3");
            string _value = Console.ReadLine();

            switch (_value)
            {
                case "1":
                    AddCustomer();
                    break;
                case "2":
                    RemoveCustomer();
                    break;
                case "3":
                    ShowAllCustomers();
                    break;
                default:
                    Console.WriteLine("You clicked an unknown letter");
                    break;
            }

public void AddCustomer()
        {

            Console.WriteLine("Input Name");
            string _name = Console.ReadLine();
            Console.WriteLine("Input Adress");
            string _adress = Console.ReadLine();

            _dataContext.Customers.Add(
                new Customer
                {
                    Name = _name,
                    Adress = _adress
                });
            _dataContext.SaveChanges();

            InputMenu();
        }

Aucun commentaire:

Enregistrer un commentaire