Ejemplo n.º 1
0
        public async Task <TaskResult> AddCard(Models.CardModel card)
        {
            if (!status)
            {
                return(new TaskResult(TaskResult.TaskName.addCard, false, TaskResult.TaskStatus.finished, null, "SDK ERROR : user not connected. Please connect user before trying to use this method"));
            }

            HttpResponseMessage rsp = await customHttpClient.performRequest(DejaMobileHttpClient.Request.addCard, card);

            if (rsp.StatusCode == System.Net.HttpStatusCode.Created)
            {
                string json = await DejaMobileHttpClient.getJsonFromHttpResponse(rsp);

                Models.CardModel digitizedCard = JsonConvert.DeserializeObject <Models.CardModel>(json);
                //add production date & description
                digitizedCard.description    = card.description;
                digitizedCard.productionDate = DateTime.Now.ToString();
                digitizedCard.uid            = Guid.NewGuid().ToString();

                if (storeCardInDb(digitizedCard))
                {
                    return(new TaskResult(TaskResult.TaskName.addCard, true, TaskResult.TaskStatus.finished, digitizedCard, "Card successfully added"));
                }
                else
                {
                    return(new TaskResult(TaskResult.TaskName.addCard, false, TaskResult.TaskStatus.finished, digitizedCard, "SDK ERROR : Card successfully added but an error has been thrown while trying to store card in database"));
                }
            }
            else
            {
                return(new TaskResult(TaskResult.TaskName.addCard, false, TaskResult.TaskStatus.finished, null, "SDK ERROR : error while trying to add a card")); //TODO : specific error handler
            }
        }
Ejemplo n.º 2
0
        public async Task <TaskResult> ConnectUser(Models.UserModel user)
        {
            HttpResponseMessage rsp = await customHttpClient.performRequest(DejaMobileHttpClient.Request.logUser, user);

            if (rsp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string json = await DejaMobileHttpClient.getJsonFromHttpResponse(rsp);

                Models.AuthJwtModel authJwt = JsonConvert.DeserializeObject <Models.AuthJwtModel>(json);
                onUserConnected(user, authJwt.token);
                return(new TaskResult(TaskResult.TaskName.logUser, true, TaskResult.TaskStatus.finished, null, "User successfully connected"));
            }
            else
            {
                onUserNotConnected();
                return(new TaskResult(TaskResult.TaskName.logUser, false, TaskResult.TaskStatus.finished, null, "ERROR while connecting user : " + rsp.StatusCode.ToString()));
            }
        }