Esempio n. 1
0
 public AttractionInfo(Admin admin, Attraction attraction)
 {
     this.admin      = admin;
     this.attraction = attraction;
 }
Esempio n. 2
0
        private void saveChangesButton_Click(object sender, EventArgs e)
        {
            try
            {
                Attraction attraction = new Attraction();
                IPAddress  ipAddress;
                if (IPAddress.TryParse(maskedTextBoxIP.Text, out ipAddress))
                {
                    attraction.attractionIp = ipAddress.ToString();
                }
                else
                {
                    throw new Exception("Не верное значение поля IP");
                }
                double priceAttraction;
                if (Double.TryParse(textBoxPrice.Text, out priceAttraction))
                {
                    attraction.attractionPrice = priceAttraction;
                }
                else
                {
                    throw new Exception("Не верное значение Цены");
                }
                if (!(String.IsNullOrEmpty(textBoxName.Text.ToString())) && textBoxName.Text.ToString().Trim() != string.Empty)
                {
                    attraction.attractionName = textBoxName.Text.ToString();
                }
                else
                {
                    throw new Exception("Введите имя");
                }

                attraction.attractionType           = selectedAttreactionType.attractionTypeId;
                attraction.attractionIsRental       = RentalStatus;
                attraction.attractionDiscountSpread = DiscountStatus;

                int pulseDuration;
                if (Int32.TryParse(textBoxPulseDuration.Text, out pulseDuration))
                {
                    if (pulseDuration > 0)
                    {
                        attraction.attractionPusleDuration = pulseDuration;
                    }
                    else
                    {
                        throw new Exception("Не верное значение длительности импульса");
                    }
                }
                else
                {
                    throw new Exception("Не верное значение длительности импульса");
                }
                if (Int32.TryParse(textBox2.Text, out pulseDuration))
                {
                    if (pulseDuration > 0)
                    {
                        attraction.attractionParam1 = textBox2.Text.ToString();
                    }
                    else
                    {
                        throw new Exception("Не верное значение param1");
                    }
                }
                else
                {
                    throw new Exception("Не верное значение param1");
                }
                attraction.attractionLastPing = DateTime.Now;
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(APP_PATH + "/api/AttractionInfo/PostNewAttraction");
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                AttractionInfo attractionInfo = new AttractionInfo(admin, attraction);
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    String json = JsonConvert.SerializeObject(attractionInfo);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                if (httpResponse.StatusCode == HttpStatusCode.Accepted)
                {
                    Close();
                }
                else if (httpResponse.StatusCode == HttpStatusCode.NoContent)
                {
                    MessageBox.Show("Ошибка добавления аттракциона");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }