예제 #1
0
        public override UIBusinessObjectComponent BusinessToUI(BUSBusinessObjectComponent businessEntity)
        {
            UIBusinessObjectComponent UIEntity = base.BusinessToUI(businessEntity);

            UIEntity.BusCompName = businessEntity.BusCompName;
            UIEntity.LinkName    = businessEntity.LinkName;
            return(UIEntity);
        }
예제 #2
0
        public override IEnumerable <ValidationResult> UIValidate(TContext context, IViewInfo viewInfo, UIBusinessObjectComponent UIEntity, bool isNewRecord)
        {
            List <ValidationResult> result = base.UIValidate(context, viewInfo, UIEntity, isNewRecord).ToList();

            if (string.IsNullOrWhiteSpace(UIEntity.BusCompName))
            {
                result.Add(new ValidationResult(
                               "Business component name is a required field",
                               new List <string>()
                {
                    "BusCompName"
                }));
            }
            return(result);
        }
예제 #3
0
        public override BUSBusinessObjectComponent UIToBusiness(UIBusinessObjectComponent UIEntity, TContext context, IViewInfo viewInfo, bool isNewRecord)
        {
            BUSBusinessObjectComponent businessEntity = base.UIToBusiness(UIEntity, context, viewInfo, isNewRecord);
            BusinessObject             busObject      = context.BusinessObjects
                                                        .AsNoTracking()
                                                        .Select(bo => new
            {
                id         = bo.Id,
                name       = bo.Name,
                components = bo.BusObjectComponents.Select(boc => new
                {
                    id   = boc.Id,
                    name = boc.Name
                })
            })
                                                        .Select(bo => new BusinessObject
            {
                Id   = bo.id,
                Name = bo.name,
                BusObjectComponents = bo.components.Select(boc => new BusinessObjectComponent
                {
                    Id   = boc.id,
                    Name = boc.name
                }).ToList()
            })
                                                        .FirstOrDefault(n => n.Id.ToString() == ComponentsRecordsInfo.GetSelectedRecord("Business Object"));

            if (busObject == null)
            {
                businessEntity.ErrorMessage = "First you need create business object.";
            }
            else
            {
                // Если запись новая и она не уникальна, записывается ошибка
                BusinessObjectComponent businessObjectComponent = busObject.BusObjectComponents?.FirstOrDefault(n => n.Name == UIEntity.Name);
                if (businessObjectComponent != null && businessObjectComponent.Id != UIEntity.Id)
                {
                    businessEntity.ErrorMessage = $"Business object component with this name is already exists in business object {busObject.Name}.";
                }
                else
                {
                    // BusObject
                    businessEntity.BusObject     = busObject;
                    businessEntity.BusObjectId   = busObject.Id;
                    businessEntity.BusObjectName = busObject.Name;

                    // BusComp
                    BusinessComponent busComp = context.BusinessComponents.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.BusCompName);
                    if (busComp != null)
                    {
                        businessEntity.BusComp     = busComp;
                        businessEntity.BusCompId   = busComp.Id;
                        businessEntity.BusCompName = busComp.Name;
                    }

                    // Link
                    Link link = context.Links.AsNoTracking().FirstOrDefault(n => n.Name == UIEntity.LinkName);
                    if (link != null)
                    {
                        businessEntity.Link     = link;
                        businessEntity.LinkId   = link.Id;
                        businessEntity.LinkName = link.Name;
                    }
                }
            }

            return(businessEntity);
        }
예제 #4
0
        public override IEnumerable <ValidationResult> BUSUIValidate(TContext context, BUSBusinessObjectComponent businessComponent, UIBusinessObjectComponent UIEntity)
        {
            List <ValidationResult> result = base.BUSUIValidate(context, businessComponent, UIEntity).ToList();

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