예제 #1
0
        public void Initialize <TContext>(TContext context)
            where TContext : MainContext, new()
        {
            // Инициализация списков
            Applets = new Dictionary <string, List <UIApplet> >()
            {
                { "Tile", new List <UIApplet>() },
                { "Form", new List <UIApplet>() },
                { "Popup", new List <UIApplet>() }
            };
            ViewItems = new List <UIViewItem>();

            // Получение фабрик
            DataBUSViewFR <TContext>     dataBUSViewFactory     = new DataBUSViewFR <TContext>();
            BUSUIViewFR <TContext>       busUIViewFactory       = new BUSUIViewFR <TContext>();
            DataBUSAppletFR <TContext>   dataBUSAppletFactory   = new DataBUSAppletFR <TContext>();
            BUSUIAppletFR <TContext>     busUIAppletFactory     = new BUSUIAppletFR <TContext>();
            DataBUSViewItemFR <TContext> dataBUSViewItemFactory = new DataBUSViewItemFR <TContext>();
            BUSUIViewItemFR <TContext>   busUIViewItemFactory   = new BUSUIViewItemFR <TContext>();

            // Маппинг в UI уровень представления
            View = busUIViewFactory.BusinessToUI(dataBUSViewFactory.DataToBusiness(viewInfo.View, context));
            viewInfo.ViewApplets.ForEach(applet =>
            {
                Applets.GetValueOrDefault(applet.Type)
                .Add(busUIAppletFactory.BusinessToUI(dataBUSAppletFactory.DataToBusiness(applet, context)));
            });

            // Маппинг в UI уровень элементов представления
            viewInfo.ViewItems.ForEach(viewItem =>
            {
                ViewItems.Add(busUIViewItemFactory.BusinessToUI(dataBUSViewItemFactory.DataToBusiness(viewItem, context)));
            });
        }
        public override Dictionary <string, object> CopyRecord()
        {
            Dictionary <string, object> result = base.CopyRecord();

            if (result["ErrorMessages"] == null)
            {
                Applet applet = (Applet)result["NewRecord"];
                applet.Columns.ForEach(column =>
                {
                    column.ColumnUPs.ForEach(up => { context.Entry(up).State = EntityState.Added; });
                    context.Entry(column).State = EntityState.Added;
                });
                applet.Controls.ForEach(control =>
                {
                    control.ControlUPs.ForEach(up => { context.Entry(up).State = EntityState.Added; });
                    context.Entry(control).State = EntityState.Added;
                });
                context.SaveChanges();
                DataBUSAppletFR <TContext> dataBUSAppletFR = new DataBUSAppletFR <TContext>();
                BUSUIAppletFR <TContext>   busUIAppletFR   = new BUSUIAppletFR <TContext>();
                result["NewRecord"] = busUIAppletFR.BusinessToUI(dataBUSAppletFR.DataToBusiness(applet, context));
            }
            return(result);
        }