public async Task<LocalizationResponse> Localize(Device device) { using (var httpClient = new HttpClient()) { var request = new LocalizationRequest(device); var json = Json.Encode(request); var content = new StringContent(json); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var httpResponse = await httpClient.PostAsync(string.Concat(GlobalSettings.Current.ObserverWebApiBaseUrl, "/localization/localize"), content); return Json.Decode<LocalizationResponse>(await httpResponse.Content.ReadAsStringAsync()); } }
public async Task<ActionResult> Index(LocalizationViewModel model) { if (!ModelState.IsValid) { var rooms = Session["Rooms"] as IList<Room>; if (rooms == null) { rooms = new List<Room>(); } model.Departments = rooms.Select(x => x.Department).DistinctBy(x => x.Name); return View(model); } var device = new Device { Name = model.DeviceName, IpAddress = model.IpAddress, MacAddress = model.MacAddress ?? "fake", Location = new Location { Name = model.SelectedLocationName }, Room = new Room { Name = model.SelectedRoomName, Department = new Department { Name = model.SelectedDepartmentName } } }; var localizationService = new LocalizationService(); var response = await localizationService.Localize(device); Session["localization_response"] = response; return RedirectToAction("Index", "Dashboard"); }