Example #1
0
        public ActionResult <string> marcarAula(dynamic json)
        {
            lock (_system)
            {
                JObject received          = JObject.Parse(JsonSerializer.Serialize(json));
                ActionResult <string> ret = Ok();
                var uMail = _system.getUserGivenToken(received.GetValue("valueST").ToString());
                if (uMail == null)
                {
                    return(Unauthorized("Client Offline"));
                }
                var         tmp = received.GetValue("aula").ToObject <int>();
                AulaGrupo   ag  = _system.GetAulaID(tmp);
                ClienteAula ca  = new ClienteAula(ag.id, ag.hora, ag.dia, uMail, ag.instrutor_email, ag.espaço_ginasio);

                if (((ag.lotaçao_Max < ag.lotaçao_Atual + 1) || !(_system.MarcarAula(ca))))
                {
                    ret = BadRequest("Lotaçao Maxima atingida");
                }


                return(ret);
            }
        }
Example #2
0
        public bool MarcarAula(ClienteAula ca)
        {
            bool r = false;

            try
            {
                connection.Open();

                string sqlCommand = "insert into Clientes_na_AulaGrupo (idAula_Grupo,hora, dia,Cliente_email,  Instrutor_email, Espaço_Ginasio)" +
                                    " values(" + ca.ToSql() + ")";

                MySqlCommand command = new MySqlCommand(sqlCommand, connection);

                ca.InitParam(command);

                if (command.ExecuteNonQuery() > 0)
                {
                    sqlCommand = "update Aula_Grupo set lotaçao_Atual = lotaçao_Atual+1 where idAula_Grupo =" + ca.id;
                    command    = new MySqlCommand(sqlCommand, connection);

                    if (command.ExecuteNonQuery() > 0)
                    {
                        r = true;

                        sqlCommand = "select nome from Aula_Grupo where idAula_Grupo = @ID_AULA";
                        command    = new MySqlCommand(sqlCommand, connection);

                        command.Parameters.Add(new MySqlParameter("@ID_AULA", MySqlDbType.Int32));
                        command.Parameters["@ID_AULA"].Value = ca.id;

                        string nomeAula = Convert.ToString(command.ExecuteScalar());

                        sqlCommand = "update Estatistica set num_vezes_feita = num_vezes_feita + 1 where Cliente_email = @CLIENTE_EMAIL " +
                                     " and nome = @NOME_AULA";
                        command = new MySqlCommand(sqlCommand, connection);

                        command.Parameters.Add(new MySqlParameter("@CLIENTE_EMAIL", MySqlDbType.VarChar));
                        command.Parameters["@CLIENTE_EMAIL"].Value = ca.cliente_email;

                        command.Parameters.Add(new MySqlParameter("@NOME_AULA", MySqlDbType.VarChar));
                        command.Parameters["@NOME_AULA"].Value = nomeAula;

                        if (command.ExecuteNonQuery() == 0)
                        {
                            sqlCommand = "insert into Estatistica (nome, num_vezes_feita, Cliente_email) values " +
                                         "(@NOME_AULA, @NUM_VEZES_FEITA, @CLIENTE_EMAIL)";
                            command = new MySqlCommand(sqlCommand, connection);

                            command.Parameters.Add(new MySqlParameter("@CLIENTE_EMAIL", MySqlDbType.VarChar));
                            command.Parameters["@CLIENTE_EMAIL"].Value = ca.cliente_email;

                            command.Parameters.Add(new MySqlParameter("@NOME_AULA", MySqlDbType.VarChar));
                            command.Parameters["@NOME_AULA"].Value = nomeAula;

                            command.Parameters.Add(new MySqlParameter("@NUM_VEZES_FEITA", MySqlDbType.Int16));

                            command.Parameters["@NUM_VEZES_FEITA"].Value = 1;
                            command.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                connection.Close();
            }

            return(r);
        }