Ejemplo n.º 1
0
        public override UIApplicationItem BusinessToUI(BUSApplicationItem businessEntity)
        {
            UIApplicationItem UIEntity = base.BusinessToUI(businessEntity);

            UIEntity.ScreenName = businessEntity.ScreenName;
            return(UIEntity);
        }
Ejemplo n.º 2
0
        public override BUSApplicationItem UIToBusiness(UIApplicationItem UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSApplicationItem businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            Application        application    = context.Applications
                                                .AsNoTracking()
                                                .Select(app => new
            {
                id    = app.Id,
                name  = app.Name,
                items = app.ApplicationItems.Select(item => new
                {
                    id   = item.Id,
                    name = item.Name
                })
            })
                                                .Select(app => new Application
            {
                Id               = app.id,
                Name             = app.name,
                ApplicationItems = app.items.Select(item => new ApplicationItem
                {
                    Id   = item.id,
                    Name = item.name
                }).ToList()
            })
                                                .FirstOrDefault(i => i.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Application"));

            if (application == null)
            {
                businessEntity.ErrorMessage = "First you need create application.";
            }
            else
            {
                // Если запись новая и она не уникальна, записывается ошибка
                ApplicationItem applicationItem = application?.ApplicationItems.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (applicationItem != null && applicationItem.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Application item with this name is already exists in application {application.Name}";
                }

                else
                {
                    businessEntity.Application   = application;
                    businessEntity.ApplicationId = application.Id;

                    // Экран
                    Screen screen = context.Screens.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.ScreenName);
                    if (screen != null)
                    {
                        businessEntity.Screen     = screen;
                        businessEntity.ScreenId   = screen.Id;
                        businessEntity.ScreenName = screen.Name;
                    }
                }
            }
            return(businessEntity);
        }
Ejemplo n.º 3
0
        public override BUSApplicationItem DataToBusiness(ApplicationItem dataEntity, TContext context)
        {
            BUSApplicationItem businessEntity = base.DataToBusiness(dataEntity, context);

            businessEntity.Application   = dataEntity.Application;
            businessEntity.ApplicationId = dataEntity.ApplicationId;

            Screen screen = context.Screens.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.ScreenId);

            businessEntity.Screen = screen;
            if (screen != null)
            {
                businessEntity.ScreenId   = screen.Id;
                businessEntity.ScreenName = screen.Name;
            }
            return(businessEntity);
        }
Ejemplo n.º 4
0
        public override ApplicationItem BusinessToData(ApplicationItem applicationItem, BUSApplicationItem businessEntity, TContext context, bool NewRecord)
        {
            ApplicationItem dataEntity = base.BusinessToData(applicationItem, businessEntity, context, NewRecord);

            dataEntity.Application   = businessEntity.Application;
            dataEntity.ApplicationId = businessEntity.ApplicationId;
            dataEntity.Screen        = businessEntity.Screen;
            dataEntity.ScreenId      = businessEntity.ScreenId;
            return(dataEntity);
        }
Ejemplo n.º 5
0
        public override IEnumerable <ValidationResult> BUSUIValidate(TContext context, BUSApplicationItem businessComponent, UIApplicationItem UIEntity)
        {
            List <ValidationResult> result = base.BUSUIValidate(context, businessComponent, UIEntity).ToList();

            if (string.IsNullOrWhiteSpace(businessComponent.ErrorMessage))
            {
                if (businessComponent.Screen == null)
                {
                    result.Add(new ValidationResult(
                                   "Screen with this name not found.",
                                   new List <string>()
                    {
                        "ScreenName"
                    }));
                }
            }
            return(result);
        }