Exemple #1
0
        public async void Execute(object control)
        {
            if (control.Equals("Nuevo"))
            {
                LimpiarCampos();
                ActivarControles();
                this._accion = ACCION.NUEVO;
            }
            else if (control.Equals("Eliminar"))
            {
                if (Elemento != null)
                {
                    MessageDialogResult resultado = await this._dialogCoordinator.ShowMessageAsync(
                        this,
                        "Eliminar Salon",
                        "Esta seguro de eliminar el registro?",
                        MessageDialogStyle.AffirmativeAndNegative);

                    if (resultado == MessageDialogResult.Affirmative)
                    {
                        try
                        {
                            _db.Salones.Remove(Elemento);
                            _db.SaveChanges();
                            this.ListaSalones.Remove(Elemento);
                            LimpiarCampos();
                        }
                        catch (Exception ex)
                        {
                            await this._dialogCoordinator.ShowMessageAsync(
                                this,
                                "Eliminar Salon",
                                ex.Message);
                        }
                    }
                }
                else
                {
                    await this._dialogCoordinator.ShowMessageAsync(
                        this,
                        "Eliminar Salon",
                        "Debe seleccionar un elemento");
                }
            }
            else if (control.Equals("Guardar"))
            {
                switch (this._accion)
                {
                case ACCION.NINGUNO:
                    break;

                case ACCION.NUEVO:
                    try
                    {
                        var registro = new Salon
                        {
                            Descripcion = this.Descripcion
                        };

                        _db.Salones.Add(registro);
                        _db.SaveChanges();
                        this.ListaSalones.Add(registro);
                    }
                    catch (Exception ex)
                    {
                        await this._dialogCoordinator.ShowMessageAsync(
                            this,
                            "Guardar Salon",
                            ex.Message);
                    }
                    finally
                    {
                        DesactivarControles();
                        this._accion = ACCION.NINGUNO;
                    }
                    break;

                case ACCION.GUARDAR:
                    try
                    {
                        int posicion = ListaSalones.IndexOf(Elemento);
                        var registro = _db.Salones.Find(Elemento.SalonId);

                        if (registro != null)
                        {
                            registro.Descripcion      = this.Descripcion;
                            _db.Entry(registro).State = EntityState.Modified;
                            _db.SaveChanges();
                            ListaSalones.RemoveAt(posicion);
                            ListaSalones.Insert(posicion, registro);
                        }
                    }
                    catch (Exception ex)
                    {
                        await this._dialogCoordinator.ShowMessageAsync(
                            this,
                            "Editar Salon",
                            ex.Message);
                    }
                    finally
                    {
                        DesactivarControles();
                        this._accion = ACCION.NINGUNO;
                    }
                    break;

                default:
                    break;
                }
            }
            else if (control.Equals("Editar"))
            {
                if (Elemento != null)
                {
                    ActivarControles();
                    this._accion = ACCION.GUARDAR;
                }
                else
                {
                    await this._dialogCoordinator.ShowMessageAsync(
                        this,
                        "Editar Salon",
                        "Debe seleccionar un elemento");
                }
            }
            else if (control.Equals("Cancelar"))
            {
                DesactivarControles();
                this._accion = ACCION.NINGUNO;
            }
        }