public async Task <ActionResult> Filler(string dateFrom, string dateTo) { string url = _appSettings.ApiUrl + "/Home/Filler"; client.BaseAddress = new Uri(url); HttpResponseMessage responseMessage = await client.GetAsync(url + "?applianceid=" + HttpContext.Session.GetString("ApplianceId") + "&dateFrom=" + dateFrom + "&dateTo=" + dateTo); var responseData = new ResponseData <Dashboard>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <Dashboard> >().Result; ApplianceDTO selectedAppliance = null; if (responseData.Data != null && responseData.Data.ApplianceDTO != null && responseData.Data.ApplianceDTO.Count > 0) { selectedAppliance = responseData.Data.ApplianceDTO.FirstOrDefault(); } return(Json(new { success = true, responseText = responseData.Message, Data = responseData.Data.Events.Select(x => new object[] { x.Timestamp != null && x.Timestamp.HasValue ? x.Timestamp.Value.ToString("dd/MM/yyyy hh:mm:ss tt"): null, x.Account != null ? (x.Account.IsAdmin != null && x.Account.IsAdmin.HasValue ? Configuration.Administrator : x.Account.PhoneNumber) : (selectedAppliance != null ? selectedAppliance.DeviceName + "(" + selectedAppliance.SerialNumber.Substring(selectedAppliance.SerialNumber.Length - 4) + ")" : string.Empty), x.EventType != null ? x.EventType.EventTypeName : string.Empty, x.Message }) })); } return(Json(new { success = false, responseText = responseData.Message })); }
public async Task <IActionResult> Index() { UserViewModels model = new UserViewModels(); if (current_UserID <= 0) { return(RedirectToAction("Signin", "Login")); } else if (current_ApplianceId <= 0) { return(RedirectToAction("Index", "Setup")); } else { ViewBag.ActiveMenu = "user"; string url = _appSettings.ApiUrl + "/User/Index"; client = new HttpClient(); client.BaseAddress = new Uri(url); HttpResponseMessage responseMessage = await client.GetAsync(url + "?applianceId=" + current_ApplianceId + "&AccountId=" + current_UserID); var responseData = new ResponseData <User>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <User> >().Result; if (responseData != null && responseData.Data != null) { ApplianceDTO selectedAppliance = null;; if (responseData.Data.lAppliance != null && responseData.Data.lAppliance.Count > 0) { foreach (var item in responseData.Data.lAppliance) { item.DeviceName += "(" + item.SerialNumber.Substring(item.SerialNumber.Length - 4) + ")"; if (item.Id == current_ApplianceId) { selectedAppliance = item; } } } model.lAccount = responseData.Data.lAccountDTO; model.lAppliance = responseData.Data.lAppliance; model.SelectedAppliance = selectedAppliance; } } } return(View(model)); }
public async Task <ActionResult> UseAddressOfTelit(SetUpViewModels model) { ApplianceDTO applianceDTO = new ApplianceDTO() { AccountId = current_UserID, SerialNumber = model.SerialNumber, Street1 = model.StreetName, Street2 = model.StreetName2, City = model.City, ZipCode = model.Zipcode, StateId = Convert.ToInt64(model.State) }; string url = _appSettings.ApiUrl + "/Setting/UseAddressOfTelit"; client = new HttpClient(); client.BaseAddress = new Uri(url); HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, applianceDTO); var responseData = new ResponseData <ApplianceDTO>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <ApplianceDTO> >().Result; if (responseData.Status == ResponseMessage.Success && responseData.Data != null) { HttpContext.Session.SetString("ApplianceId", $"{responseData.Data.Id}"); return(RedirectToAction("Index", "Home", new { })); } else { ViewBag.MessageError = responseData.Message; } } return(View(model)); }
public async Task <ActionResult> Index(SetUpViewModels model) { if (current_ApplianceId > 0) { ViewBag.BackButton = true; } string url = string.Empty; GetStates().Wait(); model.States = listStates; if (model.UseAddressFromTelit == "UseTelit") { url = _appSettings.ApiUrl + "/Setting/UseAddressOfTelit"; client = new HttpClient(); client.BaseAddress = new Uri(url); } else { url = _appSettings.ApiUrl + "/Setting/SetupThink"; client = new HttpClient(); client.BaseAddress = new Uri(url); } if (!ModelState.IsValid) { return(View(model)); } if (!ValidateSerinumber(model.SerialNumber.Trim())) { ViewBag.MessageError = "SerialNumber is invalid"; return(View(model)); } ApplianceDTO applianceDTO = new ApplianceDTO() { AccountId = current_UserID, SerialNumber = model.SerialNumber.Trim(), Street1 = model.StreetName.Trim(), Street2 = model.StreetName2 != null?model.StreetName2.Trim() : string.Empty, City = model.City.Trim(), ZipCode = model.Zipcode.Trim(), StateId = Convert.ToInt64(model.State) }; HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, applianceDTO); var responseData = new ResponseData <ApplianceDTO>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <ApplianceDTO> >().Result; if (responseData != null && responseData.Data != null) { if (responseData.Data.HasSerialNumber != null && responseData.Data.HasSerialNumber.HasValue && responseData.Data.IsMatching != null && responseData.Data.IsMatching.HasValue) { var hasSerialNumber = responseData.Data.HasSerialNumber.Value; var isMatching = responseData.Data.IsMatching.Value; if (hasSerialNumber) { if (isMatching) { HttpContext.Session.SetString("ApplianceId", $"{responseData.Data.Id}"); return(RedirectToAction("Index", "Home", new { })); } else { ViewBag.ConfirmAddress = true; } } else { ViewBag.MessageError = responseData.Message; } } else { if (responseData.Data != null && responseData.Status == ResponseStatus.Success.ToString()) { HttpContext.Session.SetString("ApplianceId", $"{responseData.Data.Id}"); return(RedirectToAction("Index", "Home", new { })); } else { ViewBag.MessageError = responseData.Message; } } } else { ViewBag.MessageError = responseData.Message; } } return(View(model)); }
public async Task <ResponseData <ApplianceDTO> > SetupThink([FromBody] ApplianceDTO appliance) { try { var response = new ResponseData <ApplianceDTO>(); var things = await TelitApi.ThingList(); bool isMatching = false; bool hasSerialNumber = false; Telit.ThingList.Result thing = new Telit.ThingList.Result(); if (things != null && things.things != null && things.things.success && things.things.@params != null && [email protected] != null && [email protected]() > 0) { foreach (var item in [email protected]) { if (item.key == appliance.SerialNumber) { hasSerialNumber = true; if (item.loc != null && item.loc.addr != null) { isMatching = await calculateAddressAsync(appliance.Street1.Trim(), appliance.City.Trim(), _stateService.GetStateById(appliance.StateId.Value).Name, appliance.ZipCode.Trim(), item.loc.lat, item.loc.lng); thing = item; break; } } } } if (!hasSerialNumber) { response.Message = ResponseMessage.SerialNumberInCorrect; response.Status = ResponseStatus.Success.ToString(); return(response); } if (isMatching) { var isSerialNumberExist = _applianceService.GetApplianceBySerialNumber(appliance.SerialNumber); var thingFind = await TelitApi.ThingFind(thing.key); bool thingIsOn = false; bool thingIsConnected = false; bool thingCellular = false; bool thingPower = false; bool thingWifi = false; bool thingWifiInternet = false; int? thingTrustLevel = null; Telit.ThingFind.Params _params = new Telit.ThingFind.Params(); string applianceEnvironment = string.Empty; if (thingFind != null && thingFind.Things != null && thingFind.Things.success && thingFind.Things.@params != null) { _params = thingFind.Things.@params; } if (_params != null && _params.alarms != null && _params.alarms.env != null && _params.alarms.env.state >= 0 && _params.alarms.env.state < 16) { applianceEnvironment = Convert.ToString(_params.alarms.env.state, 2).PadLeft(4, '0'); var array = !string.IsNullOrEmpty(applianceEnvironment) ? applianceEnvironment.ToArray() : new char[] { }; thingIsOn = Convert.ToBoolean(_params.alarms.on.state); thingIsConnected = _params.connected; thingCellular = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[2].ToString())) : false; thingPower = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[3].ToString())) : false; thingWifi = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[1].ToString())) : false; thingWifiInternet = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[0].ToString())) : false; thingTrustLevel = _params.alarms.trust != null ? (int?)_params.alarms.trust.state : null; } if (isSerialNumberExist == null) { var app = _applianceService.Insert(new Appliance() { AccountId = appliance.AccountId, Cellular = thingCellular, IsConnected = thingIsConnected, City = appliance.City, DeviceName = _params != null && _params.attrs != null && _params.attrs.name != null ? _params.attrs.name.value : string.Empty, OsVersion = "", GeoFenceEnabled = _params.alarms != null && _params.alarms.timerState != null && _params.alarms.timerState.state != 0 ? true : false, Lat = _params.loc != null ? _params.loc.lat : 0, Lon = _params.loc != null ? _params.loc.lng : 0, SerialNumber = appliance.SerialNumber, Power = thingPower, StateId = appliance.StateId, Street1 = appliance.Street1, Street2 = appliance.Street2, TimerEnabled = _params.alarms != null && _params.alarms.timerState != null && _params.alarms.timerState.state != 0 ? true : false, TriggerMile = Convert.ToDecimal(_appSettings.TriggerMiles), Wifi = thingWifi, WiFiInternet = thingWifiInternet, ZipCode = appliance.ZipCode, TrustLevel = thingTrustLevel != null ? thingTrustLevel : 0, IsOn = thingIsOn }); if (app != null) { var accountAppliance = _accountApplianceService.Insert(new AccountAppliance() { AccountId = app.AccountId, AirGapVersion = "", ApplianceId = app.Id, IsQRCodeScaned = false, IsVerified = false }); appliance.Id = app.Id; if (_params.attrs != null && _params.attrs.timerSchedule != null) { var timerScheduleDTO = JsonConvert.DeserializeObject <TimerScheduleFromTelit>(_params.attrs.timerSchedule.value); char[] weekDayArray = timerScheduleDTO.Weekdays.ToCharArray(); char[] weekEndArray = timerScheduleDTO.Weekends.ToCharArray(); string valueWeekDay = string.Empty; string valueWeekEnd = string.Empty; for (int i = 0; i < weekDayArray.Length; i++) { if (weekDayArray[i] == '1') { valueWeekDay += i + 1 + ","; } } for (int i = 0; i < weekEndArray.Length; i++) { if (weekEndArray[i] == '1') { valueWeekEnd += i + 1 + ","; } } if (!string.IsNullOrEmpty(valueWeekDay)) { var timerScheduleOfWeekDays = new TimerSchedule() { TimerTypeId = Configuration.Weekdays, ApplianceId = app.Id, ActiveValues = !string.IsNullOrEmpty(valueWeekDay) ? valueWeekDay.Remove(valueWeekDay.Length - 1) : string.Empty }; _timerScheduleService.Insert(timerScheduleOfWeekDays); } if (!string.IsNullOrEmpty(valueWeekEnd)) { var timerScheduleOfWeekEnd = new TimerSchedule() { TimerTypeId = Configuration.Weekends, ApplianceId = app.Id, ActiveValues = !string.IsNullOrEmpty(valueWeekEnd) ? valueWeekEnd.Remove(valueWeekEnd.Length - 1) : string.Empty }; _timerScheduleService.Insert(timerScheduleOfWeekEnd); } } } } else { if (isSerialNumberExist.AccountId == null) { isSerialNumberExist.AccountId = appliance.AccountId; isSerialNumberExist.Street1 = appliance.Street1; isSerialNumberExist.Street2 = appliance.Street2; isSerialNumberExist.City = appliance.City; isSerialNumberExist.StateId = appliance.StateId; isSerialNumberExist.ZipCode = appliance.ZipCode; isSerialNumberExist.Lat = _params.loc != null ? _params.loc.lat : 0; isSerialNumberExist.Lon = _params.loc != null ? _params.loc.lng : 0; isSerialNumberExist.Cellular = thingCellular; isSerialNumberExist.IsConnected = thingIsConnected; isSerialNumberExist.DeviceName = _params != null && _params.attrs != null && _params.attrs.name != null ? _params.attrs.name.value : string.Empty; isSerialNumberExist.OsVersion = ""; isSerialNumberExist.GeoFenceEnabled = _params.alarms != null && _params.alarms.timerState != null && _params.alarms.timerState.state != 0 ? true : false; isSerialNumberExist.Power = thingPower; isSerialNumberExist.TimerEnabled = _params.alarms != null && _params.alarms.timerState != null && _params.alarms.timerState.state != 0 ? true : false; isSerialNumberExist.Wifi = thingWifi; isSerialNumberExist.WiFiInternet = thingWifiInternet; isSerialNumberExist.ZipCode = appliance.ZipCode; isSerialNumberExist.TrustLevel = thingTrustLevel != null ? thingTrustLevel : 0; isSerialNumberExist.IsOn = thingIsOn; isSerialNumberExist.TriggerMile = Convert.ToDecimal(_appSettings.TriggerMiles); _applianceService.Update(isSerialNumberExist); var accountAppliance = _accountApplianceService.Insert(new AccountAppliance() { AccountId = appliance.AccountId, AirGapVersion = "", ApplianceId = isSerialNumberExist.Id, IsQRCodeScaned = false, IsVerified = false }); appliance.Id = isSerialNumberExist.Id; if (_params.attrs != null && _params.attrs.timerSchedule != null) { var timerScheduleDTO = JsonConvert.DeserializeObject <TimerScheduleFromTelit>(_params.attrs.timerSchedule.value); char[] weekDayArray = timerScheduleDTO.Weekdays.ToCharArray(); char[] weekEndArray = timerScheduleDTO.Weekends.ToCharArray(); string valueWeekDay = string.Empty; string valueWeekEnd = string.Empty; for (int i = 0; i < weekDayArray.Length; i++) { if (weekDayArray[i] == '1') { valueWeekDay += i + 1 + ","; } } for (int i = 0; i < weekEndArray.Length; i++) { if (weekEndArray[i] == '1') { valueWeekEnd += i + 1 + ","; } } var timerSchedule = _timerScheduleService.GetTimerScheduleByApplianceId(appliance.Id); if (timerSchedule != null && timerSchedule.Count > 0) { foreach (var item in timerSchedule) { if (item.TimerTypeId == Configuration.Weekdays) { item.ActiveValues = !string.IsNullOrEmpty(valueWeekDay) ? valueWeekDay.Remove(valueWeekDay.Length - 1) : string.Empty; } if (item.TimerTypeId == Configuration.Weekends) { item.ActiveValues = !string.IsNullOrEmpty(valueWeekEnd) ? valueWeekEnd.Remove(valueWeekEnd.Length - 1) : string.Empty; } _timerScheduleService.Update(item); } } else { if (!string.IsNullOrEmpty(valueWeekDay)) { var timerScheduleOfWeekDays = new TimerSchedule() { TimerTypeId = Configuration.Weekdays, ApplianceId = isSerialNumberExist.Id, ActiveValues = !string.IsNullOrEmpty(valueWeekDay) ? valueWeekDay.Remove(valueWeekDay.Length - 1) : string.Empty }; _timerScheduleService.Insert(timerScheduleOfWeekDays); } if (!string.IsNullOrEmpty(valueWeekEnd)) { var timerScheduleOfWeekEnd = new TimerSchedule() { TimerTypeId = Configuration.Weekends, ApplianceId = isSerialNumberExist.Id, ActiveValues = !string.IsNullOrEmpty(valueWeekEnd) ? valueWeekEnd.Remove(valueWeekEnd.Length - 1) : string.Empty }; _timerScheduleService.Insert(timerScheduleOfWeekEnd); } } } } else { response.Status = ResponseStatus.Success.ToString(); response.Message = ResponseMessage.SerialNumberIsExist; return(response); } } } appliance.IsMatching = isMatching; appliance.HasSerialNumber = hasSerialNumber; response.Data = appliance; response.Status = ResponseStatus.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <ApplianceDTO>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }
public async Task <ResponseData <AirGapSetting> > UseAddressOfTelit([FromBody] ApplianceDTO appliance) { try { InitialData(appliance.AccountId.ToString(), appliance.Id.ToString()); var response = new ResponseData <AirGapSetting>(); var app = _applianceService.GetApplianceById(appliance.Id); var things = await TelitApi.ThingList(); Telit.ThingList.Result thing = new Telit.ThingList.Result(); if (things != null && things.things != null && things.things.success && things.things.@params != null && [email protected] != null && [email protected]() > 0) { foreach (var item in [email protected]) { if (item.key == app.SerialNumber) { app.Street1 = item.loc != null && item.loc.addr != null ? item.loc.addr.streetNumber + " " + item.loc.addr.street : string.Empty; app.StateId = item.loc != null && item.loc.addr != null && _stateService.GetStateByNameOrCode(item.loc.addr.state) != null ? (long?)_stateService.GetStateByNameOrCode(item.loc.addr.state).Id : null; app.Street2 = string.Empty; app.City = item.loc != null && item.loc.addr != null ? item.loc.addr.city : string.Empty; app.ZipCode = item.loc != null && item.loc.addr != null ? item.loc.addr.zipCode : null; app.Lat = item.loc != null ? item.loc.lat : 0; app.Lon = item.loc != null ? item.loc.lng : 0; _applianceService.Update(app); break; } } } foreach (var account in ListAccount) { if (account.Id == appliance.AccountId) { continue; } foreach (var noti in listNotificationPreference) { if (noti.AccountId == account.Id) { switch (noti.EventTypeId) { case Constant.EventType.NetWorkStatusChange: account.NetWorkStatusChange = true; break; case Constant.EventType.HomePowerLoss: account.HomePowerLoss = true; break; case Constant.EventType.ISPOutage: account.ISPOutage = true; break; } } } } ListAccount = ListAccount.Where(x => x.Id != appliance.AccountId).ToList(); var airGapSetting = new AirGapSetting() { ListApplianceDTO = listAccountAppliance, ListAccountDTO = ListAccount, TimerScheduleDTO = listTimerSchedule }; response.Data = airGapSetting; response.Status = ResponseStatus.Success.ToString(); response.Message = ResponseMessage.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <AirGapSetting>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }
public async Task <ResponseData <AirGapSetting> > CompareAddressFromTelit([FromBody] ApplianceDTO appliance) { try { InitialData(appliance.AccountId.ToString(), appliance.Id.ToString()); var response = new ResponseData <AirGapSetting>(); var app = _applianceService.GetApplianceById(appliance.Id); var things = await TelitApi.ThingList(); bool isMatching = false; Telit.ThingList.Result thing = new Telit.ThingList.Result(); if (things != null && things.things != null && things.things.success && things.things.@params != null && [email protected] != null && [email protected]() > 0) { foreach (var item in [email protected]) { if (item.key == app.SerialNumber) { if (item.loc != null && item.loc.addr != null) { isMatching = await calculateAddressAsync(appliance.Street1.Trim(), appliance.City.Trim(), _stateService.GetStateById(appliance.StateId.Value).Name, appliance.ZipCode.Trim(), item.loc.lat, item.loc.lng); thing = item; break; } } } } if (isMatching) { app.Street1 = appliance.Street1; app.Street2 = appliance.Street2; app.StateId = appliance.StateId; app.City = appliance.City; app.ZipCode = appliance.ZipCode; var locationElement = await GetLatLngByAddressAsync(appliance.Street1.Trim(), appliance.City.Trim(), _stateService.GetStateById(appliance.StateId.Value).Name, appliance.ZipCode.Trim()); app.City = appliance.City; app.Lat = Convert.ToDouble(locationElement.Element("lat").Value); app.Lon = Convert.ToDouble(locationElement.Element("lng").Value); _applianceService.Update(app); } foreach (var account in ListAccount) { if (account.Id == appliance.AccountId) { continue; } foreach (var noti in listNotificationPreference) { if (noti.AccountId == account.Id) { switch (noti.EventTypeId) { case Constant.EventType.NetWorkStatusChange: account.NetWorkStatusChange = true; break; case Constant.EventType.HomePowerLoss: account.HomePowerLoss = true; break; case Constant.EventType.ISPOutage: account.ISPOutage = true; break; } } } } ListAccount = ListAccount.Where(x => x.Id != appliance.AccountId).ToList(); var airGapSetting = new AirGapSetting() { ListApplianceDTO = listAccountAppliance, ListAccountDTO = ListAccount, TimerScheduleDTO = listTimerSchedule, IsMatching = isMatching }; response.Data = airGapSetting; response.Status = ResponseStatus.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <AirGapSetting>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }
public async Task <ActionResult> Index(AirViewModels model) { GetStates().Wait(); model.States = listStates; string url = string.Empty; long applianceId = 0; if (current_ApplianceId > 0) { applianceId = current_ApplianceId; } if (model.UseAddressFromTelit == "UseTelit") { url = _appSettings.ApiUrl + "/Air/UseAddressOfTelit"; client = new HttpClient(); client.BaseAddress = new Uri(url); } else { url = _appSettings.ApiUrl + "/Air/CompareAddressFromTelit"; client = new HttpClient(); client.BaseAddress = new Uri(url); } ApplianceDTO applianceDTO = new ApplianceDTO() { AccountId = current_UserID, Street1 = model.StreetName, Street2 = model.StreetName2, City = model.City, ZipCode = model.Zipcode, StateId = Convert.ToInt64(model.State), Id = current_ApplianceId }; HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, applianceDTO); var responseData = new ResponseData <AirGapSetting>(); if (responseMessage.IsSuccessStatusCode) { responseData = responseMessage.Content.ReadAsAsync <ResponseData <AirGapSetting> >().Result; if (responseData != null && responseData.Data != null) { if (responseData.Data.ListApplianceDTO != null && responseData.Data.ListApplianceDTO.Count > 0) { foreach (var item in responseData.Data.ListApplianceDTO) { item.DeviceName += "(" + item.SerialNumber.Substring(item.SerialNumber.Length - 4) + ")"; if (item.Id == applianceId) { model.SelectedAppliance = item; model.StreetName = item.Street1; model.StreetName2 = item.Street2; model.State = item.StateId.ToString(); model.City = item.City; model.Zipcode = item.ZipCode; } } model.lAppliance = responseData.Data.ListApplianceDTO; } if (responseData.Data.TimerScheduleDTO != null && responseData.Data.TimerScheduleDTO.Count > 0) { Dictionary <long, string[]> lTimer = new Dictionary <long, string[]>(); foreach (var item in responseData.Data.TimerScheduleDTO) { if (!string.IsNullOrEmpty(item.ActiveValues)) { if (item.ActiveValues.IndexOf(',') != -1) { lTimer.Add(item.TimerTypeId.Value, item.ActiveValues.Split(',')); } else { lTimer.Add(item.TimerTypeId.Value, new string[] { item.ActiveValues }); } } } model.lTimerSchedule = lTimer; } if (responseData.Data.States != null && responseData.Data.States.Count() > 0) { var listStates = new List <SelectListItem>(); foreach (var item in responseData.Data.States) { listStates.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString(), Selected = item.Id == model.SelectedAppliance.StateId ? true : false }); } model.States = listStates; } if (responseData.Data.ListAccountDTO != null && responseData.Data.ListAccountDTO.Count() > 0) { model.lAccountDTO = responseData.Data.ListAccountDTO; } if (responseData.Data.IsMatching != null && responseData.Data.IsMatching.HasValue) { var isMatching = responseData.Data.IsMatching.Value; if (isMatching) { return(RedirectToAction("Index", "Air", new { })); } else { ViewBag.ConfirmAddress = true; } } else { if (responseData.Data != null && responseData.Status == ResponseStatus.Success.ToString()) { return(RedirectToAction("Index", "Air", new { })); } else { ViewBag.MessageError = responseData.Message; } } } else { ViewBag.MessageError = responseData.Message; } } return(View(model)); }
public async Task <ResponseData <Dashboard> > Index(string accountid, string applianceid) { try { var accountAppliance = _accountApplianceService.GetAccountApplianceByAccountId(Convert.ToInt64(accountid)); var _event = _eventService.GetEventByApplianceId(Convert.ToInt64(applianceid)); var lAccounts = _accountApplianceService.GetAccountByApplianceId(Convert.ToInt64(applianceid), true); List <AccountApplianceDTO> accountApplianceDTO = new List <AccountApplianceDTO>(); if (accountAppliance != null && accountAppliance.Count > 0) { foreach (var item in accountAppliance) { accountApplianceDTO.Add(new AccountApplianceDTO(item)); } } lAccounts = lAccounts.Where(x => x.Id != Convert.ToInt64(accountid)).ToList(); if (!TelitApi.IsConnected) { TelitApi.CheckIOTConnection().Wait(); } var appliance = _applianceService.GetApplianceById(Convert.ToInt64(applianceid)); var thingFind = await TelitApi.ThingFind(appliance.SerialNumber); Telit.ThingFind.Params _params = new Telit.ThingFind.Params(); string applianceEnvironment = string.Empty; ApplianceDTO applianceDTO = new ApplianceDTO(); if (thingFind != null && thingFind.Things != null && thingFind.Things.success && thingFind.Things.@params != null) { _params = thingFind.Things.@params; } if (_params != null && _params.alarms != null && _params.alarms.env != null && _params.alarms.env.state >= 0 && _params.alarms.env.state < 16) { applianceEnvironment = Convert.ToString(_params.alarms.env.state, 2).PadLeft(4, '0'); var array = !string.IsNullOrEmpty(applianceEnvironment) ? applianceEnvironment.ToArray() : new char[] { }; applianceDTO.Cellular = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[2].ToString())) : false; applianceDTO.Power = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[3].ToString())) : false; applianceDTO.Wifi = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[1].ToString())) : false; applianceDTO.WiFiInternet = array.Length == 4 ? Convert.ToBoolean(Convert.ToInt16(array[0].ToString())) : false; } applianceDTO.TimerEnabled = _params != null && _params.alarms != null && _params.alarms.timerState != null ? (Convert.ToInt64(_params.alarms.timerState.state) != 0 ? true : false) : false; applianceDTO.DeviceName = _params != null && _params.attrs != null && _params.attrs.name != null ? _params.attrs.name.value : appliance.DeviceName; applianceDTO.SerialNumber = appliance.SerialNumber; applianceDTO.TriggerMile = appliance.TriggerMile; applianceDTO.Id = appliance.Id; applianceDTO.IsOn = _params != null && _params.alarms != null && _params.alarms.on != null?CheckApplianceIsOn(Convert.ToInt16(_params.alarms.on.state)) : false; applianceDTO.IsConnected = _params.connected; applianceDTO.Lat = appliance.Lat; applianceDTO.Lon = appliance.Lon; applianceDTO.GeoFenceEnabled = appliance.GeoFenceEnabled; applianceDTO.Status = appliance.Status; if (_params != null && _params.alarms != null) { applianceDTO.TrustLevel = _params.alarms.trust != null ? (int?)_params.alarms.trust.state : 3; } var plans = _stripeService.GetPlans(); var subscriptionId = _accountApplianceService.GetAccountApplianceByAccountIdAndApplianceId(Convert.ToInt64(accountid), Convert.ToInt64(applianceid)); DateTime?expireDate = null; bool cancelAtEnd = false; if (subscriptionId != null && !string.IsNullOrEmpty(subscriptionId.SubscriptionId)) { var stripe = _stripeService.RetrieveSubscription(subscriptionId.SubscriptionId); // current period end expireDate = stripe.CurrentPeriodEnd; cancelAtEnd = stripe.CancelAtPeriodEnd; } var dashboard = new Dashboard() { AccountAppliance = accountApplianceDTO, Events = _event, ListAccountsDTO = lAccounts, IsIOTConnected = TelitApi.IsConnected, Plans = plans, AppDTO = applianceDTO, ExpireDate = expireDate, CancelAtEnd = cancelAtEnd, IsApplianceConnected = applianceDTO.IsConnected.Value }; var response = new ResponseData <Dashboard>(); response.Data = dashboard; response.Message = ResponseMessage.Success; response.Status = ResponseStatus.Success.ToString(); return(response); } catch (Exception ex) { var response = new ResponseData <Dashboard>(); response.Message = ex.Message; response.Status = ResponseStatus.Error.ToString(); return(response); } }