private void editOrSubmitButton_Click(object sender, RoutedEventArgs e) { isEditing = !isEditing; if (isEditing) { nameCakeTextbox.IsEnabled = true; removeImage.IsEnabled = true; priceTextbox.IsEnabled = true; categoryComboBox.IsEnabled = true; descriptionTextbox.IsEnabled = true; editOrSubmitButton.Content = "Xác nhận"; } else { if (imageUploadImage.Tag.ToString() != cake.Image_Main) { nameImage = imageUploadImage.Tag.ToString(); // Copy file var folder = AppDomain.CurrentDomain.BaseDirectory; string newNameFile = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(nameImage); var targetPath = $"{folder}\\Assets\\Images\\Uploads\\"; var destFile = System.IO.Path.Combine(targetPath, newNameFile); System.IO.File.Copy(fileUploadPath, destFile, true); // -- nameImage = newNameFile; } var categoryEntered = categories[categoryComboBox.SelectedIndex]; var newCake = new Cake(); newCake.Id = cake.Id; newCake.Name = nameCakeTextbox.Text; newCake.Price = int.Parse(priceTextbox.Text); newCake.Description = descriptionTextbox.Text; newCake.Image_Main = nameImage; newCake.Category = categoryEntered; CakesDAO.RemoveCake(cake.Id); CakesDAO.InsertCake(newCake); nameCakeTextbox.IsEnabled = false; removeImage.IsEnabled = false; priceTextbox.IsEnabled = false; categoryComboBox.IsEnabled = false; descriptionTextbox.IsEnabled = false; editOrSubmitButton.Content = "Chỉnh sửa"; } }
private void DisplayDetail() { cake = CakesDAO.GetById(idCake); var folder = AppDomain.CurrentDomain.BaseDirectory; var pathImageAbsolute = $"{folder}\\Assets\\Images\\Uploads\\{cake.Image_Main}"; imageUploadImage.Source = new BitmapImage(new Uri(pathImageAbsolute, UriKind.Absolute)); categories = CategoriesDAO.GetCategories(); categoryComboBox.ItemsSource = categories; categoryComboBox.SelectedIndex = categories.FindIndex(item => item.Id == cake.Category.Id); imageUploadImage.Tag = cake.Image_Main; nameImage = cake.Image_Main; this.DataContext = cake; }