コード例 #1
0
        public async Task <IActionResult> AddPoint()
        {
            try
            {
                var pointParam = new AddCalcEnergyPoint();
                using (var client = new HttpClient {
                    BaseAddress = new Uri("http://localhost:8050")
                })
                {
                    var req  = new HttpRequestMessage(HttpMethod.Get, "ConsObject");
                    var resp = await client.SendAsync(req);

                    if (!resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", new { msg = (await resp.Content.ReadAsStringAsync()).FromJson <string>() }));
                    }

                    pointParam.ChildOrganizations = (await resp.Content.ReadAsStringAsync()).FromJson <ItemInfo[]>();
                    req  = new HttpRequestMessage(HttpMethod.Get, "ElectricEnergyMeter");
                    resp = await client.SendAsync(req);

                    if (!resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", new { msg = (await resp.Content.ReadAsStringAsync()).FromJson <string>() }));
                    }

                    pointParam.ElectricEnergyMeters = (await resp.Content.ReadAsStringAsync()).FromJson <ItemInfo[]>();
                    req  = new HttpRequestMessage(HttpMethod.Get, "CurTransformator");
                    resp = await client.SendAsync(req);

                    if (!resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", new { msg = (await resp.Content.ReadAsStringAsync()).FromJson <string>() }));
                    }

                    pointParam.CurTransformators = (await resp.Content.ReadAsStringAsync()).FromJson <ItemInfo[]>();
                    req  = new HttpRequestMessage(HttpMethod.Get, "VoltTransformator");
                    resp = await client.SendAsync(req);

                    if (!resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", new { msg = (await resp.Content.ReadAsStringAsync()).FromJson <string>() }));
                    }

                    pointParam.VoltTransformators = (await resp.Content.ReadAsStringAsync()).FromJson <ItemInfo[]>();
                    return(View(pointParam));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", new { msg = ex.Message }));
            }
        }
コード例 #2
0
        public async Task <IActionResult> AddPoint(AddCalcEnergyPoint point)
        {
            try
            {
                var engPoint = new CalcEnergyPoint
                {
                    Id                    = Guid.NewGuid(),
                    Name                  = point.Name,
                    ConsObjectId          = Guid.Parse(point.ChildOrganizationId),
                    ElectricEnergyMeterId = Guid.Parse(point.EnergyMeterId),
                    VoltTransformatorId   = Guid.Parse(point.VoltTransId),
                    CurTransformatorId    = Guid.Parse(point.CurTransId)
                };

                using (var client = new HttpClient()
                {
                    BaseAddress = new Uri("http://localhost:8050")
                })
                {
                    var req = new HttpRequestMessage(HttpMethod.Post, "CalcEnergyPoint");
                    var js  = engPoint.ToJson();
                    req.Content = new StringContent(engPoint.ToJson(), Encoding.UTF8, "application/json");
                    var resp = await client.SendAsync(req);

                    if (resp.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }

                    return(RedirectToAction("Index", new { msg = (await resp.Content.ReadAsStringAsync()).FromJson <string>() }));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", new { msg = ex.Message }));
            }
        }