Ejemplo n.º 1
0
 private IDictionary <Guid, Guid> FindTestResultsByKidProfile(KidProfile kidProfile)
 {
     return(Connection
            .Query <KeyValuePair <Guid, Guid> >(
                "SELECT [SkillId] AS [Key], [LevelId] AS [Value] FROM [TestResult] WHERE [KidProfileId]=@KidProfileId",
                kidProfile).ToDictionary(kv => kv.Key, kv => kv.Value));
 }
Ejemplo n.º 2
0
        public void Add(KidProfile kidProfile)
        {
            var shouldOpen = Connection.State != ConnectionState.Open;

            if (shouldOpen)
            {
                Connection.Open();
            }
            Connection.Execute(@"INSERT INTO [KidProfile]([KidId],[KidProfileId],[CreateDateTime])
VALUES (@KidId,@KidProfileId,@CreateDateTime)", kidProfile);
            if (kidProfile.TestResult != null)
            {
                foreach (var kv in kidProfile.TestResult)
                {
                    Connection.Execute(@"INSERT INTO [TestResult]([KidProfileId],[SkillId],[LevelId])
VALUES (@KidProfileId,@SkillId,@LevelId)", new { kidProfile.KidProfileId, SkillId = kv.Key, LevelId = kv.Value });
                }
            }
            if (shouldOpen)
            {
                Connection.Close();
            }
        }
Ejemplo n.º 3
0
    public async Task <bool> PutCreateChild(string nomeCrianca, string dataNascimento, string genero, Int64 imageId)
    {
        PersonDTO currentUser = new PersonDTO();

        try
        {
            currentUser = JsonConvert.DeserializeObject <PersonDTO>(PlayerPrefs.GetString(ConstantClass.CURRENT_USER));
            Debug.Log(PlayerPrefs.GetString(ConstantClass.CURRENT_USER));

            //Atualizamos o objeto do usuário adicionando mais uma criança ao objeto do usuário.
            if (currentUser.kids == null)
            {
                currentUser.kids = new List <KidProfile>();
            }

            currentUser.kids.Add(new KidProfile
            {
                name      = nomeCrianca,
                birthDate = dataNascimento,
                genre     = genero,
                imageId   = imageId,
                franchise = FavoriteController.favoriteFranchiseIdList
            });


            //Tentamos subir o objeto através de um PUT.
            var dadosPOST = JsonConvert.SerializeObject(currentUser);
            Debug.Log(dadosPOST);

            var dados         = Encoding.UTF8.GetBytes(dadosPOST);
            var requisicaoWeb = WebRequest.CreateHttp(ConstantClass.SERVER_URL + "Person/");

            requisicaoWeb.Method        = "PUT";
            requisicaoWeb.ContentType   = "application/json";
            requisicaoWeb.ContentLength = dados.Length;
            requisicaoWeb.UserAgent     = "RequisicaoWebDemo";

            Loading.instance.StartLoading();

            //precisamos escrever os dados post para o stream
            using (var stream = requisicaoWeb.GetRequestStream())
            {
                stream.Write(dados, 0, dados.Length);
                stream.Close();
            }

            using (var resposta = await requisicaoWeb.GetResponseAsync())
            {
                Debug.Log(resposta);
                var          streamDados = resposta.GetResponseStream();
                StreamReader reader      = new StreamReader(streamDados);
                object       objResponse = reader.ReadToEnd();

                var userConvert = JsonConvert.DeserializeObject <PersonDTO>(objResponse.ToString());

                KidProfile kid        = userConvert.kids[userConvert.kids.Count - 1];
                var        currentKid = JsonConvert.SerializeObject(kid);
                PlayerPrefs.SetString(ConstantClass.CURRENT_KID, currentKid.ToString());
                CurrentStatsInfo.currentKid = JsonConvert.DeserializeObject <KidProfile>(objResponse.ToString());
                Debug.Log(PlayerPrefs.GetString(ConstantClass.CURRENT_KID));

                PlayerPrefs.SetString(ConstantClass.CURRENT_USER, objResponse.ToString());
                CurrentStatsInfo.currentUser = JsonConvert.DeserializeObject <PersonDTO>(objResponse.ToString());
                streamDados.Close();
                resposta.Close();
            }
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.ProtocolError)
            {
                if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest)
                {
                    Debug.LogError("Tipo ou parâmetro do objeto não corresponde ao servidor. 400 Bad Request");
                    Message.instance.Show(MessageClass.ERROR_BAD_REQUEST);

                    return(false);
                }
                else if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.InternalServerError)
                {
                    Debug.LogError("WebException, HttpWebResponse 500 Internal Server Error");
                    Message.instance.Show(MessageClass.ERROR_INTERNAL_SERVER);
                    return(false);
                }
                else if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.GatewayTimeout)
                {
                    Debug.LogError("WebException, HttpWebResponse 504 Gateway Timeout");
                    Message.instance.Show(MessageClass.ERROR_GATEWAY_TIMEOUT);
                    return(false);
                }
                else
                {
                    Debug.Log(((HttpWebResponse)ex.Response).StatusCode);
                    return(false);
                }
            }
        }
        finally
        {
            Loading.instance.StopLoading();
        }

        return(true);
    }
Ejemplo n.º 4
0
 public void Add(KidProfile kidProfile)
 {
     KidProfileRepository.Add(kidProfile);
 }