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)); }
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); } } }