Exemplo n.º 1
0
        public static async Task <int> Delete(object obj, Type T, Type TPHtype = null)
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);

            DeleteUpdateResponse res = await client.DeleteAsync(RequestHelper(obj, T, TPHtype));

            if (res.Error.ErrorResponse != "")
            {
                throw new Exception(res.Error.ErrorResponse);
            }
            return(res.RowsAffected);
        }
Exemplo n.º 2
0
        public static async Task <int> Insert(object obj, Type T, Type TPHtype = null)
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);

            InsertResponse res = await client.InsertAsync(RequestHelper(obj, T, TPHtype));

            if (res.Error.ErrorResponse != "")
            {
                throw new Exception(res.Error.ErrorResponse);
            }
            return(res.InsertedID);
        }
Exemplo n.º 3
0
        public static async Task <string> GetCategoriesHash()
        {
            var channel = GenerateChannel();
            var client  = new NetshopClient(channel);

            var res = await client.GetCategoriesHashAsync(new GetAllRequest());

            if (res.Error.ErrorResponse != "")
            {
                throw new Exception(res.Error.ErrorResponse);
            }
            return(res.Hash);
        }
Exemplo n.º 4
0
        public static async Task <List <T> > GetListOfPartsByCategoryId <T>(int CategoryId)
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);

            var res = await client.GetPartsByCategoryIdAsync(new GetByIdRequest { Id = CategoryId });

            if (res.ErrorMessage != "")
            {
                throw new Exception(res.ErrorMessage);
            }
            List <T> deserialized = utils.DeserializeJsonWithTypes <T>(res.Response);

            return(deserialized);
        }
Exemplo n.º 5
0
        public static async Task <int> PlaceOrder(int partsID, int partsQTY, string clientName, string clientEmail)
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);
            var req    = new PlaceOrderRequest {
                PartsId = partsID, PartsQty = partsQTY, ClientName = clientName, ClientEMail = clientEmail
            };
            InsertResponse res = await client.PlaceOrderAsync(req);

            if (res.Error.ErrorResponse != "")
            {
                throw new Exception(res.Error.ErrorResponse);
            }
            return(res.InsertedID);
        }
Exemplo n.º 6
0
        public static async Task <List <ClientOrder> > GetListOfOrders()
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);

            var res = await client.GetOrdersAsync(new GetAllRequest());

            if (res.ErrorMessage != "")
            {
                throw new Exception(res.ErrorMessage);
            }
            var deserialized = JsonConvert.DeserializeObject <List <ClientOrder> >(res.Response);

            return(deserialized);
        }
Exemplo n.º 7
0
        public static async Task <NPart> GetPartsById(int PartId)
        {
            using var channel = GenerateChannel();
            var client = new NetshopClient(channel);

            var res = await client.GetPartByIdAsync(new GetByIdRequest { Id = PartId });

            if (res.ErrorMessage != "")
            {
                throw new Exception(res.ErrorMessage);
            }
            List <NPart> deserialized = utils.DeserializeJsonWithTypes <NPart>(res.Response);

            if (deserialized.Count != 1)
            {
                throw new Exception("Something went wrong on selection NPart.");
            }
            return(deserialized.First());
        }