Ejemplo n.º 1
0
        public override PagedResultFilter Adapt(MEPSearchModel source)
        {
            var gridExtraFilter = FilterAdapter.Adapt(source.ExtraFilter);

            CombinedGroup.Conditions[0].Group = gridExtraFilter == null ? null : gridExtraFilter.Group;

            AddGenericCondition(FieldType.String, "Description", source.Description);
            AddGenericCondition(FieldType.QuotedList, "Status", source.Status);
            AddGenericCondition(FieldType.String, "Name", source.Name);
            AddGenericCondition(FieldType.String, "SerialNumber", source.SerialNumber);
            AddGenericCondition(FieldType.QuotedList, "TimeZone", source.TimeZone);
            AddGenericCondition(FieldType.DateTime, "InstallationDateTime", source.InstallationDate);

            return(new PagedResultFilter
            {
                Group = CombinedGroup,
                PageIndex = source.Page,
                PageSize = source.Rows,
                SortFieldName = source.OrderBy,
                SortType =
                    source.OrderDirection.ToLower() == "asc"
                                   ? SortType.Ascending
                                   : source.OrderDirection.ToLower() == "desc"
                                         ? SortType.Descending
                                         : (SortType?)null
            });
        }
Ejemplo n.º 2
0
 public string Delete(string Json)
 {
     try
     {
         string        TableName = JsonAdapter.TableNameFromJson(Json);
         List <Packet> packets   = PackageAdapter.PacketsFromJson(Json);
         string        Condition = FilterAdapter.GetCondition(TableName, packets.ToArray());
         string        sql       = $"DELETE FROM \"{TableName}\" WHERE {Condition}";
         return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql)));
     }
     catch (Exception ex)
     {
         return(new JObject().AddStatus(ex).ToString());
     }
 }
Ejemplo n.º 3
0
        public ApiAdapter(IDataBaseManagerFactory dbEngine, string address, string port, string table, string login, string password)
        {
            DbManager   = new DatabaseManager(dbEngine, address, port, table, login, password);
            DbConnector = new DbConnector(DbManager);

            LanguageAdapter                = new LanguageAdapter(DbConnector);
            UserAdapter                    = new UserAdapter(DbConnector);
            UserDetailsAdapter             = new UserDetailsAdapter(DbConnector);
            TransactionTypeAdapter         = new TransactionTypeAdapter(DbConnector);
            TransferTypeAdapter            = new TransferTypeAdapter(DbConnector);
            FrequencyAdapter               = new FrequencyAdapter(DbConnector);
            ImportanceAdapter              = new ImportanceAdapter(DbConnector);
            TagAdapter                     = new TagAdapter(DbConnector);
            OperationAdapter               = new OperationAdapter(DbConnector);
            OperationDetailsAdapter        = new OperationDetailsAdapter(DbConnector);
            OperationTagRelationAdapter    = new OperationTagAdapter(DbConnector);
            OperationsGroupAdapter         = new OperationsGroupAdapter(DbConnector);
            OperationsGroupRelationAdapter = new OperationsGroupTagAdapter(DbConnector);
            FilterAdapter                  = new FilterAdapter(DbConnector);
            DashboardAdapter               = new DashboardAdapter(DbConnector);
            DashboardFilterRelationAdapter = new DashboardFilterRelationAdapter(DbConnector);
            BankAdapter                    = new BankAdapter(DbConnector);
            SettingsAdapter                = new SettingsAdapter(DbConnector);
            SchematicTypeAdapter           = new SchematicTypeAdapter(DbConnector);
            SchematicAdapter               = new SchematicAdapter(DbConnector);

            LanguageMapper        = new LanguageMapper();
            UserMapper            = new UserMapper();
            UserDetailsMapper     = new UserDetailsMapper();
            TransactionTypeMapper = new TransactionTypeMapper();
            TransferTypeMapper    = new TransferTypeMapper();
            FrequencyMapper       = new FrequencyMapper();
            ImportanceMapper      = new ImportanceMapper();
            TagMapper             = new TagMapper();
            TagRelationMapper     = new RelationTagMapper();
            OperationMapper       = new OperationMapper();
            OperationsGroupMapper = new OperationsGroupMapper();
            FilterMapper          = new FilterMapper();
            DashboardMapper       = new DashboardMapper();
            DashboardFilterMapper = new DashboardFilterMapper();
            BankMapper            = new BankMapper();
            SettingsMapper        = new SettingsMapper();
            SchematicTypeMapper   = new SchematicTypeMapper();
            SchematicMapper       = new SchematicMapper();
        }
