Ejemplo n.º 1
0
        public bool SaveNote(PostNote note)
        {
            if (note == null) //Check if the note contains any data
            {
                return(false);
            }
            else
            {
                string connectionString = DATABASE_CONNECTION;

                // The SQL query to be sent to the server
                string query = "INSERT INTO Note (PatientID, Title, Text, Picture) VALUES ('@PatientID', '@Title', '@Text', '@Picture');";

                //Replace the values in the SQL query string with the data to be added to the server
                query = query.Replace("@PatientID", Convert.ToString(note.PatientID))
                        .Replace("@Title", note.Title)
                        .Replace("@Text", note.Text)
                        .Replace("@Picture", note.Picture);

                // Establish connection with the SQL server
                SqlConnection connection = new SqlConnection(connectionString);

                try
                {
                    connection.Open(); // Open the connection to the server

                    // Create the command to be sent to the server with the query and connection info
                    SqlCommand command = new SqlCommand(query, connection);
                    command.ExecuteNonQuery(); // Execute the command on the server
                    command.Dispose();
                    connection.Close();        // Close the connection to the server
                    return(true);
                }
                catch (Exception)
                {
                    // If the command fails return false
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
    public async Task <IActionResult> Ajouter(Guid id, PostNote postNote, CancellationToken token)
    {
        if (id != postNote.IdErabliere)
        {
            return(BadRequest("L'id de la route ne concorde pas avec l'érablière possédant la note"));
        }

        if (postNote.Created == null)
        {
            postNote.Created = DateTimeOffset.Now;
        }

        if (postNote.NoteDate == null)
        {
            postNote.NoteDate = DateTimeOffset.Now;
        }

        var entite = await _depot.Notes.AddAsync(_mapper.Map <Note>(postNote), token);

        await _depot.SaveChangesAsync(token);

        return(Ok(entite.Entity));
    }
Ejemplo n.º 3
0
    public void SendNotification()
    {
        if (PlayerPrefs.HasKey("child"))
        {
            //Firebase
            DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

            //Hora
            string a = System.DateTime.Now.GetDateTimeFormats('u') [0].ToString();
            a = a.Replace("-", "").Replace("Z", "");

            string date = a.Split(' ') [0];
            string hour = a.Split(' ') [1];

            string jsonStr = "";

            //Data
            PostData data = new PostData();
            data.cod  = GameController.Instance.nivelGenerator.nivel.frase;
            data.hora = hour;

            //NOtifiation
            PostNote not = new PostNote();
            not.title = "Fase completada!";
            not.body  = PlayerPrefs.GetString("child-name") + " completou a frase: " + GameController.Instance.nivelGenerator.nivel.frase + ". Parabenize-o!";
            not.icon  = "img/icone.png";

            PostObject aa = new PostObject();
            reference.Database.GetReference("children").GetValueAsync().ContinueWith(task => {
                if (task.IsCompleted)
                {
                    DataSnapshot snapshot = task.Result;
                    aa.data         = data;
                    aa.notification = not;
                    aa.to           = "/topics/" + snapshot.Child(PlayerPrefs.GetString("child")).Child("caregiver").Value.ToString();
                    jsonStr         = JsonUtility.ToJson(aa);

                    WWWForm form = new WWWForm();
                    form.AddField("name", "value");
                    Dictionary <string, string> headers = form.headers;
                    byte[] rawData = System.Text.Encoding.UTF8.GetBytes(jsonStr);
                    string url     = "https://fcm.googleapis.com/fcm/send";

                    // Add a custom header to the request.
                    // In this case a basic authentication to access a password protected resource.

                    headers ["Content-Type"]  = "application/json";
                    headers ["Authorization"] = "key=AIzaSyBqitOEyrJzCRCGhwDhg54jrj6h_HRLZC4";

                    /*
                     * headers.Add("Content-Type", "application/json");
                     * headers.Add("Authorization", "key=AIzaSyBqitOEyrJzCRCGhwDhg54jrj6h_HRLZC4");
                     */
                    // Post a request to an URL with our custom headers
                    WWW www = new WWW(url, rawData, headers);

                    StartCoroutine(WaitForRequest(www));
                }
            });
        }
    }