private void CreateCardProcess()
        {
            InvokeInBackground(async() =>
            {
                #region uploading photos
                bool photos_exist   = true;
                var documents       = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var cards_cache_dir = Path.Combine(documents, Constants.CardsPersonalImages);
                if (!Directory.Exists(cards_cache_dir))
                {
                    photos_exist = false;
                }
                else
                {
                    photos_exist       = false;
                    string[] filenames = Directory.GetFiles(cards_cache_dir);
                    foreach (var img in filenames)
                    {
                        photos_exist = true;
                        break;
                    }
                }
                var documentsLogo  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var logo_cache_dir = Path.Combine(documentsLogo, Constants.CardsLogo);
                if (Directory.Exists(logo_cache_dir))
                {
                    string[] filenames = Directory.GetFiles(logo_cache_dir);
                    foreach (var img in filenames)
                    {
                        photos_exist = true;
                        break;
                    }
                }
                int?logo_id = null;
                List <int> attachments_ids_list = new List <int>();
                if (photos_exist)
                {
                    InvokeOnMainThread(() =>
                    {
                        mainTextTV.Text = "Фотографии выгружаются";
                    });
                    AttachmentsUploadModel res_photos = null;
                    try
                    {
                        res_photos = await attachments.UploadIOS(databaseMethods.GetAccessJwt(), UDID);
                    }
                    catch
                    {
                        if (!methods.IsConnected())
                        {
                            InvokeOnMainThread(() =>
                            {
                                NoConnectionViewController.view_controller_name = GetType().Name;
                                this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                return;
                            });
                        }
                        return;
                    }
                    if (res_photos != null)
                    {
                        //var deserialized_logo = JsonConvert.DeserializeObject<CompanyLogoModel>(res_photos);
                        logo_id = res_photos.logo_id;
                        attachments_ids_list = res_photos.attachments_ids;
                        if (logo_id == Constants.image_upload_status_code401)
                        {
                            InvokeOnMainThread(() =>
                            {
                                ShowSeveralDevicesRestriction();
                                return;
                            });
                            return;
                        }
                    }
                }
                #endregion uploading photos
                InvokeOnMainThread(() =>
                {
                    mainTextTV.Text = "Визитка синхронизируется";
                });
                string company_card_res = "";
                if (!CompanyDataViewControllerNew.company_null)
                {
                    try
                    {
                        if (logo_id != null)
                        {
                            company_card_res = await companies.CreateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard(), logo_id);
                        }
                        else
                        {
                            company_card_res = await companies.CreateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard());
                        }
                        if (company_card_res == Constants.image_upload_status_code401.ToString())
                        {
                            InvokeOnMainThread(() =>
                            {
                                ShowSeveralDevicesRestriction();
                                return;
                            });
                            return;
                        }
                    }
                    catch
                    {
                        if (!methods.IsConnected())
                        {
                            InvokeOnMainThread(() =>
                            {
                                NoConnectionViewController.view_controller_name = GetType().Name;
                                this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                return;
                            });
                        }
                        return;
                    }
                }
                try
                {
                    string user_card_res;
                    if (!CompanyDataViewControllerNew.company_null)
                    {
                        var deserialized = JsonConvert.DeserializeObject <CompanyCardResponse>(company_card_res);
                        try
                        {
                            user_card_res = await cards.CreatePersonalCard(databaseMethods.GetAccessJwt(),
                                                                           databaseMethods.GetDataFromUsersCard(deserialized.id,
                                                                                                                databaseMethods.GetLastSubscription(),
                                                                                                                EditCompanyDataViewControllerNew.position,
                                                                                                                EditCompanyDataViewControllerNew.corporativePhone),
                                                                           attachments_ids_list,
                                                                           UDID);
                        }
                        catch
                        {
                            if (!methods.IsConnected())
                            {
                                InvokeOnMainThread(() =>
                                {
                                    NoConnectionViewController.view_controller_name = GetType().Name;
                                    this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                    return;
                                });
                            }
                            return;
                        }
                    }
                    else
                    {
                        try
                        {
                            user_card_res = await cards.CreatePersonalCard(databaseMethods.GetAccessJwt(),
                                                                           databaseMethods.GetDataFromUsersCard(null,
                                                                                                                databaseMethods.GetLastSubscription(),
                                                                                                                EditCompanyDataViewControllerNew.position,
                                                                                                                EditCompanyDataViewControllerNew.corporativePhone),
                                                                           attachments_ids_list,
                                                                           UDID);
                        }
                        catch
                        {
                            if (!methods.IsConnected())
                            {
                                InvokeOnMainThread(() =>
                                {
                                    NoConnectionViewController.view_controller_name = GetType().Name;
                                    this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                    return;
                                });
                            }
                            return;
                        }
                    }
                    if (user_card_res == Constants.image_upload_status_code401.ToString())
                    {
                        InvokeOnMainThread(() =>
                        {
                            ShowSeveralDevicesRestriction();
                            return;
                        });
                        return;
                    }
                    try
                    {
                        var users_card_des = JsonConvert.DeserializeObject <CompanyCardResponse>(user_card_res);
                        personal_card_id   = users_card_des.id;
                        QRViewController.just_created_card_name = databaseMethods.get_card_name();
                        clearAll();

                        CardDoneViewController.card_id = personal_card_id;
                        InvokeOnMainThread(() =>
                        {
                            //CardDoneViewController.variant_displaying = 1;

                            databaseMethods.InsertLastCloudSync(DateTime.Now);
                            this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(CardDoneViewController)), true);
                        });
                    }
                    catch
                    {
                        InvokeOnMainThread(() =>
                        {
                            var deserialized_error = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(user_card_res);
                            //if (deserialized_error[0].message == Constants.alreadyDone)
                            UIAlertView alert = new UIAlertView()
                            {
                                Title   = "Ошибка",
                                Message = deserialized_error[0].message
                            };
                            if (deserialized_error[0].code == Constants.alreadyDone)
                            {
                                alert.Message = "Визитка с таким названием существует. ";
                            }
                            alert.AddButton("OK");
                            alert.Show();
                            pop();
                        });
                    }
                }
                catch
                {
                    InvokeOnMainThread(() =>
                    {
                        var deserialized_error = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(company_card_res);
                        if (deserialized_error != null)
                        {
                            UIAlertView alert = new UIAlertView()
                            {
                                Title   = "Ошибка",
                                Message = deserialized_error[0].message
                            };
                            alert.AddButton("OK");
                            alert.Show();
                            pop();
                        }
                        else
                        {
                            this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(CardDoneViewController)), true);
                        }
                    });
                }
            });
        }
        private async Task <bool> CreateCardProcess()
        {
            #region uploading photos
            bool photosExist    = true;
            var  personalImages = _nativeMethods.GetPersonalImages();
            if (personalImages.Result == null)
            {
                photosExist = false;
            }
            else
            {
                photosExist = true;
            }
            var documentsLogo = _nativeMethods.GetDocumentsLogo();
            if (documentsLogo.Result != null)
            {
                photosExist = true;
            }
            int?       logoId             = null;
            List <int> attachmentsIdsList = new List <int>();
            if (photosExist)
            {
                _mainTextTv.Text = TranslationHelper.GetString("photosAreBeingUploaded", _ci);
                AttachmentsUploadModel resPhotos = null;
                try
                {
                    resPhotos = await _attachments.UploadAndroid(_databaseMethods.GetAccessJwt(), clientName, personalImages.Result, documentsLogo.Result);
                }
                catch (Exception ex)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }
                if (resPhotos == null)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }

                if (resPhotos != null)
                {
                    //var deserialized_logo = JsonConvert.DeserializeObject<CompanyLogoModel>(res_photos);
                    logoId             = resPhotos.logo_id;
                    attachmentsIdsList = resPhotos.attachments_ids;
                    if (logoId == Constants.image_upload_status_code401)
                    {
                        ShowSeveralDevicesRestriction();
                        return(false);
                    }
                }
            }
            #endregion uploading photos
            _mainTextTv.Text = TranslationHelper.GetString("cardIsSynchronizing", _ci);
            string companyCardRes = "";
            if (!CompanyDataActivity.CompanyNull)
            {
                try
                {
                    if (logoId != null)
                    {
                        companyCardRes = await _companies.CreateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard(), logoId);
                    }
                    else
                    {
                        companyCardRes = await _companies.CreateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard());
                    }
                }
                catch (Exception ex)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }
                if (String.IsNullOrEmpty(companyCardRes))
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }
                if (companyCardRes == Constants.image_upload_status_code401.ToString())
                {
                    ShowSeveralDevicesRestriction();
                    return(false);
                }
            }
            try
            {
                string userCardRes = null;
                try
                {
                    if (!CompanyDataActivity.CompanyNull)
                    {
                        var deserialized = JsonConvert.DeserializeObject <CompanyCardResponse>(companyCardRes);
                        userCardRes = await _cards.CreatePersonalCard(_databaseMethods.GetAccessJwt(),
                                                                      _databaseMethods.GetDataFromUsersCard(deserialized.id,
                                                                                                            _databaseMethods.GetLastSubscription(),
                                                                                                            EditCompanyDataActivity.Position,
                                                                                                            EditCompanyDataActivity.CorporativePhone),
                                                                      attachmentsIdsList,
                                                                      clientName);
                    }
                    else
                    {
                        userCardRes = await _cards.CreatePersonalCard(_databaseMethods.GetAccessJwt(),
                                                                      _databaseMethods.GetDataFromUsersCard(null,
                                                                                                            _databaseMethods.GetLastSubscription(),
                                                                                                            EditCompanyDataActivity.Position,
                                                                                                            EditCompanyDataActivity.CorporativePhone),
                                                                      attachmentsIdsList,
                                                                      clientName);
                    }
                }
                catch (Exception ex)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }
                if (String.IsNullOrEmpty(userCardRes))
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return(false);
                    }
                }
                if (userCardRes == Constants.image_upload_status_code401.ToString())
                {
                    ShowSeveralDevicesRestriction();
                    return(false);
                }
                try
                {
                    var usersCardDes = JsonConvert.DeserializeObject <CompanyCardResponse>(userCardRes);
                    PersonalCardId = usersCardDes.id;
                    QrActivity.JustCreatedCardName = _databaseMethods.get_card_name();
                    _nativeMethods.ClearAll();

                    CardDoneActivity.CardId = PersonalCardId;
                    //CardDoneViewController.variant_displaying = 1;

                    _databaseMethods.InsertLastCloudSync(DateTime.Now);
                    ClearAll();
                    StartActivity(typeof(CardDoneActivity));
                }
                catch
                {
                    try
                    {
                        var deserializedError = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(userCardRes);
                        //if (deserialized_error[0].message == Constants.alreadyDone)
                        if (deserializedError[0].code == Constants.alreadyDone)
                        {
                            Toast.MakeText(this, TranslationHelper.GetString("cardWithThisNameExists", _ci), ToastLength.Long).Show();
                        }
                    }
                    catch { }
                    Pop();
                }
            }
            catch (Exception ex)
            {
                try
                {
                    var deserializedError = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(companyCardRes);
                    if (deserializedError != null)
                    {
                        Toast.MakeText(this, deserializedError[0].message, ToastLength.Long).Show();
                        Pop();
                    }
                    else
                    {
                        Toast.MakeText(this, TranslationHelper.GetString("tryOnceMore", _ci), ToastLength.Long).Show();
                        OnBackPressed();
                    }
                }
                catch { }
                //StartActivity(typeof(CardDoneActivity));
            }
            return(true);
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            UDID = UIDevice.CurrentDevice.IdentifierForVendor.ToString();
            InitElements();
            if (!methods.IsConnected())
            {
                NoConnectionViewController.view_controller_name = GetType().Name;
                this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                return;
            }
            InvokeInBackground(async() =>
            {
                if (!EditCompanyDataViewControllerNew.changedCompanyData)
                {
                    goto DoPersonalStuff;
                }
                #region uploading photos
                bool photos_exist   = true;
                var documents       = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var cards_cache_dir = Path.Combine(documents, Constants.CardsPersonalImages);
                if (!Directory.Exists(cards_cache_dir))
                {
                    photos_exist = false;
                }
                else
                {
                    photos_exist       = false;
                    string[] filenames = Directory.GetFiles(cards_cache_dir);
                    foreach (var img in filenames)
                    {
                        photos_exist = true;
                        break;
                    }
                }
                var documentsLogo  = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var logo_cache_dir = Path.Combine(documentsLogo, Constants.CardsLogo);
                if (Directory.Exists(logo_cache_dir))
                {
                    string[] filenames = Directory.GetFiles(logo_cache_dir);
                    foreach (var img in filenames)
                    {
                        photos_exist = true;
                        break;
                    }
                }
                int?logo_id = null;
                if (photos_exist)
                {
                    InvokeOnMainThread(() =>
                    {
                        mainTextTV.Text = "Фотографии выгружаются";
                    });
                    AttachmentsUploadModel res_photos = null;
                    try
                    {
                        res_photos = await attachments.UploadIOS(databaseMethods.GetAccessJwt(), UDID);
                    }
                    catch
                    {
                        if (!methods.IsConnected())
                        {
                            InvokeOnMainThread(() =>
                            {
                                NoConnectionViewController.view_controller_name = GetType().Name;
                                this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                                return;
                            });
                        }
                        return;
                    }
                    if (res_photos != null)
                    {
                        //var deserialized_logo = JsonConvert.DeserializeObject<CompanyLogoModel>(res_photos);
                        //logo_id = deserialized_logo.id;
                        logo_id = res_photos.logo_id;
                        if (logo_id == Constants.image_upload_status_code401)
                        {
                            InvokeOnMainThread(() =>
                            {
                                ShowSeveralDevicesRestriction();
                                return;
                            });
                            return;
                        }
                    }
                }
                else
                {
                    logo_id = EditCompanyDataViewControllerNew.logo_id;
                }

                #endregion uploading photos
                InvokeOnMainThread(() =>
                {
                    mainTextTV.Text = "Визитка синхронизируется";
                });
                string res_company = null;
                try
                {
                    if (logo_id != null)
                    {
                        if (EditPersonalProcessViewController.company_id != null)
                        {
                            res_company = await companies.UpdateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard(), EditPersonalProcessViewController.company_id, logo_id);
                        }
                        else
                        {
                            res_company = await companies.CreateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard(), logo_id);
                        }
                    }
                    else
                    {
                        if (EditPersonalProcessViewController.company_id != null)
                        {
                            res_company = await companies.UpdateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard(), EditPersonalProcessViewController.company_id);
                        }
                        else
                        {
                            res_company = await companies.CreateCompanyCard(databaseMethods.GetAccessJwt(), UDID, databaseMethods.GetDataFromCompanyCard());
                        }
                    }
                }
                catch
                {
                    if (!methods.IsConnected())
                    {
                        InvokeOnMainThread(() =>
                        {
                            NoConnectionViewController.view_controller_name = GetType().Name;
                            this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                            return;
                        });
                    }
                    return;
                }
                if (res_company == Constants.image_upload_status_code401.ToString())
                {
                    InvokeOnMainThread(() =>
                    {
                        ShowSeveralDevicesRestriction();
                        return;
                    });
                    return;
                }
                try
                {
                    var deserialized = JsonConvert.DeserializeObject <CompanyCardResponse>(res_company);
                }
                catch
                {
                    databaseMethods.ClearCompanyCardTable();
                    InvokeOnMainThread(() =>
                    {
                        var deserialized_error = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(res_company);
                        UIAlertView alert      = new UIAlertView()
                        {
                            Title   = "Ошибка в данных компании",
                            Message = deserialized_error[0].message
                        };
                        alert.AddButton("OK");
                        alert.Show();
                        this.NavigationController.PopViewController(true);
                    });
                }

                if (res_company.Contains("id") && res_company.Length < 12)
                {
                    EditPersonalProcessViewController.company_id = Convert.ToInt32(JsonConvert.DeserializeObject <CompanyCardResponse>(res_company).id);
                }
                DoPersonalStuff:
                //caching card to db
                databaseMethods.InsertUsersCard(
                    EditPersonalDataViewControllerNew.myName,
                    EditPersonalDataViewControllerNew.mySurname,
                    EditPersonalDataViewControllerNew.myMiddlename,
                    EditPersonalDataViewControllerNew.myPhone,
                    EditPersonalDataViewControllerNew.myEmail,
                    EditPersonalDataViewControllerNew.myHomePhone,
                    EditPersonalDataViewControllerNew.mySite,
                    EditPersonalDataViewControllerNew.myDegree,
                    EditPersonalDataViewControllerNew.myCardName,
                    EditPersonalDataViewControllerNew.myBirthDate,
                    HomeAddressViewController.myCountry,
                    HomeAddressViewController.myRegion,
                    HomeAddressViewController.myCity,
                    HomeAddressViewController.FullAddressStatic,
                    HomeAddressViewController.myIndex,
                    HomeAddressViewController.myNotation,
                    NewCardAddressMapViewController.lat,
                    NewCardAddressMapViewController.lng,
                    true
                    );
                System.Net.Http.HttpResponseMessage res = null;
                try
                {
                    res = await cards.CardUpdate(databaseMethods.GetAccessJwt(),
                                                 EditViewController.card_id,
                                                 databaseMethods.GetDataFromUsersCard(EditPersonalProcessViewController.company_id,
                                                                                      databaseMethods.GetLastSubscription(),
                                                                                      EditCompanyDataViewControllerNew.position, EditCompanyDataViewControllerNew.corporativePhone),
                                                 EditPersonalDataViewControllerNew.is_primary,
                                                 SocialNetworkTableViewSource <int, int> .socialNetworkListWithMyUrl,
                                                 EditViewController.ids_of_attachments,
                                                 UDID);
                }
                catch (Exception ex)
                {
                    if (!methods.IsConnected())
                    {
                        InvokeOnMainThread(() =>
                        {
                            NoConnectionViewController.view_controller_name = GetType().Name;
                            this.NavigationController.PushViewController(sb.InstantiateViewController(nameof(NoConnectionViewController)), false);
                            return;
                        });
                    }
                    return;
                }
                if (res.StatusCode.ToString().Contains("401") || res.StatusCode.ToString().ToLower().Contains(Constants.status_code401))
                {
                    InvokeOnMainThread(() =>
                    {
                        ShowSeveralDevicesRestriction();
                        return;
                    });
                    return;
                }

                InvokeOnMainThread(() =>
                {
                    ClearAll();

                    var vc = sb.InstantiateViewController(nameof(RootQRViewController));
                    try
                    {
                        this.NavigationController.PushViewController(vc, true);
                        //var vc_list = this.NavigationController.ViewControllers.ToList();
                        //try { vc_list.RemoveAt(vc_list.Count - 2); } catch { }
                        //this.NavigationController.ViewControllers = vc_list.ToArray();
                    }
                    catch { }
                });
            });
        }
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.LoadingLayout);
            clientName = Android.OS.Build.Manufacturer + " " + Android.OS.Build.Model;
            InitElements();
            if (!_methods.IsConnected())
            {
                NoConnectionActivity.ActivityName = this;
                StartActivity(typeof(NoConnectionActivity));
                Finish();
                return;
            }

            if (!EditCompanyDataActivity.ChangedCompanyData)
            {
                goto DoPersonalStuff;
            }

            #region uploading photos
            bool photosExist    = true;
            var  personalImages = await _nativeMethods.GetPersonalImages();

            if (personalImages == null)
            {
                photosExist = false;
            }
            else
            {
                photosExist = true;
            }
            var documentsLogo = await _nativeMethods.GetDocumentsLogo();

            if (documentsLogo != null)
            {
                photosExist = true;
            }
            int?       logoId             = null;
            List <int> attachmentsIdsList = new List <int>();
            if (photosExist)
            {
                _mainTextTv.Text = TranslationHelper.GetString("photosAreBeingUploaded", _ci);
                AttachmentsUploadModel resPhotos = null;
                try
                {
                    resPhotos = await _attachments.UploadAndroid(_databaseMethods.GetAccessJwt(), clientName, personalImages, documentsLogo);
                }
                catch (Exception ex)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return;
                    }
                }
                if (resPhotos == null)
                {
                    if (!_methods.IsConnected())
                    {
                        NoConnectionActivity.ActivityName = this;
                        StartActivity(typeof(NoConnectionActivity));
                        Finish();
                        return;
                    }
                }
                if (resPhotos != null)
                {
                    //var deserialized_logo = JsonConvert.DeserializeObject<CompanyLogoModel>(res_photos);
                    logoId             = resPhotos.logo_id;
                    attachmentsIdsList = resPhotos.attachments_ids;
                    if (logoId == Constants.image_upload_status_code401)
                    {
                        ShowSeveralDevicesRestriction();
                        return;
                    }
                }
            }
            _mainTextTv.Text = TranslationHelper.GetString("cardIsSynchronizing", _ci);
            #endregion uploading photos
            string resCompany = null;
            try
            {
                if (logoId != null)
                {
                    if (EditPersonalProcessActivity.CompanyId != null)
                    {
                        resCompany = await _companies.UpdateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard(), EditPersonalProcessActivity.CompanyId, logoId);
                    }
                    else
                    {
                        resCompany = await _companies.CreateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard(), logoId);
                    }
                }
                else
                {
                    if (EditPersonalProcessActivity.CompanyId != null)
                    {
                        resCompany = await _companies.UpdateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard(), EditPersonalProcessActivity.CompanyId);
                    }
                    else
                    {
                        resCompany = await _companies.CreateCompanyCard(_databaseMethods.GetAccessJwt(), clientName, _databaseMethods.GetDataFromCompanyCard());
                    }
                }
            }
            catch (Exception ex)
            {
                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }
            }
            if (String.IsNullOrEmpty(resCompany))
            {
                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }
            }
            if (resCompany == Constants.image_upload_status_code401.ToString())
            {
                ShowSeveralDevicesRestriction();
                return;
            }
            try
            {
                var deserialized = JsonConvert.DeserializeObject <CompanyCardResponse>(resCompany);
            }
            catch
            {
                _databaseMethods.ClearCompanyCardTable();
                var deserializedError = JsonConvert.DeserializeObject <List <CreateCompanyErrorModel> >(resCompany);
                Toast.MakeText(this, TranslationHelper.GetString("errorInCompanyData", _ci), ToastLength.Long).Show();
                base.OnBackPressed();
                return;
            }

            if (resCompany.Contains("id") && resCompany.Length < 12)
            {
                EditPersonalProcessActivity.CompanyId = Convert.ToInt32(JsonConvert.DeserializeObject <CompanyCardResponse>(resCompany).id);
            }
