public Message Get(Message message) { MessageInformation information = new MessageInformation(message); try { string sessionToken = this.GetSessionToken(information); MessagePath path = new MessagePath(information); ISecurityManager securityManager = IoC.Get <ISecurityManager>(); object response; if (path.IsByParent) { MessagePath parentPath = new MessagePath(information, true); if (!parentPath.HasKeyParameter) { throw new ArgumentException("A link to a parent must have parameter key"); } dynamic bo = securityManager.DynamicGetBO(parentPath.DtoType, sessionToken); object parent = bo.GetOne(string.Empty, parentPath.QueryInfo); IObjectProxy proxy = ObjectProxyFactory.Get(parent); object value = proxy.GetValue(parent, path.ParentKeyParameter); QueryInfo query = new QueryInfo(); query.Equal(path.KeyParameterName, value.ToString()); bo = securityManager.DynamicGetBO(path.DtoType, sessionToken); response = bo.GetOne(string.Empty, query); } else { dynamic bo = securityManager.DynamicGetBO(path.DtoType, sessionToken); if (path.HasKeyParameter) { response = bo.GetOne(string.Empty, path.QueryInfo); } else { response = bo.GetAll(path.QueryInfo); } } 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) { if (ex is TargetInvocationException) { return(ex.InnerException.Message.ToJsonMessage()); } else { return(ex.Message.ToJsonMessage()); } } }
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()); } }
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()); } }
public Message Delete(Message message) { MessageInformation information = new MessageInformation(message); try { string sessionToken = this.GetSessionToken(information); MessagePath path = new MessagePath(information); if (!path.HasKeyParameter) { throw new ArgumentException("DELETE operation must have a key parameter in the path."); } ISecurityManager securityManager = IoC.Get <ISecurityManager>(); dynamic bo = securityManager.DynamicGetBO(path.DtoType, sessionToken); object response = bo.Delete(path.KeyParameter); return(response.ToJsonMessage()); } catch (Exception ex) { return(ex.Message.ToJsonMessage()); } }