Exemplo n.º 1
0
        public async Task <ItemUnit> GetById(int itemUnitId)
        {
            ItemUnit item = new ItemUnit();
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters.Add("itemUnitId", itemUnitId.ToString());

            //#################
            IEnumerable <Claim> claims = await APIResult.getList("ItemsUnits/GetById", parameters);

            foreach (Claim c in claims)
            {
                if (c.Type == "scopes")
                {
                    item = JsonConvert.DeserializeObject <ItemUnit>(c.Value, new IsoDateTimeConverter {
                        DateTimeFormat = "dd/MM/yyyy"
                    });
                }
            }
            return(item);

            //ItemUnit items = null;
            //... Use HttpClient.
            //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            //using (var client = new HttpClient())
            //{
            //    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            //    client.BaseAddress = new Uri(Global.APIUri);
            //    client.DefaultRequestHeaders.Clear();
            //    client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
            //    client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
            //    HttpRequestMessage request = new HttpRequestMessage();
            //    request.RequestUri = new Uri(Global.APIUri + "ItemsUnits/GetById?itemUnitId=" + itemUnitId);
            //    request.Headers.Add("APIKey", Global.APIKey);
            //    request.Method = HttpMethod.Get;
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    HttpResponseMessage response = await client.SendAsync(request);

            //    if (response.IsSuccessStatusCode)
            //    {
            //        var jsonString = await response.Content.ReadAsStringAsync();
            //        jsonString = jsonString.Replace("\\", string.Empty);
            //        jsonString = jsonString.Trim('"');
            //       // fix date format
            //       JsonSerializerSettings settings = new JsonSerializerSettings
            //       {
            //           Converters = new List<JsonConverter> { new BadDateFixingConverter() },
            //           DateParseHandling = DateParseHandling.None
            //       };
            //        items = JsonConvert.DeserializeObject<ItemUnit>(jsonString, new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy" });
            //        return items;
            //    }
            //    else //web api sent error response
            //    {
            //        items = new ItemUnit();
            //    }
            //    return items;
            //}
        }
Exemplo n.º 2
0
        //***************************************
        // add or update item unit
        //***************************************
        public async Task <int> saveItemUnit(ItemUnit itemUnit)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            string method = "ItemsUnits/Save";

            var myContent = JsonConvert.SerializeObject(itemUnit);

            parameters.Add("Object", myContent);
            return(await APIResult.post(method, parameters));


            //// ... Use HttpClient.
            //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            ////
            //var myContent = JsonConvert.SerializeObject(itemUnit);

            //using (var client = new HttpClient())
            //{
            //    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            //    client.BaseAddress = new Uri(Global.APIUri);
            //    client.DefaultRequestHeaders.Clear();
            //    client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
            //    client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
            //    HttpRequestMessage request = new HttpRequestMessage();
            //    // encoding parameter to get special characters
            //    myContent = HttpUtility.UrlEncode(myContent);
            //    request.RequestUri = new Uri(Global.APIUri + "ItemsUnits/Save?itemsUnitsObject=" + myContent);
            //    request.Headers.Add("APIKey", Global.APIKey);
            //    request.Method = HttpMethod.Post;
            //    //set content type
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    var response = await client.SendAsync(request);

            //    if (response.IsSuccessStatusCode)
            //    {
            //        return "true";
            //    }
            //    return "false";
            //}
        }
Exemplo n.º 3
0
        public async Task <int> unitsConversion(int branchId, int fromItemUnit, int toItemUnt, int fromQuantity, int toQuantity, int userId, ItemUnit smallUnit)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();
            string method = "ItemsLocations/unitsConversion";


            parameters.Add("branchId", branchId.ToString());
            parameters.Add("userId", userId.ToString());
            parameters.Add("fromItemUnit", fromItemUnit.ToString());
            parameters.Add("toItemUnt", toItemUnt.ToString());
            parameters.Add("fromQuantity", fromQuantity.ToString());
            parameters.Add("toQuantity", toQuantity.ToString());



            var myContent = JsonConvert.SerializeObject(smallUnit);

            parameters.Add("Object", myContent);

            return(await APIResult.post(method, parameters));



            //// ... Use HttpClient.
            //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            //if (smallUnit == null)
            //    smallUnit = new ItemUnit();
            //var myContent = JsonConvert.SerializeObject(smallUnit);
            //using (var client = new HttpClient())
            //{
            //    ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            //    client.BaseAddress = new Uri(Global.APIUri);
            //    client.DefaultRequestHeaders.Clear();
            //    client.DefaultRequestHeaders.Add("Connection", "Keep-Alive");
            //    client.DefaultRequestHeaders.Add("Keep-Alive", "3600");
            //    HttpRequestMessage request = new HttpRequestMessage();
            //    request.RequestUri = new Uri(Global.APIUri + "ItemsLocations/unitsConversion?branchId=" + branchId+ "&fromItemUnit="+ fromItemUnit + "&toItemUnit="+toItemUnt+
            //                                                    "&fromQuantity="+fromQuantity + "&toQuantity="+ toQuantity + "&userId=" +userId + "&smallUnit=" + myContent);
            //    request.Headers.Add("APIKey", Global.APIKey);
            //    request.Method = HttpMethod.Post;
            //    //set content type
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    var response = await client.SendAsync(request);

            //    if (response.IsSuccessStatusCode)
            //    {
            //        return true;
            //    }
            //    return false;
            //}
        }