async void OnfaviriteClicked(object sender, EventArgs args)
        {
            bool connect = await WebData.CheckConnection(); // проверка подключения

            if (connect == false)
            {
                return;
            }

            ToolbarItem item = (ToolbarItem)sender;

            FavoriteRoom room = Client.isRoomFavoit(Current);

            if (room == null) // добавление
            {
                FavoriteRoom newroom = await new FavRoomService().Add((Current.Clone() as Room).ToFavRoom(Client.CurrentClient.ClientId));
                if (newroom != null)
                {
                    DbService.AddFavoriteRoom(newroom);
                    item.IconImageSource = "@drawable/stared.png";
                }
            }
            else // удаление
            {
                bool deleted = await new FavRoomService().Delete(room.FavoriteRoomId);
                if (deleted)
                {
                    DbService.RemoveFavoriteRoom(room);
                    item.IconImageSource = "@drawable/unstared.png";
                }
            }
        }
Example #2
0
        public async void LoginIn(object sender, EventArgs e)
        {
            if (LoginPage.LoginBox.Text == "" || LoginPage.PasswBox.Text == "")
            {
                DependencyService.Get <IToast>().Show("Введены не все поля");
                return;
            }
            if (isLoading)
            {
                DependencyService.Get <IToast>().Show("Пользователь уже загружается");
                return;
            }

            bool connect = await WebData.CheckConnection();

            if (connect == false)
            {
                return;
            }

            isLoading = true;

            var client = await new ClientService().Authrization(LoginPage.LoginBox.Text, LoginPage.PasswBox.Text);

            if (client != null) // если сервер вернул данные пользователя - загрузить в пользователя
            {
                Client.setClient(Int32.Parse(client["Id"]), client["Name"], client["Login"]);
                DbService.SaveClient(Client.CurrentClient); // сохранили пользователя

                List <Note> clientnotes = await new NoteService().GetClient(Client.CurrentClient.ClientId);
                RemoveDuplicateNote(clientnotes);   // если эта заметка уже загружена как публичная - удалить
                RemoveNonLoadedRoomId(clientnotes); // если заметка связаны с незагруженным помещением - отвязать

                DbService.AddNote(clientnotes);

                DbService.AddFavoriteRoom(await new FavRoomService().Get(Client.CurrentClient.ClientId));

                isLoading = false;
                GetClientPage();
                return;
            }
            else
            {
                await DisplayAlert("Ошибка", "Неверный логин или пароль", "OK");

                isLoading = false;
                return;
            }
        }