private void btnAddItem_Click(object sender, EventArgs e) { txtPrice.Text = txtPrice.Text.Replace('.', ','); if (cmbCategory.SelectedIndex < 0 || String.IsNullOrWhiteSpace(txtName.Text) || String.IsNullOrWhiteSpace(txtStock.Text) || !System.Text.RegularExpressions.Regex.IsMatch(txtStock.Text, "^[0-9]*$") || String.IsNullOrWhiteSpace(txtPrice.Text) || !System.Text.RegularExpressions.Regex.IsMatch(txtPrice.Text, @"^[0-9]*(?:\,[0-9]+)?$")) { MessageBox.Show("Please fill the fields properly", "Process incomplete", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //Creating the menu item for dao class. ChapeauModel.MenuItem item = new ChapeauModel.MenuItem() { Name = txtName.Text, Price = float.Parse(txtPrice.Text), Stock = int.Parse(txtStock.Text), Category = ConvertToCategory(cmbCategory.SelectedItem.ToString()) }; serviceItem.CreateMenuItem(item); MessageBox.Show("Item has been created", "Process complete", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = ""; txtPrice.Text = ""; txtStock.Text = ""; cmbCategory.SelectedItem = null; }
public IHttpActionResult CreateMenuItem(MenuItemCreate menuItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MenuItemService service = CreatedMenuItemService(); service.CreateMenuItem(menuItem); return(Ok()); }