private void ProductForm_Load(object sender, EventArgs e) { if (id.HasValue) { try { SushiViewModel view = service.GetElement(id.Value); if (view != null) { Name.Text = view.SushiName; Price.Text = view.Price.ToString(); productElems = view.ElementRequirements; LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { productElems = new List <ElementRequirementsViewModel>(); } }
private void Calculate() { if (SushiCB.SelectedValue != null && !string.IsNullOrEmpty(CountTB.Text)) { try { int id = Convert.ToInt32(SushiCB.SelectedValue); SushiViewModel product = serviceP.GetElement(id); int count = Convert.ToInt32(CountTB.Text); SumTB.Text = (count * product.Price).ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public decimal Calc(decimal count, int sushi) { SushiViewModel sush = APIClient.GetRequest <SushiViewModel>($"api/main/getsushi?sushiId={sushi}"); return(count * sush.Price); }