Esempio n. 1
0
        private Task Persist(MethodEnum method, Try <Type> maybeRoot, HttpContext context)
        {
            if (maybeRoot.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var rootType = maybeRoot.Result;
            var array    = Utility.ParseObject(Serialization, rootType.MakeArrayType(), context.Request.Body, false, Locator, context);

            if (array.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var arg = (object[])array.Result;

            return(Converter.PassThrough <PersistAggregateRoot, PersistAggregateRoot.Argument <object> >(
                       context,
                       new PersistAggregateRoot.Argument <object>
            {
                RootName = rootType.FullName,
                ToInsert = method == MethodEnum.Insert ? arg : null,
                ToUpdate = method == MethodEnum.Update ? CreateKvMethod.MakeGenericMethod(rootType).Invoke(this, new[] { arg }) : null,
                ToDelete = method == MethodEnum.Delete ? arg : null
            }));
        }
Esempio n. 2
0
        public void Create(string root, [FromQuery(Name = "result")] string result = null)
        {
            var request       = HttpContext.Request;
            var response      = HttpContext.Response;
            var rootType      = Utility.CheckAggregateRoot(DomainModel, root, response);
            var validatedData = Utility.ParseObject(Serialization, rootType, request.Body, false, Locator, request, response);

            if (validatedData.IsFailure)
            {
                return;
            }

            Converter.PassThrough <Create, Create.Argument <object> >(
                HttpContext,
                new Create.Argument <object>
            {
                Name           = rootType.Result.FullName,
                Data           = validatedData.Result,
                ReturnInstance = Utility.ReturnInstance(result, request)
            });
        }
Esempio n. 3
0
        public Task Create(Type rootType, HttpContext context)
        {
            if (!typeof(IAggregateRoot).IsAssignableFrom(rootType))
            {
                return(Utility.WriteError(context.Response, $"{rootType.FullName} is not an aggregate root", HttpStatusCode.BadRequest));
            }
            var request       = context.Request;
            var result        = request.Query.ContainsKey("result") ? request.Query["result"][0] : null;
            var validatedData = Utility.ParseObject(Serialization, rootType, request.Body, false, Locator, context);

            if (validatedData.IsFailure)
            {
                return(Task.CompletedTask);
            }

            return(Converter.PassThrough <Create, Create.Argument <object> >(
                       context,
                       new Create.Argument <object>
            {
                Name = rootType.FullName,
                Data = validatedData.Result,
                ReturnInstance = Utility.ReturnInstance(result, request)
            }));
        }
        public Task PopulateReport(string report, HttpContext context)
        {
            var request       = context.Request;
            var response      = context.Response;
            var reportType    = Utility.CheckDomainObject(DomainModel, report, response);
            var validatedData = Utility.ParseObject(Serialization, reportType, request.Body, true, Locator, context);

            if (validatedData.IsFailure)
            {
                return(Task.CompletedTask);
            }
            return(Converter.PassThrough <PopulateReport, PopulateReport.Argument <object> >(
                       context,
                       new PopulateReport.Argument <object>
            {
                ReportName = reportType.Result.FullName,
                Data = validatedData.Result
            }));
        }
        public void Find(string domainObject, [FromQuery(Name = "order")] string order = null)
        {
            var request  = HttpContext.Request;
            var response = HttpContext.Response;
            var type     = Utility.CheckIdentifiable(DomainModel, domainObject, response);

            if (type.IsFailure)
            {
                return;
            }
            var uris = Serialization.TryDeserialize <string[]>(request, response);

            if (uris.IsFailure)
            {
                return;
            }

            Converter.PassThrough <GetDomainObject, GetDomainObject.Argument>(
                HttpContext,
                new GetDomainObject.Argument
            {
                Name       = domainObject,
                Uri        = uris.Result,
                MatchOrder = order == "match"
            });
        }
Esempio n. 6
0
        public Task Find(string domainObject, HttpContext context)
        {
            var request  = context.Request;
            var response = context.Response;
            var order    = request.Query.ContainsKey("order") ? request.Query["order"][0] : null;

            var type = Utility.CheckIdentifiable(DomainModel, domainObject, response);

            if (type.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var uris = Serialization.TryDeserialize <string[]>(request, response);

            if (uris.IsFailure)
            {
                return(Task.CompletedTask);
            }

            return(Converter.PassThrough <GetDomainObject, GetDomainObject.Argument>(
                       context,
                       new GetDomainObject.Argument
            {
                Name = domainObject,
                Uri = uris.Result,
                MatchOrder = order == "match"
            }));
        }