Example #1
0
        public async Task<SaveResultInfo> SaveAccountMeterValues(AccountDetailInfo model)
        {
            SaveResultInfo result = null;

            model.UserID = new Guid(User.FindFirst(MyClaimTypes.UserId).Value);
            model.Token = new Guid(this.Token);

            var url = String.Format(AppConst.Http + "://{0}/{1}?token={2}", AppConst.ServerName, "MeterExport/SaveAccountMeterValues", Token);

            try
            {
                using (HttpClient client = new HttpClient())
                {

                    var json = new StringContent(
                        JsonConvert.SerializeObject(model),
                        Encoding.UTF8,
                        "application/json");

                    using (HttpResponseMessage response = await client.PostAsync(url, json))
                    {
                        using (HttpContent content = response.Content)
                        {
                            String __content = await content.ReadAsStringAsync();

                            if (response.StatusCode == HttpStatusCode.OK)
                            {
                                result = JsonConvert.DeserializeObject<SaveResultInfo>(__content);
                            }
                            else if (response.StatusCode == HttpStatusCode.Forbidden)
                            {
                                throw new InvalidOperationException("Not authorized access!");
                            }
                        }
                    }
                }
            }
            catch (Exception __ex)
            {
                Debug.WriteLine(__ex);
                throw;
            }

            return result;
        }
Example #2
0
        public async Task<IActionResult> SaveAccountMeterValues(AccountDetailInfo model)
        {
            var result = await (new AccountServices(User)).SaveAccountMeterValues(model);

            return Json(result);
        }