2019-01-13 16:36:26 +01:00
|
|
|
|
using Magazyn.DataModels;
|
|
|
|
|
using Magazyn.Views;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
using Newtonsoft.Json;
|
2019-01-22 17:35:51 +01:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
|
|
|
|
namespace Magazyn
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
HttpClient client;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-01-14 20:10:05 +01:00
|
|
|
|
client = new HttpClient();
|
|
|
|
|
RefreshListOfFruits();
|
|
|
|
|
}
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshListOfFruits();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FruitViewSaveChangingAmountOfFruits(int amountChanged, Fruit fruit)
|
|
|
|
|
{
|
|
|
|
|
string json = "{\"id\": " + fruit.Id.ToString() + ", \"change\": " + amountChanged.ToString() + " }";
|
|
|
|
|
|
2019-01-13 18:05:47 +01:00
|
|
|
|
Task<HttpResponseMessage> response = client.PostAsync("https://sysmag.herokuapp.com/api/product/change-quantity", new StringContent(json, Encoding.UTF8, "application/json"));
|
2019-01-21 14:43:04 +01:00
|
|
|
|
while (response.IsCompleted != true)
|
|
|
|
|
{
|
|
|
|
|
RefreshListOfFruits();
|
|
|
|
|
}
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshListOfFruits()
|
|
|
|
|
{
|
2019-01-22 17:35:51 +01:00
|
|
|
|
|
2019-01-14 20:10:05 +01:00
|
|
|
|
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all");
|
2019-01-22 17:35:51 +01:00
|
|
|
|
while (response.IsCompleted != true) ;
|
|
|
|
|
|
|
|
|
|
string responseString = response.Result.Content.ReadAsStringAsync().Result;
|
|
|
|
|
|
|
|
|
|
JObject replay = JObject.Parse(responseString);
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
2019-01-22 17:35:51 +01:00
|
|
|
|
Fruit[] fruits = JsonConvert.DeserializeObject<Fruit[]>(replay["content"].ToString());
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
|
|
|
|
UpdateListOfFruits(fruits);
|
2019-01-14 20:10:05 +01:00
|
|
|
|
}
|
2019-01-13 16:36:26 +01:00
|
|
|
|
|
|
|
|
|
private void UpdateListOfFruits(Fruit[] list)
|
|
|
|
|
{
|
|
|
|
|
fruitList.Items.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (Fruit item in list)
|
|
|
|
|
{
|
|
|
|
|
FruitView fruitView = new FruitView(item);
|
|
|
|
|
fruitView.SaveChangingAmountOfFruits += FruitViewSaveChangingAmountOfFruits;
|
|
|
|
|
fruitList.Items.Add(fruitView);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 17:01:56 +01:00
|
|
|
|
private WarehousePrice GetWarehousePrice()
|
2019-01-13 16:36:26 +01:00
|
|
|
|
{
|
|
|
|
|
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-price-of-all");
|
|
|
|
|
while (response.IsCompleted != true) ;
|
2019-01-13 17:01:56 +01:00
|
|
|
|
|
|
|
|
|
WarehousePrice price = JsonConvert.DeserializeObject<WarehousePrice>(response.Result.Content.ReadAsStringAsync().Result.ToString());
|
|
|
|
|
|
|
|
|
|
return price;
|
2019-01-13 16:36:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2019-01-21 19:48:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-16 19:29:42 +01:00
|
|
|
|
MessageBox.Show("Wartość magazynu to: " + GetWarehousePrice().Price.ToString() + "zł", "Wartość magazynu" );
|
2019-01-21 19:48:10 +01:00
|
|
|
|
|
2019-01-13 16:36:26 +01:00
|
|
|
|
}
|
2019-01-14 20:10:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-13 16:36:26 +01:00
|
|
|
|
}
|
|
|
|
|
|