Beispiel #1
0
        public ResponseData <AirGapSetting> deleteSerialNumber(string applianceId, string accountId)
        {
            try
            {
                _accountApplianceService.Remote(Convert.ToInt64(applianceId));

                var appliance = _applianceService.GetApplianceById(Convert.ToInt64(applianceId));
                appliance.AccountId = null;
                appliance.Status    = false;
                _applianceService.Update(appliance);
                var listAccountAppliance = _accountApplianceService.GetApplianceByAccountId(Convert.ToInt64(accountId));
                var airGapSetting        = new AirGapSetting()
                {
                    ListApplianceDTO = listAccountAppliance
                };

                _notificationPreferenceService.RemoveNotificationPreferenceByApplianceId(Convert.ToInt64(applianceId));
                _notificationService.RemoveNotificationByApplianceId(Convert.ToInt64(applianceId));
                _eventService.RemoveEventByApplianceId(Convert.ToInt64(applianceId));

                var response = new ResponseData <AirGapSetting>();
                response.Data    = airGapSetting;
                response.Message = ResponseMessage.Success;
                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);
            }
        }
Beispiel #2
0
        public async Task <ResponseData <bool> > UpdateAppliance(string subscriptionId, string update)
        {
            try
            {
                var accountAppliance = _accountApplianceService.GetAccountApplianceBySubScription(subscriptionId);
                var appliance        = _applianceService.GetApplianceById(accountAppliance.FirstOrDefault().ApplianceId.Value);
                var response         = new ResponseData <bool>();
                var thingFind        = await TelitApi.ThingFind(appliance.SerialNumber);

                Telit.ThingFind.Params _params = new Telit.ThingFind.Params();
                _params = thingFind.Things.@params;

                var success = await TelitApi.UpdateStatusOfAppliance(_params.iccid, update == Configuration.Disable?true : false);

                if (success)
                {
                    appliance.Status = update == Configuration.Enable ? true : false;
                    _applianceService.Update(appliance);
                    if (!appliance.Status.Value)
                    {
                        accountAppliance.FirstOrDefault().SubscriptionId = null;
                        _accountApplianceService.Update(accountAppliance.FirstOrDefault());
                    }

                    response.Message = ResponseMessage.Success;
                }
                else
                {
                    response.Message = ResponseMessage.Error;
                }
                response.Status = ResponseStatus.Success.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                var response = new ResponseData <bool>();
                response.Message = ex.Message;
                response.Status  = ResponseStatus.Error.ToString();
                return(response);
            }
        }
Beispiel #3
0
        public ResponseData <AccountDTO> UpdateUser(string applianceId, string currenctUserId, string accountId, string firstName, string lastName, string isVerified)
        {
            try
            {
                var account = _accountService.GetAccountById(Convert.ToInt64(accountId));
                account.FirstName = firstName;
                account.LastName  = lastName;
                _accountService.Update(account);
                bool temp             = Convert.ToBoolean(isVerified);
                var  accountAppliance = _accountApplianceService.GetAccountApplianceByAccountIdAndApplianceId(Convert.ToInt64(accountId), Convert.ToInt64(applianceId));
                var  appliance        = _applianceService.GetApplianceById(Convert.ToInt64(applianceId));
                if (temp != accountAppliance.IsVerified)
                {
                    accountAppliance.IsVerified = temp;
                    var _event = new Event()
                    {
                        AccountId   = Convert.ToInt64(currenctUserId),
                        ApplianceId = Convert.ToInt64(applianceId),
                        EventTypeId = Constant.EventType.AccountVerifyForAppliance,
                        Timestamp   = DateTime.UtcNow,
                        Message     = appliance.DeviceName + "(" + appliance.SerialNumber.Substring(appliance.SerialNumber.Length - 4) + ")" + ": " + (temp ? "Add " + account.PhoneNumber : "Remove " + account.PhoneNumber)
                    };

                    _eventService.Insert(_event);

                    if (accountAppliance.PhoneType == Configuration.Android)
                    {
                        var pushGcmotification = new AndroidGcmPushNotification(_appSettings);
                        pushGcmotification.InitPushNotification(accountAppliance.DeviceToken, _event.Message);
                    }
                    else
                    {
                        var applePush = new ApplePushNotificationService(_appSettings);
                        applePush.PushMessage(_event.Message, accountAppliance.DeviceToken, 0, null).Wait();
                    }

                    var notification = new Notification()
                    {
                        AccountId   = accountAppliance.AccountId,
                        ApplianceId = accountAppliance.ApplianceId,
                        EventId     = _event.Id,
                        Timestamp   = DateTime.UtcNow
                    };

                    _notificationService.Insert(notification);
                }

                _accountApplianceService.Update(accountAppliance);
                var response = new ResponseData <AccountDTO>();
                response.Message = ResponseMessage.Success;
                response.Status  = ResponseStatus.Success.ToString();
                return(response);
            }
            catch (Exception ex)
            {
                var response = new ResponseData <AccountDTO>();
                response.Message = ex.Message;
                response.Status  = ResponseStatus.Error.ToString();
                return(response);
            }
        }
Beispiel #4
0
        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);
            }
        }