private async void RegisterExecute()
        {
            var registerURL = constants.Constants.ServerHostURL + RegisterHttpQuery;

            var json           = JsonConvert.SerializeObject(this.UserRegisterRequestModel);
            var responseResult = await ServerProvider.Post(json, registerURL);

            try
            {
                var token = JsonConvert.DeserializeObject <JwtToken>(responseResult);
                ServiceLocator.Current.GetInstance <UserViewModel>().JwtToken = token;
                this.IsErrorOccured = false;
            }
            catch
            {
                this.IsErrorOccured = true;
            }

            if (this.IsErrorOccured)
            {
                ServiceLocator.Current.GetInstance <MainNavigationViewModel>().ViewType = ViewType.AuthorizationView;
            }
            else
            {
                ServiceLocator.Current.GetInstance <MainNavigationViewModel>().ViewType = ViewType.MainAuthorizedView;
            }
        }
 private async void LogOutExecute()
 {
     var loginURL = constants.Constants.ServerHostURL + LogoutCommand;
     var responseStatus = await ServerProvider.Post(loginURL);
     this.IsUserAuthorized = !(responseStatus == HttpStatusCode.OK ||
         responseStatus == HttpStatusCode.Accepted ||
         responseStatus == HttpStatusCode.Created);
     if (!this.isUserAuthorized)
     {
         ServiceLocator.Current.GetInstance<MainNavigationViewModel>().ViewType = ViewType.AuthorizationView;
     }
 }
示例#3
0
        //private async void GetActiveBabyExecute()
        //{
        //    var device = ServiceLocator.Current.GetInstance<DeviceViewModel>().SelectedDevice;
        //    var deviceId = device.DeviceId;
        //    var devicePoint = new Point()
        //    {
        //        X = 49.993499,
        //        Y = 36.230376
        //    };

        //    var babies = await this.GetAllBabies();

        //    for (int i = this.Babies.Count - 1; i >= 0; i++)
        //    {
        //        this.Babies.RemoveAt(i);
        //    }

        //    foreach (var baby in babies)
        //    {
        //        this.Babies.Add(baby);
        //    }
        //}

        private async Task <List <Baby> > GetActiveBaby(int deviceId, Point location)
        {
            var activeTrashCans = new List <Baby>();
            var httpQuery       = string.Format("{0}{1}{2}", constants.Constants.ServerHostURL, BabyHttp, deviceId);
            var json            = JsonConvert.SerializeObject(location);
            var serverResponse  = await ServerProvider.Post(json, httpQuery);

            try
            {
                var nearestTrashCans = JsonConvert.DeserializeObject <List <Baby> >(serverResponse);
                activeTrashCans = nearestTrashCans;
            }
            catch
            {
                Debug.WriteLine("Get active babies failed.");
            }
            return(activeTrashCans);
        }
示例#4
0
        private async void AddDeviceExecute()
        {
            var devicesHttpUrl = constants.Constants.ServerHostURL + DevicesHttpUrl;

            this.AddingDevice.Owner = ServiceLocator.Current.GetInstance <UserViewModel>().User;
            var json     = JsonConvert.SerializeObject(this.AddingDevice);
            var response = await ServerProvider.Post(json, devicesHttpUrl);

            try
            {
                var deviceFromJson = JsonConvert.DeserializeObject <Device>(response);
                this.Devices.Add(deviceFromJson);
                this.AddingDevice = new Device();
                this.GetEfficiency();
            }
            catch
            {
                Debug.WriteLine("Device adding failed.");
            }
        }
        private async void LoginExecute()
        {
            var loginURL = constants.Constants.ServerHostURL + LoginHttpQuery;
            var json = JsonConvert.SerializeObject(this.AuthModel);
            var responseResult = await ServerProvider.Post(json, loginURL);
            try
            {
                var token = JsonConvert.DeserializeObject<JwtToken>(responseResult);
                ServiceLocator.Current.GetInstance<UserViewModel>().JwtToken = token;
                this.IsUserAuthorized = true;
            }
            catch
            {
                this.IsUserAuthorized = false;
            }

            if (this.isUserAuthorized)
            {
                ServiceLocator.Current.GetInstance<MainNavigationViewModel>().ViewType = ViewType.MainAuthorizedView;
            }
        }