Esempio n. 1
0
        private async void BabyModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (_currentProfile == null)
            {
                return;
            }

            BabyModel babyModel = (BabyModel)sender;

            if (e.PropertyName == "Picture")
            {
                babyModel = _currentProfile.CurrentBaby;

                if (babyModel != null)
                {
                    MediaManager mediaManager = MediaManager.Instance;

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

                    if (media == null)
                    {
                        // Insert
                        media = mediaManager.CreateImageMedia(babyModel.Picture);
                        await mediaManager.Add(media);

                        babyModel.MediaId = media.Id;
                    }
                    else
                    {
                        // Update
                        media.Image = babyModel.Picture;
                        await mediaManager.Update(media);
                    }
                }
            }
            else if (e.PropertyName == "IsSelected")
            {
                _currentProfile.CurrentBaby = babyModel;
            }
            else if (e.PropertyName == "IsDeleteRequested")
            {
                _currentProfile.ShowBabyDeleteAlert = babyModel.IsDeleteRequested;
            }

            BabyModelPropertyChanged?.Invoke(babyModel, e.PropertyName);
        }
Esempio n. 2
0
        public async void AddBaby(BabyModel babyModel)
        {
            if (_currentProfile != null)
            {
                try
                {
                    DataManager  dataManager  = DataManager.Instance;
                    MediaManager mediaManager = MediaManager.Instance;
                    Media        media        = null;

                    _currentProfile.Babies.Add(babyModel);

                    // If no current baby is set, make this the current baby as well
                    if (_currentProfile.CurrentBaby == null)
                    {
                        _currentProfile.CurrentBaby = babyModel;
                    }

                    if (babyModel.Picture != null)
                    {
                        media = mediaManager.CreateImageMedia(babyModel.Picture);
                        await mediaManager.Add(media);

                        babyModel.MediaId = media.Id;
                    }

                    Children child = new Children()
                    {
                        Id       = Guid.NewGuid().ToString(),
                        Name     = babyModel.Name,
                        Birthday = DateTime.Now
                    };

                    if (media != null)
                    {
                        child.MediaId = media.Id;
                    }

                    await dataManager.AddChild(child);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Exception in AddBaby - " + e.Message);
                }
            }
        }