Esempio n. 1
0
        public async Task <Mesa> BuscarDatos(int numero, int codPiso)
        {
            using (SqlConnection sql = new SqlConnection(_ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("[dbo].[Sp_Bus_Rest_Mesa]", sql))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("aTipoAccion", "POR_NUMERO"));
                    cmd.Parameters.Add(new SqlParameter("eNumero", numero));
                    cmd.Parameters.Add(new SqlParameter("ePiso", codPiso));
                    var response = new Mesa();
                    await sql.OpenAsync();

                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        if (reader.HasRows && await reader.ReadAsync())
                        {
                            response.numero = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                            if ((reader.IsDBNull(1) ? 0 : reader.GetInt32(1)) > 0)
                            {
                                response.piso = await _reposiPiso.BuscarDatos(reader.GetInt32(1));
                            }
                            response.descripcion = reader.IsDBNull(2) ? "" : reader.GetString(2);
                            response.numSillas   = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                            response.disponible  = reader.IsDBNull(4) ? false : reader.GetBoolean(4);
                            response.estado      = reader.IsDBNull(5) ? "" : reader.GetString(5);
                        }
                        return(response);
                    }
                }
            }
        }
Esempio n. 2
0
        public async Task <UsuarioPiso> BuscarDatos(int codUser)
        {
            using (SqlConnection sql = new SqlConnection(_ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("[dbo].[Sp_Bus_Mot_UsuarioPabellon]", sql))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("aTipoAccion", "POR_USUARIO"));
                    cmd.Parameters.Add(new SqlParameter("eUsuario", codUser));
                    var response = new UsuarioPiso();
                    await sql.OpenAsync();

                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        if (reader.HasRows && await reader.ReadAsync())
                        {
                            if ((reader.IsDBNull(1) ? 0 : reader.GetInt32(1)) > 0)
                            {
                                response.Usuario = await _reposiUsuario.GetUser(reader.GetInt32(1));
                            }
                            if ((reader.IsDBNull(2) ? 0 : reader.GetInt32(2)) > 0)
                            {
                                response.Piso = await _reposiPiso.BuscarDatos(reader.GetInt32(2));
                            }
                        }
                        return(response);
                    }
                }
            }
        }
        public async Task <ResultAPI> CambiarMesa(int Piso, int MesaAnt, int MesaNueva, int codUser, bool imprimirTicket)
        {
            var response = new ResultAPI();
            var user     = new Usuario();
            var miPiso   = new Piso();

            try
            {
                user = await _reposiUsuario.GetUser(codUser);

                miPiso = await _reposiPiso.BuscarDatos(Piso);

                using (SqlConnection sql = new SqlConnection(_ConnectionString))
                {
                    using (SqlCommand cmd = new SqlCommand("[dbo].[Sp_Grab_Rest_Pedido]", sql))
                    {
                        cmd.CommandType    = System.Data.CommandType.StoredProcedure;
                        cmd.CommandTimeout = 0;

                        cmd.Parameters.Add(new SqlParameter("@aTipoAccion", "CAMBIAR_MESA"));
                        cmd.Parameters.Add(new SqlParameter("@ePiso", Piso));
                        cmd.Parameters.Add(new SqlParameter("@eMesa", MesaAnt));
                        cmd.Parameters.Add(new SqlParameter("@eMesaNueva", MesaNueva));
                        await sql.OpenAsync();

                        using (var reader = await cmd.ExecuteReaderAsync())
                        {
                            if (reader.HasRows && await reader.ReadAsync())
                            {
                                response.codigo = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                            }

                            if (response.codigo == -1)
                            {
                                response.message_error = "Ocurrió un error al intentar cambiar de mesa.";
                            }
                            if (response.codigo == -2)
                            {
                                response.message_error = "La mesa ingresada no existe.";
                            }
                            if (response.codigo == -3)
                            {
                                response.message_error = "La mesa ingresada ya se encuentra ocupada.";
                            }
                            if (response.codigo > 0)
                            {
                                response.message_error = "OK";
                                response.estado        = true;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                response.message_error = e.Message;
            }

            if (response.estado && imprimirTicket)
            {
                ImprimirTicketCambioMesa(user.login, miPiso, MesaAnt, MesaNueva, true);
            }
            return(response);
        }