Example #1
0
        private void ChangeEncoderPassword(Models.Encoder encoder)
        {
            var pwd = encoder.Password;

            encoder.Update(nameof(Models.Encoder.Password), "");

            MainViewModel.EnqueueMessage(
                $"{encoder.Username}'s password has been reset.",
                "UNDO", en =>
            {
                en.Update(nameof(Models.Encoder.Password), pwd);
            }, encoder, true);
        }
Example #2
0
 private void EncoderDeleted(Models.Encoder encoder)
 {
     Open();
     MainViewModel.EnqueueMessage(
         $"{encoder.FullName} ({encoder.Username}) is successfully deleted.",
         "UNDO", en =>
     {
         en.Update(nameof(en.IsDeleted), false);
         Models.Encoder.Cache.Add(en);
         _items.Refresh();
         OnPropertyChanged(nameof(HasEncoders));
     }, encoder, true);
     OnPropertyChanged(nameof(HasEncoders));
 }
Example #3
0
        private async void AddNew()
        {
            var newUser = new NewUserDialog();

            newUser.AcceptCommand = new DelegateCommand(dd =>
            {
                IsDialogOpen     = false;
                var encoder      = new Models.Encoder();
                encoder.Username = newUser.Username;
                encoder.FullName = newUser.FullName;
                encoder.Save();
            }, dd => !string.IsNullOrWhiteSpace(newUser.Username) && !Models.Encoder.UsernameExists(newUser.Username));

            await DialogHost.Show(new Views.NewUserDialog()
            {
                DataContext = newUser
            }, "InnerDialog");

            OnPropertyChanged(nameof(HasEncoders));
        }
Example #4
0
        private void ChangeEncoderPicture(Models.Encoder encoder)
        {
            {
                var dlg = new OpenFileDialog();
                dlg.Title       = "Select Picture";
                dlg.Multiselect = false;
                dlg.Filter      = @"All Images|*.BMP;*.JPG;*.JPEG;*.GIF;*.PNG|
                               BMP Files|*.BMP;*.DIB;*.RLE|
                               JPEG Files|*.JPG;*.JPEG;*.JPE;*.JFIF|
                               GIF Files|*.GIF|
                               PNG Files|*.PNG";

                if (string.IsNullOrWhiteSpace(Settings.Default.OpenFileLocation))
                {
                    dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                }
                else
                {
                    dlg.InitialDirectory = Settings.Default.OpenFileLocation;
                }

                if (!dlg.ShowDialog(App.Current.MainWindow) ?? false)
                {
                    return;
                }

                Settings.Default.OpenFileLocation = Path.GetDirectoryName(dlg.FileName);
                Settings.Default.Save();

                try
                {
                    encoder.BackupPicture();
                    using (var img = Image.FromFile(dlg.FileName))
                    {
                        using (var bmp = ImageProcessor.Resize(img, 471))
                        {
                            using (var bin = new MemoryStream())
                            {
                                bmp.Save(bin, ImageFormat.Jpeg);
                                encoder.Picture = bin.ToArray();
                            }
                        }
                        using (var bmp = ImageProcessor.Resize(img, 74))
                        {
                            using (var bin = new MemoryStream())
                            {
                                bmp.Save(bin, ImageFormat.Jpeg);
                                encoder.Thumbnail = bin.ToArray();
                            }
                        }
                    }

                    encoder.Save();

                    MainViewModel.EnqueueMessage($"{encoder.Username}'s picture has been changed.", "UNDO",
                                                 en =>
                    {
                        en.RestorePicture();
                        en.Save();
                    }, encoder, true);
                }
                catch (Exception e)
                {
                    Messenger.Default.Broadcast(Messages.Error, e);
                }
            }
        }