Exemplo n.º 1
0
        private async void SaveQueryMethod()
        {
            if (SelectedProjects == null)
            {
                SelectedProjects = new ObservableCollection <Models.ProjectsManagementPageModels.Project>();
            }
            if (QueryDescription.Length > 1 && QueryDescription.Length < 100)
            {
                var skillsQuery    = string.Join(",", SkillsConditions?.Select(s => $"{s.Skill.Id}:{s.From.Id}-{s.To.Id}"));
                var languagesQuery = string.Join(",", LanguagesConditions?.Select(l => $"{l.Language.Id}:{l.From.Id}-{l.To.Id}"));
                var projectsQuery  = string.Join(",", SelectedProjects?.Select(p => p.Id));

                var query = $"{skillsQuery}&{languagesQuery}&{projectsQuery}";

                using (var _database = new ITManagerEntities())
                {
                    var user = await _database.Users.Where(u => u.Id == ShellViewModel.CurrentUserId)
                               .Include(u => u.Queries).FirstOrDefaultAsync();

                    user.Queries.Add(new Query()
                    {
                        Description = QueryDescription,
                        QueryString = query,
                        UserId      = ShellViewModel.CurrentUserId
                    });
                    await _database.SaveChangesAsync();
                }
                _eventAggregator.GetEvent <UpdateQueriesEvent>().Publish();
                QueryErrors = string.Empty;
            }
            else
            {
                QueryErrors = "Query description length must be from 1 to 100 sybmols.";
            }
        }
Exemplo n.º 2
0
        private void LanguagesSelectionChangedMethod()
        {
            if (SelectedLanguages == null)
            {
                SelectedLanguages = new ObservableCollection <Models.UserPageModel.LanguagesList>();
            }
            if (SelectedLanguages.Count > LanguagesConditions.Count)
            {
                foreach (var selectedLanguage in SelectedLanguages)
                {
                    if (LanguagesConditions.Where(s => s.Language.Id == selectedLanguage.Id).FirstOrDefault() == null)
                    {
                        LanguagesConditions.Add(new LanguageCondition
                        {
                            Language = selectedLanguage,
                            From     = LanguageLevels.First(),
                            To       = LanguageLevels.Last()
                        });
                        return;
                    }
                }
            }

            if (SelectedLanguages.Count < LanguagesConditions.Count)
            {
                foreach (var languageCondition in LanguagesConditions)
                {
                    if (SelectedLanguages.Where(s => s.Id == languageCondition.Language.Id).FirstOrDefault() == null)
                    {
                        var language = LanguagesConditions.Where(s => s.Language.Id == languageCondition.Language.Id).FirstOrDefault();
                        if (language == null)
                        {
                            return;
                        }
                        LanguagesConditions.Remove(language);
                        return;
                    }
                }
            }
        }