暂无描述

sbakhtina 9b6b19242d Обновить 'README.md' 1 月之前
.vs 1b2e1f4b5e first commit 1 月之前
Windows 1b2e1f4b5e first commit 1 月之前
bin 1b2e1f4b5e first commit 1 月之前
img 1b2e1f4b5e first commit 1 月之前
models 1b2e1f4b5e first commit 1 月之前
obj 1b2e1f4b5e first commit 1 月之前
App.xaml 1b2e1f4b5e first commit 1 月之前
App.xaml.cs 1b2e1f4b5e first commit 1 月之前
AssemblyInfo.cs 1b2e1f4b5e first commit 1 月之前
MainWindow.xaml 1b2e1f4b5e first commit 1 月之前
MainWindow.xaml.cs 1b2e1f4b5e first commit 1 月之前
README.md 9b6b19242d Обновить 'README.md' 1 月之前
sql_pagining.csproj 1b2e1f4b5e first commit 1 月之前
sql_pagining.csproj.user 1b2e1f4b5e first commit 1 月之前

README.md

ApiDataProvider

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace sql_pagining.models
{
    public class ApiDataProvider : DBDataProvider
    {
        private static string baseUrl = "http://localhost:5000";
        public override IEnumerable<Product> getProduct(int pageNum)
        {
            var client = new HttpClient();

            var body = client.GetStringAsync(
                $"{baseUrl}/product?pageNum={pageNum}"
            ).Result;

            return JsonConvert.DeserializeObject<Product[]>(body);
        }


        public override void setOrder(string condition)
        {
            var client = new HttpClient();
            var jsonString = JsonConvert.SerializeObject(condition);
            var json = new StringContent(jsonString, Encoding.UTF8, "aplication/json");
            var body = client.PutAsync($"{baseUrl}/setOrder", json);

        }

        public override List<ProductType> getProductTypes()
        {
            var client = new HttpClient();
            var body = client.GetStringAsync($"{baseUrl}/productType").Result;
            return JsonConvert.DeserializeObject<List<ProductType>>(body);
        }

        public override void setMinCostForAgent(decimal minCost, int[] ids)
        {
            var client = new HttpClient();
            var jsonString = JsonConvert.SerializeObject(ids);
            var json = new StringContent(jsonString, Encoding.UTF8, "application/json");
            var body = client.PutAsync($"{baseUrl}/minCostForAgent/{minCost}", json);
        }


        public override void saveProduct(Product product)
        {
            var client = new HttpClient();
            var jsonString = JsonConvert.SerializeObject(product);
            var json = new StringContent(jsonString, Encoding.UTF8, "application/json");
            if (product.ID != 0)
            {
                var body = client.PutAsync($"{baseUrl}/product", json);
            }
            else
            {
                var body = client.PostAsync($"{baseUrl}/product", json);
            }
        }

        public override int saleCount(int ID)
        {
            var client = new HttpClient();
            var body = client.GetStringAsync($"{baseUrl}/saleCount/{ID}").Result;
            return JsonConvert.DeserializeObject<int>(body);
        }

        public override void removePriceHistory(int ID)
        {
            var client = new HttpClient();
            var body = client.DeleteAsync($"{baseUrl}/removePriceHistory/{ID}");
        }

        public override List<ProductMaterial> getProductMaterials(int ID)
        {
            var client = new HttpClient();
            var body = client.GetStringAsync($"{baseUrl}/productMaterial/{ID}").Result;
            return JsonConvert.DeserializeObject<List<ProductMaterial>>(body);
        }

        public override void deleteProductMaterial(ProductMaterial productMaterial)
        {
            var client = new HttpClient();
            var body = client.DeleteAsync($"{baseUrl}/productMaterial");
        }

        public override List<Material> getAvailableMaterials()
        {
            var client = new HttpClient();
            var body = client.GetStringAsync($"{baseUrl}/material").Result;
            return JsonConvert.DeserializeObject<List<Material>>(body);
        }

        public override void addProductMaterial(ProductMaterial material)
        {
            var client = new HttpClient();
            var jsonString = JsonConvert.SerializeObject(material);
            var json = new StringContent(jsonString, Encoding.UTF8, "application/json");
            var body = client.PostAsync($"{baseUrl}/productMaterial", json).Result;
        }
    }
}