Esempio n. 1
0
        internal void ValidateAssociation(IObjectFacade nakedObject, IAssociationFacade oneToOneAssoc, object attemptedValue, IAssociationFacade parent = null)
        {
            string key = GetFieldInputId(parent, nakedObject, oneToOneAssoc);

            try {
                var oid = Facade.OidTranslator.GetOidTranslation(nakedObject);

                var ac = new ArgumentContextFacade {
                    Value        = attemptedValue,
                    ValidateOnly = true
                };

                var pcs = Facade.PutProperty(oid, oneToOneAssoc.Id, ac);

                if (!string.IsNullOrEmpty(pcs.Reason))
                {
                    ModelState.AddModelError(key, pcs.Reason);
                }
            }
            catch (NakedObjectsFacadeException) {
                ModelState.AddModelError(key, MvcUi.InvalidEntry);
            }
            finally {
                AddAttemptedValue(key, attemptedValue);
            }
        }
        public static PropertyContextFacade DeletePropertyAndValidate(this IFrameworkFacade frameworkFacade, string domainType, string instanceId, string propertyName, ArgumentContextFacade argContext)
        {
            var link    = frameworkFacade.OidTranslator.GetOidTranslation(domainType, instanceId);
            var context = frameworkFacade.DeleteProperty(link, propertyName, argContext);

            return(ValidatePropertyContext(context));
        }
 private PropertyContextFacade ChangeProperty(NakedObject nakedObject, string propertyName, ArgumentContextFacade argument)
 {
     ValidateConcurrency(nakedObject, argument.Digest);
     return(CanChangeProperty(nakedObject, propertyName, argument.ValidateOnly, argument.Value).ToPropertyContextFacade(this));
 }
        private PropertyContextFacade ChangeCollection(PropertyContext context, Func <NakedObject, NakedObject, Consent> validator, Action <NakedObject, NakedObject> mutator, ArgumentContextFacade args)
        {
            ValidateConcurrency(context.Target, args.Digest);

            var property = (OneToManyAssociation)context.Property;

            if (ConsentHandler(IsOfCorrectType(property, context), context, Cause.Other))
            {
                if (ConsentHandler(IsCurrentlyImmutable(context.Target), context, Cause.Immutable))
                {
                    if (ConsentHandler(property.isAvailable(context.Target), context, Cause.Disabled))
                    {
                        if (ConsentHandler(validator(context.Target, (NakedObject)context.ProposedNakedObject), context, Cause.Other))
                        {
                            if (!args.ValidateOnly)
                            {
                                mutator(context.Target, (NakedObject)context.ProposedNakedObject);
                            }
                        }
                    }
                }
            }

            context.Mutated = true;
            return(context.ToPropertyContextFacade(this));
        }
 public PropertyContextFacade DeleteFromCollection(IOidTranslation objectId, string propertyName, ArgumentContextFacade argument)
 {
     return(MapErrors(() => {
         PropertyContext context = SetupPropertyContext(GetObjectAsNakedObject(objectId), propertyName, argument.Value);
         var property = (OneToManyAssociation)context.Property;
         return ChangeCollection(context, property.validToRemove, property.removeElement, argument);
     }));
 }
 public PropertyContextFacade DeleteProperty(IOidTranslation objectId, string propertyName, ArgumentContextFacade argument)
 {
     return(MapErrors(() => ChangeProperty(GetObjectAsNakedObject(objectId), propertyName, argument)));
 }