Beispiel #1
0
        public Message Post(Message message)
        {
            MessageInformation information = new MessageInformation(message);

            try
            {
                string                 sessionToken    = this.GetSessionToken(information);
                MessagePath            path            = new MessagePath(information);
                ISecurityManager       securityManager = IoC.Get <ISecurityManager>();
                IServiceConfiguration  configuration   = IoC.Get <IServiceConfiguration>();
                JsonSerializerSettings settings        = IoC.Get <JsonSerializerSettings>();
                if (path.IsQuery)
                {
                    dynamic   bo   = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    QueryInfo info = information.GetBody <QueryInfo>();
                    info.AddFacetsFrom(path.QueryInfo);
                    object response;
                    if (path.HasKeyParameter)
                    {
                        response = bo.GetOne(string.Empty, info);
                    }
                    else
                    {
                        response = bo.GetAll(info);
                    }
                    if (configuration.IsHateoas)
                    {
                        response = this.ConvertToHateoas(response, configuration, path);
                    }
                    return(response.ToJsonMessage(settings, configuration.Indented));
                }
                else
                {
                    if (path.HasKeyParameter)
                    {
                        throw new ArgumentException("POST operation cannot have a key parameter in the path.");
                    }
                    dynamic bo       = securityManager.DynamicGetBO(path.DtoType, sessionToken);
                    dynamic dto      = information.GetBody(path.DtoType);
                    object  response = bo.Insert(dto);
                    if (configuration.IsHateoas)
                    {
                        response = ConvertToHateoas(response, configuration, path, true);
                    }
                    return(response.ToJsonMessage());
                }
            }
            catch (Exception ex)
            {
                return(ex.Message.ToJsonMessage());
            }
        }