Exemple #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());
            }
        }
Exemple #2
0
        public Message Put(Message message)
        {
            MessageInformation information = new MessageInformation(message);

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