DoPersonalStuff:
            //caching card to db
            _databaseMethods.InsertUsersCard(
                EditPersonalDataActivity.MyName,
                EditPersonalDataActivity.MySurname,
                EditPersonalDataActivity.MyMiddlename,
                EditPersonalDataActivity.MyPhone,
                EditPersonalDataActivity.MyEmail,
                EditPersonalDataActivity.MyHomePhone,
                EditPersonalDataActivity.MySite,
                EditPersonalDataActivity.MyDegree,
                EditPersonalDataActivity.MyCardName,
                EditPersonalDataActivity.MyBirthDate,
                HomeAddressActivity.MyCountry,
                HomeAddressActivity.MyRegion,
                HomeAddressActivity.MyCity,
                HomeAddressActivity.FullAddressStatic,
                HomeAddressActivity.MyIndex,
                HomeAddressActivity.MyNotation,
                NewCardAddressMapActivity.Lat,
                NewCardAddressMapActivity.Lng,
                true
                );
            HttpResponseMessage res = null;
            try
            {
                res = await _cards.CardUpdate(_databaseMethods.GetAccessJwt(),
                                              EditActivity.CardId,
                                              _databaseMethods.GetDataFromUsersCard(EditPersonalProcessActivity.CompanyId,
                                                                                    _databaseMethods.GetLastSubscription(),
                                                                                    EditCompanyDataActivity.Position, EditCompanyDataActivity.CorporativePhone),
                                              EditPersonalDataActivity.IsPrimary,
                                              GetPersonalNetworks(),
                                              EditActivity.IdsOfAttachments,
                                              clientName);
            }
            catch (Exception ex)
            {
                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }
            }
            if (res == null)
            {
                if (!_methods.IsConnected())
                {
                    NoConnectionActivity.ActivityName = this;
                    StartActivity(typeof(NoConnectionActivity));
                    Finish();
                    return;
                }
            }
            if (res.StatusCode.ToString().Contains("401") || res.StatusCode.ToString().ToLower().Contains(Constants.status_code401))
            {
                ShowSeveralDevicesRestriction();
                return;
            }

            await Clear();

            try
            {
                StartActivity(typeof(QrActivity));
                //var vc_list = this.NavigationController.ViewControllers.ToList();
                //try { vc_list.RemoveAt(vc_list.Count - 2); } catch { }
                //this.NavigationController.ViewControllers = vc_list.ToArray();
            }
            catch { }
        }