Esempio n. 1
0
        /// <summary>
        /// Guarda un grupo y sus integrantes
        /// </summary>
        /// <history>
        /// [ecanul] 04/04/2016 Created;
        /// [ecanul] 21/06/2016 Modified. Agregada Asincronia.
        /// [ecanul] 09/09/2016 Modified. Ahora se actualiza el formulario despues de guardar
        /// </history>
        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List <Guest> lstGuests = (List <Guest>)dtgGuestGroupIntegrants.ItemsSource;
                _guestsGroup = new GuestsGroup();
                //Si no ha especificado un nombre de grupo
                if (string.IsNullOrEmpty(txtDescription.Text))
                {
                    UIHelper.ShowMessage("Specify the Guest Group Name", MessageBoxImage.Error);
                    return;
                }
                //Si tiene menos de 2 integrantes
                if (_lstGuestTemp == null || _lstGuestTemp.Count <= 1)
                {
                    UIHelper.ShowMessage("Specify at least 2 integrants", MessageBoxImage.Error);
                    return;
                }
                //Si se tiene un grupo
                if (!string.IsNullOrEmpty(txtID.Text))
                {//Obtiene el registro existente en base de datos
                    _guestsGroup.gxID = Convert.ToInt32(txtID.Text.Trim());
                    _guestsGroup      = await BRGuestsGroups.GetGuestsGroup(_guestsGroup.gxID);

                    _oldListGuests = _guestsGroup.Guests.ToList();
                }
                _guestsGroup.gxN = txtDescription.Text.Trim();
                //Guests a agregar
                List <Guest> lstAdd = lstGuests.Where(gu => !_oldListGuests.Any(gui => gui.guID == gu.guID)).ToList();
                //Guests a eliminar
                List <Guest> lstDel = _oldListGuests.Where(gu => !lstGuests.Any(gui => gui.guID == gu.guID)).ToList();
                //Guarda los datos
                int res = await BRGuestsGroups.SaveGuestGroup(_guestsGroup, _mode, lstAdd, lstDel);

                EnableControls(0);

                txtgxID.Text = res.ToString();
                await LoadGrdGuestsGroups();

                var gg = new GuestsGroup {
                    gxID = res
                };
                LoadGridGuestsGroupsIntegrants(gg);
                txtgxID.Text = string.Empty;
                txtID.Text   = res.ToString();
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Carga el DataGrid GuestsGroups
        /// </summary>
        /// <history>
        /// [ECANUL] 28-03-2016 Created
        /// [ecaul]17/06/2016 Modified. Implementado Asincronia
        /// </history>
        private async Task <int> LoadGrdGuestsGroups()
        {
            StaStart("Loading Groups...");
            if (!string.IsNullOrEmpty(txtgxID.Text))
            {
                _guestsGroup.gxID = Convert.ToInt32(txtgxID.Text);
            }
            _lstGuestsGroups = await BRGuestsGroups.GetGuestsGroups(_guest, _guestsGroup);

            dtgGuestsGroup.ItemsSource = _lstGuestsGroups;

            string s = dtgGuestsGroup.Items.Count == 1 ? "Group" : "Groups";

            StatusBarReg.Content = $"{dtgGuestsGroup.Items.Count} {s}";
            StaEnd();
            txtgxID.Text = string.Empty;
            return(_lstGuestsGroups.Count());
        }