public override BusinessObject BusinessToData(BusinessObject busObject, BUSBusinessObject businessEntity, TContext context, bool NewRecord)
        {
            BusinessObject dataEntity = base.BusinessToData(busObject, businessEntity, context, NewRecord);

            dataEntity.PrimaryBusCompId = businessEntity.PrimaryBusCompId;
            return(dataEntity);
        }
        public override UIBusinessObject BusinessToUI(BUSBusinessObject businessEntity)
        {
            UIBusinessObject UIEntity = base.BusinessToUI(businessEntity);

            UIEntity.PrimaryBusCompName = businessEntity.PrimaryBusCompName;
            return(UIEntity);
        }
        public override BUSBusinessObject UIToBusiness(UIBusinessObject UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSBusinessObject businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            BusinessComponent primaryBusComp = context.BusinessComponents.FirstOrDefault(n => n.Name == UIEntity.PrimaryBusCompName);

            if (primaryBusComp != null)
            {
                businessEntity.PrimaryBusComp     = primaryBusComp;
                businessEntity.PrimaryBusCompId   = primaryBusComp.Id;
                businessEntity.PrimaryBusCompName = primaryBusComp.Name;
            }
            return(businessEntity);
        }
        public override BUSBusinessObject DataToBusiness(BusinessObject dataEntity, TContext context)
        {
            BUSBusinessObject businessEntity = base.DataToBusiness(dataEntity, context);
            BusinessComponent primaryBusComp = context.BusinessComponents.AsNoTracking().FirstOrDefault(i => i.Id == dataEntity.PrimaryBusCompId);

            if (primaryBusComp != null)
            {
                businessEntity.PrimaryBusComp     = primaryBusComp;
                businessEntity.PrimaryBusCompId   = primaryBusComp.Id;
                businessEntity.PrimaryBusCompName = primaryBusComp.Name;
            }
            return(businessEntity);
        }
        public override IEnumerable <ValidationResult> BUSUIValidate(TContext context, BUSBusinessObject businessComponent, UIBusinessObject UIEntity)
        {
            List <ValidationResult> result = base.BUSUIValidate(context, businessComponent, UIEntity).ToList();

            if (!string.IsNullOrWhiteSpace(UIEntity.PrimaryBusCompName) && businessComponent.PrimaryBusComp == null)
            {
                result.Add(new ValidationResult(
                               "Business component with this name not found.",
                               new List <string>()
                {
                    "PrimaryBusCompName"
                }));
            }
            return(result);
        }