Exemplo n.º 1
0
        public async Task <IEnumerable <model.MenuItem> > Update()
        {
            proxy.MenuProxy proxy    = new proxy.MenuProxy();
            var             updateGM = await proxy.GetMenu(menuApiUrl);

            repositories.MenuRepository repo = new repositories.MenuRepository(new System.Data.SqlClient.SqlConnection());
            repo.UpdateMenu();
            return(updateGM);
        }
Exemplo n.º 2
0
        public void UpdateMenu()
        {
            var config = new configurations.Config();

            Configuration.GetSection("PasswordConfig").Bind(config);

            string connectionString = $"Server=IP;Database=DB;User Id=USERID;Password={config}";

            Console.WriteLine("Getting Menu");
            proxy.MenuProxy proxy = new proxy.MenuProxy();

            var menu = proxy.GetMenu(menuApiUrl).GetAwaiter().GetResult();

            using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("TRUNCATE TABLE MENU", connection)){
                    connection.Open();
                    cmd.ExecuteNonQuery();
                    repo = new repositories.MenuRepository(connection);

                    insertMenu(menu);
                }
            void insertMenu(IEnumerable <model.MenuItem> menu, int?parentMenuId = null)
            {
                int id = 0;

                foreach (var mi in menu)
                {
                    mi.ParentMenuId = parentMenuId;
                    id = repo.Insert(mi).GetAwaiter().GetResult();

                    Console.WriteLine($"Inserted menuitem id = {id}");

                    if (mi.Children != null)
                    {
                        insertMenu(mi.Children, id);
                    }
                }
            }
        }