private void EditClient_Click(object sender, RoutedEventArgs e) { if (!InValidContext()) { return; } var clientViewModel = new ClientViewModel() { Id = int.Parse(Id.Text), Name = Name.Text, MiddleName = MiddleName.Text, LastName = LastName.Text, SecondSurName = SecondSurName.Text, Age = int.Parse(Age.Text), Address = Address.Text, Identification = Identification.Text, IdentityGuid = IdentityGuid.Text, Phone = Phone.Text }; try { _clientRepository.UpateClient(clientViewModel.Id, clientViewModel); var rutaBorrar = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KallpaBox\\TempAssets"; var rutaDesktop = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KallpaBox\\Assets"; var photo = _photoRepository.GetPhotoClientId(_idClient); var rutaTemp = rutaBorrar + "\\" + _idClient + ".jpg"; if (ImageClient.Source != null) { if (!(Directory.Exists(rutaDesktop))) { Directory.CreateDirectory(rutaDesktop); } if (!(Directory.Exists(rutaBorrar))) { Directory.CreateDirectory(rutaBorrar); } var imagetemp = ImageClient.Source as BitmapSource; ImageClient.Source = null; ImageClient.UpdateLayout(); File.Delete(photo.PhotoClient); Thread.Sleep(1000); if (photo != null) { photo.PhotoClient = rutaDesktop + "\\" + _idClient + ".jpg"; _photoRepository.UpdatePhoto(photo); } else { photo = new Photo() { ClientId = _idClient, PhotoClient = rutaDesktop + "\\" + _idClient + ".jpg", LengthPhoto = FileInfoExtension.ObtenerTamanoArchivo(photo.PhotoClient) }; _photoRepository.CreatePhoto(photo); } BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(imagetemp)); FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Write, rutaDesktop); f.AllLocalFiles = FileIOPermissionAccess.Write; try { f.Demand(); } catch (SecurityException s) { Console.WriteLine(s.Message); } using (var fileStream = new FileStream(photo.PhotoClient, FileMode.Create)) { encoder.Save(fileStream); } } CleanControls(); PresentationMessage.ShowMessegeQueue(this.SnackBarEditClients.MessageQueue, "Cliente editado con exito"); } catch (Exception ex) { throw new Exception($"Error {ex.Message}", ex); } }