예제 #1
0
        private async Task UpdateCaregivers()
        {
            if (null != _currentProfile)
            {
                _currentProfile.Caregivers.Clear();

                IEnumerable <CaregiverRelation> cRelations = await DataManager.Instance.GetCaregiversRelations(_currentProfile.ProfileId);

                foreach (var item in cRelations)
                {
                    if (item.IsDeleteRequested)
                    {
                        continue;
                    }

                    CaregiverModel model = new CaregiverModel()
                    {
                        ProfileId      = item?.ProfileId,
                        CaregiverId    = item?.CaregiverProfileId,
                        CaregiverEmail = item?.CaregiverEmail,
                        IsRequest      = false
                    };

                    string probeId = (_currentProfile.ProfileId == item.CaregiverProfileId ? item.ProfileId : item.CaregiverProfileId);

                    Profile profile = await DataManager.Instance.GetProfile(probeId);

                    if (null != profile)
                    {
                        model.CaregiverEmail = profile.Email;
                    }
                    _currentProfile.Caregivers.Add(model);
                }

                IEnumerable <CaregiverRequest> cRequests = await DataManager.Instance.GetCaregiversRequests(_currentProfile.ProfileId);

                foreach (var item in cRequests)
                {
                    if (item.IsDeleteRequested)
                    {
                        continue;
                    }

                    CaregiverModel model = new CaregiverModel()
                    {
                        ProfileId      = item?.ProfileId,
                        CaregiverId    = null,
                        CaregiverEmail = item?.Email,
                        IsRequest      = true
                    };
                    _currentProfile.Caregivers.Add(model);
                }

                Device.BeginInvokeOnMainThread(() =>
                {
                    ProfilePropertyChanged?.Invoke(_currentProfile, nameof(_currentProfile.Caregivers));
                });
            }
        }
예제 #2
0
        public async Task Sync()
        {
            User user = await DataManager.Instance.GetUser();

            //Profile profile = await DataManager.Instance.GetUserProfiles(LoginManager.Instance.UserId);
            Profile profile = await DataManager.Instance.GetUserProfiles(user.DefaultProfileId);

            MediaManager mediaManager = MediaManager.Instance;

            if ((user != null) && (profile != null))
            {
                IEnumerable <Children> children = await DataManager.Instance.GetChildren(profile.Id);

                BabyModel babyModel;
                string    userName = (user.Name != null) ? user.Name : Name;

                // These will be grabbed from LoginManager once it is finished
                if (_currentProfile == null)
                {
                    _currentProfile = new ProfileModel()
                    {
                        Name      = userName,
                        Email     = UserEmail,
                        ProfileId = profile.Id
                    };
                    _currentProfile.PropertyChanged += _currentProfile_PropertyChanged;

                    ProfilePropertyChanged?.Invoke(_currentProfile, nameof(CurrentProfile));
                }
                else if (_currentProfile.Name != userName || _currentProfile.Email != UserEmail)
                {
                    _currentProfile.Name             = userName;
                    _currentProfile.Email            = UserEmail;
                    _currentProfile.ProfileId        = profile.Id;
                    _currentProfile.PropertyChanged += _currentProfile_PropertyChanged;

                    ProfilePropertyChanged?.Invoke(_currentProfile, nameof(CurrentProfile));
                }

                foreach (Children child in children)
                {
                    var existing = _currentProfile.Babies.Where(c => c.Id == child.Id).FirstOrDefault();

                    if (existing == null)
                    {
                        babyModel = new BabyModel()
                        {
                            Id       = child.Id,
                            Name     = child.Name,
                            Birthday = child.Birthday,
                        };

                        Media media = mediaManager.Get(child.MediaId);

                        if (media != null)
                        {
                            babyModel.Picture = media.Image;
                            babyModel.MediaId = media.Id;
                        }

                        babyModel.PropertyChanged += BabyModel_PropertyChanged;

                        _currentProfile.Babies.Add(babyModel);

                        if (_currentProfile.CurrentBaby == null)
                        {
                            _currentProfile.CurrentBaby = babyModel;
                        }
                    }
                }

                await UpdateCaregivers();
            }
        }