Exemple #1
0
        private async void Create_Click(object sender, RoutedEventArgs e)
        {
            var index = ProductBox.SelectedIndex;

            ModelManager modelManager = ModelManager.GetInstance();
            JObject      newObj       = new JObject();

            newObj.Add("Description", new JValue(DescriptionBox.Text));
            newObj.Add("Name", new JValue(DeviceGroupNameBox.Text));
            newObj.Add("OsFeedType", new JValue(OsFeedTypeBox.SelectedIndex));
            newObj.Add("ProductId", new JValue(ProductModels[index].Context.Id));
            newObj.Add("UpdatePolicy", new JValue(UpdatePolicyBox.SelectedIndex));

            List <DeviceGroupModel> groups = await modelManager.GetDeviceGroupModels(this.CurrentTenantModel, false);

            foreach (DeviceGroupModel model in groups)
            {
                if (model.Product == ProductModels[index].Product &&
                    model.DeviceGroup == DeviceGroupNameBox.Text)
                {
                    MessageBox.Show("DeviceGroup is already exists",
                                    "Error", MessageBoxButtons.OK);
                    return;
                }
            }

            Cursor = System.Windows.Input.Cursors.Wait;
            this.CreateButton.IsEnabled = false;
            this.CloseButton.IsEnabled  = false;

            if (await modelManager.CreateDeviceGroup(CurrentTenantModel, newObj.ToString()))
            {
                MessageBox.Show("Create DeviceGroup is success.",
                                "Ok", MessageBoxButtons.OK);
            }
            else
            {
                MessageBox.Show("Create DeviceGroup is failure",
                                "Error", MessageBoxButtons.OK);
            }
            Cursor = null;
            this.CreateButton.IsEnabled = true;
            this.CloseButton.IsEnabled  = true;
        }