Пример #1
0
        public void SaveNewDictionaryToDB()
        {
            //Get primary and translated language selected by User
            string     fromLanguage = Languages.ElementAt(PrimaryLangSelectedIndex);
            string     toLanguage   = Languages.ElementAt(translateLangSelectedIndex);
            Dictionary dict         = App.PritixDB.GetDictionaryByLanguage(fromLanguage, toLanguage).Result;

            if (dict == null)
            {
                //Save dictionary to DB
                App.PritixDB.SaveDictionaryItemAsync(new Dictionary()
                {
                    FromLanguage = fromLanguage, ToLanguage = toLanguage
                }).Wait();
                Dictionary lastSavedDictionary = App.PritixDB.GetDictionaryByLanguage(fromLanguage, toLanguage).Result;
                var        xxxx = App.PritixDB.GetAllDictionariesByUserId(App.PritixDB.CurrentLoggedInUser.UserId).Result;

                App.PritixDB.SaveUserDictionaryMapping(new UserDictionaryMapping()
                {
                    DictionaryId = lastSavedDictionary.DictionaryId, UserId = App.PritixDB.CurrentLoggedInUser.UserId
                }).Wait();

                new DialogService().ShowMessage("Success!!", "Your dictionary is successfully saved.", "OK", GoBackToHome);
            }
            else
            {
                //Check wether User mapping with this dictionary present or not
                var userDictMapping = App.PritixDB.GetUserDictMappingByDictId(dict.DictionaryId).Result;
                //Means mapping not exist but dictionary exist(Which is added by other user)
                if (userDictMapping == null)
                {
                    try
                    {
                        var xx      = App.PritixDB.GetAllDictionariesByUserId(App.PritixDB.CurrentLoggedInUser.UserId).Result;
                        var mapping = new UserDictionaryMapping()
                        {
                            DictionaryId = dict.DictionaryId, UserId = App.PritixDB.CurrentLoggedInUser.UserId
                        };
                        int mapperIndex = App.PritixDB.SaveUserDictionaryMapping(mapping).Result;
                        if (mapperIndex != 0)
                        {
                            new DialogService().ShowMessage("Success!!", "Your dictionary is successfully saved.", "OK", GoBackToHome);
                        }
                        else
                        {
                            new DialogService().ShowMessage("Error!!", "Something went wrong while mapping user with dictionary.", "OK", null);
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
                else
                {
                    new DialogService().ShowMessage("Error!!", "This Dictionary already exist.Please choose another.", "OK", null);
                }
            }
        }
        public EditDictionaryViewModel(INavigation navigation, Dictionary selectedDictionary)
        {
            this.Navigation    = navigation;
            AddKeyValue        = new Command(AddBlankKeyValuePair);
            Save               = new Command(SaveAndGoBack);
            SelectedDictionary = selectedDictionary;
            PrimaryLanguage    = selectedDictionary.FromLanguage;
            TranslateLanguage  = selectedDictionary.ToLanguage;
            var mapping = App.PritixDB.GetUserDictMappingByDictId(selectedDictionary.DictionaryId).Result;

            UserSelectedDictionaryMapping = mapping;
            List <DictionaryDetail> dictDetails = App.PritixDB.GetDictionaryDetailsByMappingIndex(mapping.MappingIndex).Result;

            DictionaryDetails = new ObservableCollection <DictionaryDetail>(dictDetails);
        }
Пример #3
0
 //User Mapping
 public Task <int> SaveUserDictionaryMapping(UserDictionaryMapping userDictMapping)
 {
     return(database.InsertAsync(userDictMapping));
 }