/// <summary> /// Saves data about the picture to the DB /// </summary> /// <param name="addPictureModel"></param> /// <param name="imageFileName"></param> /// <returns></returns> private bool SavePicture(AddPictureModel addPictureModel, string fileNameWithoutExt) { var pictureModel = new PictureModel { AlbumID = addPictureModel.AlbumID, PictureTitle = addPictureModel.Title, FileName = fileNameWithoutExt, FilePath = $"~/Pictures/{fileNameWithoutExt}.png", FileSize = addPictureModel.PictureFile.ContentLength, }; return(_pictureManager.AddPicture(pictureModel, addPictureModel.AlbumID)); }
/// <summary> /// Creator: Robert Holmes /// Created: 2020/03/18 /// Approver: Jaeho Kim /// /// Handles saving product data to the database. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnAction_Click(object sender, RoutedEventArgs e) { switch (btnAction.Content) { case ("Save"): { if (validateFields()) { try { _product.ProductID = txtProductID.Text; _product.ItemID = Convert.ToInt32(txtItemID.Text); _product.Name = txtName.Text; _product.Category = txtCategory.Text; _product.Brand = txtBrand.Text; _product.Type = (string)cboType.SelectedItem; _product.Price = (decimal)numPrice.Value; _product.Description = txtDescription.Text; if ((string)cboTaxable.SelectedItem == "No") { _product.Taxable = false; } else { _product.Taxable = true; } _productManager.AddProduct(_product); _picture.ProductID = _product.ProductID; if (!_picture.IsUsingDefault) { _pictureManager.AddPicture(_picture); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage("Failed to save product to database.\n\n" + ex.Message, ex.GetType().ToString()); } _frame.Navigate(new pgInventoryItems(_frame)); } break; } case "Update": { if (validateFields()) { try { var newProduct = new Product { ProductID = _product.ProductID, ItemID = Convert.ToInt32(txtItemID.Text), Name = txtName.Text, Category = txtCategory.Text, Brand = txtBrand.Text, Type = (string)cboType.SelectedItem, Price = (decimal)numPrice.Value, Description = txtDescription.Text, Active = _product.Active }; if (cboTaxable.SelectedItem.ToString().Equals("No")) { newProduct.Taxable = false; } else { newProduct.Taxable = true; } _productManager.EditProduct(_product, newProduct); _picture.ProductID = _product.ProductID; if (_pictureUpdated) { _pictureManager.AddPicture(_picture); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage("There was a problem saving the new product information:\n\n" + ex.Message); } _frame.Navigate(new pgInventoryItems(_frame)); } break; } case "Done": { _frame.Navigate(new pgInventoryItems(_frame)); break; } default: { break; } } }