private void button1_Click(object sender, EventArgs e) { try { decimal price; CardPriceInfo cardPriceInfo = new CardPriceInfo(); if (Decimal.TryParse(textBox1.Text, out price)) { CardStatus cardStatus = new CardStatus(); cardStatus.status_message = price.ToString(); cardPriceInfo.cardStatus = cardStatus; cardPriceInfo.admin = admin; } else { throw new Exception("Введите число"); } var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/AttractionInfo/ChangeCardPrice"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { String json = JsonConvert.SerializeObject(cardPriceInfo); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); if (httpResponse.StatusCode == HttpStatusCode.Accepted) { cardPriceInfoResponse = GetCardPriceInfo(admin); Close(); } else if (httpResponse.StatusCode == HttpStatusCode.BadGateway) { MessageBox.Show("Касса с такими параметрами уже существует"); } else if (httpResponse.StatusCode == HttpStatusCode.NotAcceptable) { MessageBox.Show("Ошибка добавления кассы"); } else if (httpResponse.StatusCode == HttpStatusCode.NoContent) { MessageBox.Show("Ошибка предачи информации о кассе"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
public CardPriceInfo(CardStatus cardStatus, Admin admin) { this.admin = admin; this.cardStatus = cardStatus; }