Пример #1
0
        public override void LoadFromStore(VMStore modelStore)
        {
            try
            {
                Profile               = JsonConvert.DeserializeObject <ClientProfileDTO>(modelStore.Store);
                Downloaded            = Profile.Downloaded;
                ClientId              = Profile.ClientId;
                SelectedMaritalStatus = MaritalStatus.FirstOrDefault(x => x.Id == Profile.MaritalStatus);
                SelectedKeyPop        = KeyPops.FirstOrDefault(x => x.Id == Profile.KeyPop);
                OtherKeyPop           = Profile.OtherKeyPop;
                SelectedEducation     = Educations.FirstOrDefault(x => x.ItemId == Profile.Education);
                SelectedCompletion    = Completions.FirstOrDefault(x => x.ItemId == Profile.Completion);
                SelectedOccupation    = Occupations.FirstOrDefault(x => x.ItemId == Profile.Occupation);

                if (null != Profile.RelTypeId && !string.IsNullOrWhiteSpace(Profile.RelTypeId))
                {
                    SelectedRelationshipType =
                        RelationshipTypes.FirstOrDefault(x => x.Description.ToLower() == Profile.RelTypeId.ToLower());
                }
            }
            catch (Exception e)
            {
                Mvx.Error(e.Message);
            }
        }
Пример #2
0
        public AddUserViewModel(IScreen screen) : base(screen)
        {
            User              = new User();
            Age               = 0;
            Username          = "";
            FullName          = "";
            Educations        = EducationTypeLookup.Load();
            Genders           = GenderTypeLookup.Load();
            MaritalStatus     = MaritalStatusTypeLookup.Load();
            SelectedEducation = Educations.FirstOrDefault();
            SelectedGender    = Genders.FirstOrDefault();
            SelectedMarital   = MaritalStatus.FirstOrDefault();
            Insert            = ReactiveCommand.Create(AddUser);

            this.WhenActivated(d =>
            {
                this.WhenAnyValue(x => x.FullName)
                .WhereNotNull()
                .Where(x => x.HasValue())
                .Where(x => this.Username.IsEmpty())
                .Subscribe(x =>
                {
                    if (!x.HasSpecialCharacters())
                    {
                        var i = 0;
                        var suggestedUsername = x.Remove(" ", "\n");
                        while (UserManager.UserExists(suggestedUsername))
                        {
                            i += 1;
                            suggestedUsername = suggestedUsername + i;
                        }
                        Username = suggestedUsername;
                    }
                }).DisposeWith(d);
            });

            this.ValidationRule(vm => vm.FullName,
                                name => name.HasValue() && name.Length > 2,
                                LanguageHelper.GetString("MustProvideAge", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => name.HasValue() && name.Length > 2,
                                LanguageHelper.GetString("MustProvideUserName", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => !name.HasSpecialCharacters() && !name.ContainsAny(' ', '\n'),
                                LanguageHelper.GetString("UserNameHasInvalidChars", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => !UserManager.UserExists(name),
                                LanguageHelper.GetString("UserExists", "Text"));

            this.ValidationRule(vm => vm.Age,
                                age => age > 4,
                                LanguageHelper.GetString("MustProvideAge", "Text"));
        }
Пример #3
0
        private async void SaveEducationsMethod()
        {
            if (IsEducationValid())
            {
                using (var _database = new ITManagerEntities())
                {
                    var userEducations = (await _database.Users.Where(u => u.Id == User.Id)
                                          .Include(u => u.Educations)
                                          .FirstOrDefaultAsync()).Educations;

                    // Removing and changing educations
                    foreach (var userEducation in userEducations.ToList())
                    {
                        var _userEducation = Educations.FirstOrDefault(l => l.Id == userEducation.Id);
                        // If exists in local collection, change data
                        if (_userEducation != null)
                        {
                            userEducation.StartDate  = _userEducation.StartDate;
                            userEducation.EndDate    = _userEducation.EndDate;
                            userEducation.Faculty    = _userEducation.Faculty;
                            userEducation.Speciality = _userEducation.Speciality;
                            userEducation.University = _userEducation.University;
                        }
                        // If not exists in local collection - remove.
                        else
                        {
                            _database.Educations.Remove(userEducation);
                        }
                    }

                    // Adding new education
                    foreach (var newEducation in Educations.Where(l => l.Id == 0))
                    {
                        userEducations.Add(new Education
                        {
                            StartDate  = newEducation.StartDate,
                            EndDate    = newEducation.EndDate,
                            Faculty    = newEducation.Faculty,
                            Speciality = newEducation.Speciality,
                            University = newEducation.University,
                            UserId     = User.Id
                        });
                    }

                    IsEducationsChecked = false;
                    User.Educations     = (await _database.Users.Where(u => u.Id == User.Id).FirstOrDefaultAsync())?.Educations;

                    await _database.SaveChangesAsync();
                }
            }
        }
Пример #4
0
        public override void Start()
        {
            base.Start();
            MaritalStatus = _lookupService.GetMaritalStatuses(true).ToList();
            KeyPops       = _lookupService.GetKeyPops(true).ToList();
            Educations    = _lookupService.GetCategoryItems("Education", true, "[Select Education]").ToList();
            Completions   = _lookupService.GetCategoryItems("Completion", true, "[Select Completion]").ToList();
            Occupations   = _lookupService.GetCategoryItems("Occupation", true, "[Select Occupation]").ToList();

            try
            {
                SelectedMaritalStatus = MaritalStatus.FirstOrDefault(x => x.Id == "");
                SelectedKeyPop        = KeyPops.FirstOrDefault(x => x.Id == "");
                SelectedEducation     = Educations.FirstOrDefault(x => x.Id == Guid.Empty);
                SelectedCompletion    = Completions.FirstOrDefault(x => x.Id == Guid.Empty);
                SelectedOccupation    = Occupations.FirstOrDefault(x => x.Id == Guid.Empty);
            }
            catch {}
        }