/// <inheritdoc /> public async Task <Beer> CreateBeerAsync(Beer beer) { Beers.Add(beer); await SaveChangesAsync(); return(await GetBeerByIdAsync(beer.BeerId)); }
public void onAddClicked(IBeer beer) { IBeer newBeer = Dao.getData().GetNewBeer(); AssignValuesToBeer(newBeer, beer); Dao.getData().AddNewBeer(newBeer); Beers.Add(newBeer); }
public void SetBeers(IEnumerable <Beer> inBeers) { Beers.Clear(); foreach (var beer in inBeers) { Beers.Add(new BeerViewModel(beer)); } RefreshFilter(); }
private async Task SearchBeer(string query) { IsBusy = true; Beers.Clear(); var beers = await _untappdService.SearchBeer(query); foreach (var beer in beers) { Beers.Add(beer); } IsBusy = false; }
async Task LoadMoreBeers() { LastLoadedPage++; var resultFromApi = await ApiService.GetBeersByStyle(_style.Id, LastLoadedPage).SetIsLoading(this); if (resultFromApi.Status == Status.Failure) { return; } LastLoadedPage = resultFromApi.CurrentPage; TotalPages = resultFromApi.NumberOfPages; resultFromApi.Data.ForEach(b => Beers.Add(b)); }
public Beer AddBeer(string name, double?alcoholByVolume = null, decimal price = 0, string description = null) { if (name != null && Beers.Any(b => b.Name == name)) { throw new ArgumentException($"Brewer {Name} has already a beer by the name of {name}"); } Beer newBeer = new Beer(name) { AlcoholByVolume = alcoholByVolume, Description = description, Price = price }; Beers.Add(newBeer); return(newBeer); }
private async Task ExecuteSearchBeersCommand() { if (IsBusy) { return; } using (Insights.TrackTime("BeerSearch", "searchTerm", SearchTerm)) { _userDialogs.ShowLoading("Searching..."); IsBusy = true; IsSearched = true; try { var results = await _beerDrinkinClient.SearchBeersAsync(SearchTerm); Beers.Clear(); if (results?.Count > 0) { foreach (var beer in results) { Beers.Add(beer); } } _userDialogs.HideLoading(); } catch (Exception ex) { _userDialogs.ShowError(ex.Message); } finally { IsBusy = false; } } }
public static void Start() { TcpListener Beerserver = null; try { // Set the TcpListener on port 13000. Int32 port = 4646; IPAddress localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port); Beerserver = new TcpListener(localAddr, port); Beerserver.Start(); while (true) { Console.WriteLine("Waiting for a connection..."); TcpClient client = Beerserver.AcceptTcpClient(); Console.WriteLine("Connected!"); // Get a stream object for reading and writing NetworkStream stream = client.GetStream(); Stream ns = client.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); sw.AutoFlush = true; string message = sr.ReadLine(); Console.WriteLine(value: "Client: " + message); if (message.Equals("Getall")) { sw.WriteLine("Getall"); sw.WriteLine(JsonConvert.SerializeObject(Beers).ToString()); } else if (message.Equals("Getbyid")) { sw.WriteLine("Getbyid"); sw.WriteLine("Write you Prefered ID"); String lineid = sr.ReadLine(); int number = Int32.Parse(lineid); sw.WriteLine(JsonConvert.SerializeObject(Beers.Find(Beers => Beers.ID==number))); } else if (message.Equals("Save")) { sw.WriteLine("Save"); sw.WriteLine("Write a new Beer"); string Beer = sr.ReadLine(); Beers.Add(JsonConvert.DeserializeObject<Beer>(Beer)); } else { sw.WriteLine("Function not recognized"); } client.Close(); Console.WriteLine("it has stopped"); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task CreateBeer(Beer beer) { Beers.Add(beer); await SaveChangesAsync(); }
public void AddBeer(Beer beer) { beer.BeerId = Beers.Any() ? Beers.Max(b => b.BeerId) + 1 : 1; Beers.Add(beer); }