Ejemplo n.º 1
0
        public void Connect(ISaveRepository repo)
        {
            ///////////////////
            // Boards AutoSaver
            ///////////////////
            var boardsChanges = Boards.Connect().Publish();

            SubscribeChanged(boardsChanges,
                             bvm =>
            {
                mon.LogicVerbose($"Box.Boards.ItemChanged {bvm.Id}::{bvm.Name}::{bvm.Modified}");
                var bi = mapper.Map <BoardViewModel, Board>(bvm);
                repo.CreateOrUpdateBoard(bi).Wait();
            });

            SubscribeAdded(boardsChanges,
                           bvm =>
            {
                mon.LogicVerbose($"Box.Boards.Add {bvm.Id}::{bvm.Name}");

                var bi = mapper.Map <BoardViewModel, Board>(bvm);
                bi     = repo.CreateOrUpdateBoard(bi).Result;

                bvm.Id = bi.Id;
            });

            SubscribeRemoved(boardsChanges,
                             bvm =>
            {
                mon.LogicVerbose($"Box.Boards.Remove {bvm.Id}::{bvm.Name}");

                repo.DeleteBoard(bvm.Id).Wait();
            });

            boardsChanges.Connect();

            ////////////////////
            // Columns AutoSaver
            ////////////////////
            var columnsChanges = Columns.Connect().Publish();

            SubscribeChanged(columnsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Columns.ItemChanged {cvm.Id}::{cvm.Name}::{cvm.Order}");
                var ci = mapper.Map <ColumnViewModel, Column>(cvm);
                repo.CreateOrUpdateColumn(ci).Wait();
            });

            SubscribeAdded(columnsChanges,
                           cvm =>
            {
                mon.LogicVerbose($"Box.Columns.Add {cvm.Id}::{cvm.Name}::{cvm.Order}");

                var ci = mapper.Map <ColumnViewModel, Column>(cvm);
                ci     = repo.CreateOrUpdateColumn(ci).Result;

                cvm.Id = ci.Id;
            });

            SubscribeRemoved(columnsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Columns.Remove {cvm.Id}::{cvm.Name}::{cvm.Order}");

                repo.DeleteColumn(cvm.Id).Wait();
            });


            columnsChanges.Connect();

            /////////////////
            // Rows AutoSaver
            /////////////////
            var rowsChanges = Rows.Connect().Publish();

            SubscribeChanged(rowsChanges,
                             rvm =>
            {
                mon.LogicVerbose($"Box.Rows.ItemChanged {rvm.Id}::{rvm.Name}::{rvm.Order}");
                var row = mapper.Map <RowViewModel, Row>(rvm);
                repo.CreateOrUpdateRow(row).Wait();
            });

            SubscribeAdded(rowsChanges,
                           rvm =>
            {
                mon.LogicVerbose($"Box.Rows.Add {rvm.Id}::{rvm.Name}::{rvm.Order}");

                var ri = mapper.Map <RowViewModel, Row>(rvm);
                ri     = repo.CreateOrUpdateRow(ri).Result;

                rvm.Id = ri.Id;
            });

            SubscribeRemoved(rowsChanges,
                             rvm =>
            {
                mon.LogicVerbose($"Box.Rows.Remove {rvm.Id}::{rvm.Name}::{rvm.Order}");

                repo.DeleteRow(rvm.Id).Wait();
            });

            rowsChanges.Connect();

            //////////////////
            // Cards AutoSaver
            //////////////////
            var cardsChanges = Cards.Connect().Publish();

            SubscribeChanged(cardsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Cards.ItemChanged {cvm.Id}::{cvm.Header}");
                var iss = mapper.Map <CardViewModel, Card>(cvm);
                repo.CreateOrUpdateCard(iss).Wait();
            });

            SubscribeAdded(cardsChanges,
                           cvm =>
            {
                mon.LogicVerbose($"Box.Cards.Add {cvm.Id}::{cvm.Header}");
                var ci = mapper.Map <CardViewModel, Card>(cvm);
                ci     = repo.CreateOrUpdateCard(ci).Result;

                cvm.Id = ci.Id;
            });

            SubscribeRemoved(cardsChanges,
                             cvm =>
            {
                mon.LogicVerbose($"Box.Cards.Remove {cvm.Id}::{cvm.Header}");

                repo.DeleteCard(cvm.Id).Wait();
            });

            cardsChanges.Connect();
        }