Beispiel #1
0
        /// <inheritdoc />
        public virtual ColumnDefinition Definition(string connectorName, string tableName, string columnName, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.Any, tableName);

            return(resource.GetColumnDefinition(columnName));
        }
Beispiel #2
0
        /// <inheritdoc />
        public virtual IQueryable <TViewModel> GetAll <TViewModel>(string connectorName, string tableName, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            //Manually $expand to prevent nulls on non pk joins
            var joinProperties = typeof(TViewModel).GetProperties()
                                 .Where(c => (c.PropertyType.IsClass && c.PropertyType != typeof(string)) ||
                                        (c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                                 .Select(c => c.Name);

            IQueryable <dynamic> list;

            if (joinProperties.Any())
            {
                list = resource.GetResourceRecords(new Dictionary <string, string>()
                {
                    { "$expand", string.Join(",", joinProperties) }
                });
            }
            else
            {
                list = resource.GetResourceRecords(new Dictionary <string, string>());
            }

            return(list.ProjectTo <TViewModel>());
        }
Beispiel #3
0
        /// <inheritdoc />
        public virtual object DeleteRow(string connectorName, string tableName, ILoggingService loggingService, params object[] id)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.DELETE, id);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.delete, tableName);

            return(resource.DeleteResourceRecordById(id));
        }
Beispiel #4
0
        /// <inheritdoc />
        public virtual object GetById(string connectorName, string tableName, ILoggingService loggingService, params object[] id)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);
            var data = resource.GetResourceRecordById(id);

            return(data);
        }
Beispiel #5
0
        /// <inheritdoc />
        public virtual TViewModel CreateNewRow <TViewModel>(string connectorName, string tableName, TViewModel value, ILoggingService loggingService = null) where TViewModel : class
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.POST);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);
            var data = resource.CreateNewResourceRecord(value);

            return(DynamicObjectExtensions.PopulateModel <TViewModel>(data));
        }
Beispiel #6
0
        /// <inheritdoc />
        public virtual object CreateNewRow(string connectorName, string tableName, JToken value, ILoggingService loggingService = null)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.POST);
            Check.NotNull(value, nameof(value));

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);
            var data = resource.CreateNewResourceRecord(value);

            return(data);
        }
Beispiel #7
0
        /// <inheritdoc />
        public virtual (IQueryable <object> list, int connectorMax) GetAll(string connectorName, string tableName, ILoggingService loggingService = null)
        {
            Check.NotEmpty(connectorName, nameof(connectorName));
            Check.NotEmpty(tableName, nameof(tableName));

            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET);
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            var queryString = _requestQuery.GetQueryStrings();

            return(resource.GetResourceRecords(queryString), resource.Connector.RecordLimit);
        }
Beispiel #8
0
        /// <inheritdoc />
        public virtual TViewModel UpdateRow <TViewModel>(string connectorName, string tableName, TViewModel value, ILoggingService loggingService = null) where TViewModel : class
        {
            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);

            object[] id = null;
            try
            {
                id = resource.GetPrimaryKeys(value);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Log even if values for PK not found
                loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.PUT, id);
            }
            return(resource.UpdateResourceRecordById(value, id));
        }
Beispiel #9
0
        /// <inheritdoc />
        public virtual object UpdateRow(string connectorName, string tableName, JToken value, ILoggingService loggingService = null)
        {
            Check.NotNull(value, nameof(value));

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.write, tableName);

            object[] id = null;
            try
            {
                id = resource.GetPrimaryKeys(value);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Log even if values for PK not found
                loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.PUT, id);
            }
            return(resource.UpdateResourceRecordById(value, id));
        }
Beispiel #10
0
        /// <inheritdoc />
        public virtual TViewModel GetById <TViewModel>(string connectorName, string tableName, ILoggingService loggingService, params object[] id) where TViewModel : class
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            //Manually $expand to prevent nulls on non pk joins
            var joinProperties = typeof(TViewModel).GetProperties()
                                 .Where(c => (c.PropertyType.IsClass && c.PropertyType != typeof(string)) ||
                                        (c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                                 .Select(c => c.Name);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            if (joinProperties.Any())
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()
                {
                    { "$expand", string.Join(",", joinProperties) }
                }));
            }
            else
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()));
            }
        }