Ejemplo n.º 4
0
        public string Update(string Json)
        {
            try
            {
                string TableName = JsonAdapter.TableNameFromJson(Json);

                List <Packet> packets   = PackageAdapter.PacketsFromJson(Json);
                string        Condition = FilterAdapter.GetCondition(TableName, packets.ToArray());

                List <UpdatePacket> updatePackets = SetConverter.FromJson(Json);
                string Sets = RowCollector.Set(updatePackets);

                string Sql = $"UPDATE \"{TableName}\" {Sets} WHERE {Condition}";
                return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(Sql)));
            }
            catch (Exception ex)
            {
                return(new JObject().AddStatus(ex).ToString());
            }
        }
Ejemplo n.º 5
0
        public string Adapt(string Json)
        {
            string        MainTable = JsonAdapter.TableNameFromJson(Json);
            string        TableName = "";
            List <Packet> packets   = PackageAdapter.PacketsONFromJson(Json);

            PackageAdapter.Normalize(ref packets);
            packets = SetTableName(MainTable, packets.ToArray());
            try
            {
                TableName = $"{GetTableNameFromPackets(packets.ToArray())}";
            }
            catch (Exception ex)
            {
                throw ex;
            }
            string condition = new FilterAdapter().GetOnCondition(TableName, packets.ToArray());
            string Sql       = $"INNER JOIN {TableName} ON {condition}";

            return(Sql);
        }
Ejemplo n.º 6
0
        public string Where(string Json)
        {
            Validators.CheckPackets check = new Validators.CheckPackets();
            try
            {
                LimitPacket limitPacket = GetLimit(ref Json);
                string      limit       = limitPacket == null ? "" : $" {LimitAdapter.AdaptToSql(limitPacket)}";

                OrderByPacket orderByPacket = GetOrderBy(ref Json);
                string        OrderBy       = orderByPacket == null ? "" : $" {OrderByAdapter.ToSql(orderByPacket)}";

                if (check.CheckJoin(Json))
                {
                    string Condition            = "";
                    Joining.JoinAdapter adapter = new Joining.JoinAdapter();
                    string TableName            = JsonAdapter.TableNameFromJson(Json);
                    if (check.CheckPacket(Json))
                    {
                        List <Packet> packets = PackageAdapter.PacketsFromJson(Json);
                        PackageAdapter.Normalize(ref packets);
                        Condition = $"WHERE {FilterAdapter.GetCondition(TableName, packets.ToArray())}";
                    }
                    string JoinCondition = adapter.Adapt(Json);
                    string sql           = $"SELECT * FROM \"{TableName}\" {JoinCondition} {Condition}{OrderBy}{limit}";
                    return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql)));
                }
                else
                {
                    string        TableName = JsonAdapter.TableNameFromJson(Json);
                    List <Packet> packets   = PackageAdapter.PacketsFromJson(Json);
                    string        Condition = FilterAdapter.GetCondition(TableName, packets.ToArray());
                    string        sql       = $"SELECT * FROM \"{TableName}\" WHERE {Condition}{OrderBy}{limit}";
                    return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql)));
                }
            }
            catch (Exception ex)
            {
                return(new JObject().AddStatus(ex).ToString());
            }
        }
Ejemplo n.º 7
0
 public List <ApiFilter> GetFilters(ApiUser user)
 {
     FilterMapper.Update(user);
     return(FilterMapper.ConvertToApiEntitiesCollection(FilterAdapter.GetAll($"user_id={user.Id}")).ToList());
 }
Ejemplo n.º 8
0
 public bool DeleteFilter(int id)
 {
     FilterAdapter.Delete(id);
     return(true);
 }