public async Task <string> Get(string name) { try { List <Bird> allBirds = (List <Bird>) new DataContractJsonSerializer(typeof(List <Bird>)) .ReadObject(await AzureDataBase.DownloadData("все_птицы.json", AzureDataBase.BlobContainerBirds)); return((allBirds.Where(x => x.Name.Contains(name)).Distinct().First()).Serialize()); //return (await AzureDataBase.DownloadBirdData(name)).Serialize(); } catch (BirdBaseException e) { return("Ошибка: " + e.Message); } catch (Exception) { return("Неизвестная ошибка"); } }
public async Task <string> Filter([FromRoute] string color, [FromRoute] string size) { try { // Подтянули всех птиц List <Bird> allBirds = (List <Bird>) new DataContractJsonSerializer(typeof(List <Bird>)) .ReadObject(await AzureDataBase.DownloadData("все_птицы.json", AzureDataBase.BlobContainerBirds)); //List<Bird> allBirds = JsonSerializer.Deserialize<List<Bird>>(await AzureDataBase.DownloadAllBirds()); // Фильтруем птиц List <Bird> found_birds = allBirds.Where(x => x.Color.Contains(color) && x.Size.Contains(size)).GroupBy(x => x.Name).Select(g => g.First()).ToList(); // Сереализуем массив и отправляем обратно var ms = new MemoryStream(); // Serializer the List<Bird> object to the stream. new DataContractJsonSerializer(typeof(List <Bird>)).WriteObject(ms, found_birds); byte[] json = ms.ToArray(); ms.Close(); return(Encoding.UTF8.GetString(json, 0, json.Length)); } catch (BirdBaseException e) { return("Ошибка: " + e.Message); } catch (Exception) { return("Неизвестная ошибка"); } }