Exemplo n.º 1
0
        public ActionResult ConstructFrom()
        {
            OperationSymbol operationSymbol;
            Entity          entity = null;

            if (this.IsLite())
            {
                Lite <Entity> lite = this.ExtractLite <Entity>();
                entity = OperationLogic.ServiceConstructFromLite(lite, operationSymbol = this.GetOperationKeyAssert(lite.EntityType));
            }
            else
            {
                MappingContext context = this.UntypedExtractEntity().UntypedApplyChanges(this).UntypedValidate();

                entity = (Entity)context.UntypedValue;

                if (context.HasErrors())
                {
                    return(context.ToJsonModelState());
                }

                try
                {
                    entity = OperationLogic.ServiceConstructFrom(entity, operationSymbol = this.GetOperationKeyAssert(entity.GetType()));
                }
                catch (IntegrityCheckException e)
                {
                    context.ImportErrors(e.Errors);
                    return(context.ToJsonModelState());
                }
            }

            return(this.DefaultConstructResult(entity, operation: operationSymbol));
        }
Exemplo n.º 2
0
        public ActionResult Delete()
        {
            if (this.IsLite())
            {
                Lite <Entity> lite = this.ExtractLite <Entity>();

                OperationLogic.ServiceDelete(lite, this.GetOperationKeyAssert(lite.EntityType), null);

                return(this.DefaultDelete(lite.EntityType));
            }
            else
            {
                MappingContext context = this.UntypedExtractEntity().UntypedApplyChanges(this).UntypedValidate();

                Entity entity = (Entity)context.UntypedValue;

                try
                {
                    OperationLogic.ServiceDelete(entity, this.GetOperationKeyAssert(entity.GetType()), null);
                }
                catch (IntegrityCheckException e)
                {
                    context.ImportErrors(e.Errors);
                    return(context.ToJsonModelState());
                }

                return(this.DefaultDelete(entity.GetType()));
            }
        }
        public JsonNetResult Validate(string rootType = null, string propertyRoute = null)
        {
            ModifiableEntity mod = this.UntypedExtractEntity();

            PropertyRoute route = (rootType.HasText() || propertyRoute.HasText()) ? PropertyRoute.Parse(TypeLogic.GetType(rootType), propertyRoute) : PropertyRoute.Root(mod.GetType());

            MappingContext context = mod.UntypedApplyChanges(this, route: route).UntypedValidate();

            IEntity ident    = context.UntypedValue as IEntity;
            string  newToStr = context.UntypedValue.ToString();

            return(context.ToJsonModelState(newToStr));
        }
Exemplo n.º 4
0
        public ActionResult ShipOrder()
        {
            MappingContext <OrderEntity> ctx = this.ExtractEntity <OrderEntity>().ApplyChanges(this);

            if (ctx.HasErrors())
            {
                return(ctx.ToJsonModelState());
            }

            var shipDate = this.ParseValue <DateTime>("shipDate");

            try
            {
                ctx.Value.Execute(OrderOperation.Ship, shipDate);
            }
            catch (IntegrityCheckException e)
            {
                ctx.ImportErrors(e.Errors);

                return(ctx.ToJsonModelState());
            }

            return(this.DefaultExecuteResult(ctx.Value));
        }