Exemplo n.º 1
0
        private List <string> GetSearchParameters(string genericName, string brandName, string manufacturer,
                                                  string barcode, TherapeuticClassDbModel therapeuticClass)
        {
            List <string> searchParameters = new List <string>();

            if (!string.IsNullOrWhiteSpace(genericName))
            {
                searchParameters.Add($"GenericName = '{genericName}'");
            }

            if (!string.IsNullOrWhiteSpace(brandName))
            {
                searchParameters.Add($"BrandName = '{brandName}'");
            }

            if (!string.IsNullOrWhiteSpace(manufacturer))
            {
                searchParameters.Add($"Manufacturer = '{manufacturer}'");
            }

            if (!string.IsNullOrWhiteSpace(barcode))
            {
                searchParameters.Add($"Barcode = '{barcode}'");
            }

            if (therapeuticClass != null)
            {
                searchParameters.Add($"TherapeuticClassId = {therapeuticClass.TherapeuticClassId}");
            }

            return(searchParameters);
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <ItemDbModel> > GetItems(string genericName = "", string brandName = "", string manufacturer = "", string barcode = "",
                                                                TherapeuticClassDbModel therapeuticClass = null)
        {
            var searchParameters = GetSearchParameters(genericName, brandName, manufacturer, barcode, therapeuticClass);

            string query = "";

            if (searchParameters.Count == 0)
            {
                query = "SELECT * FROM Item";
            }
            else
            {
                var searchQuery = string.Join(" AND ", searchParameters);

                query = $"SELECT * FROM Item WHERE {searchQuery}";
            }

            return(await SqliteDataAccess.ExecuteQueryAsync <ItemDbModel>(_connectionString, query));
        }