コード例 #1
0
ファイル: ExternalDBService.cs プロジェクト: andyboniface/IE
        public async Task <IEMember> ModifyMember(string myUsername, IEMember member)
        {
            ExternalDBCommand cmd = new ExternalDBCommand();

            cmd.requestingUsername = myUsername;
            cmd.member             = member;

            var    dateTimeConverter = new IsoDateTimeConverter();
            string json = JsonConvert.SerializeObject(cmd, dateTimeConverter);

            var         httpClient = new HttpClient();
            HttpContent contents   = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage resp = await httpClient.PostAsync(MODIFY_MEMBER_URL, contents);

            if ((resp != null) && (resp.IsSuccessStatusCode))
            {
                //
                // We need to parse the results - somehow convert back into an array of IEMembers....
                //
                string jsonReply = await resp.Content.ReadAsStringAsync();

                _logger.LogInfo("ModifyMember reply= " + jsonReply);

                try
                {
                    IEMember replyMember = JsonConvert.DeserializeObject <IEMember>(jsonReply, dateTimeConverter);
                    return(replyMember);
                } catch (Exception e) {
                    _logger.LogError("ModifyMember error=" + e.Message);
                    _logger.LogError("Stack=" + e.StackTrace);
                }
            }
            return(null);
        }
コード例 #2
0
ファイル: ExternalDBService.cs プロジェクト: andyboniface/IE
        public async Task <List <IEMember> > FetchAllMembers(string myUsername)
        {
            ExternalDBCommand cmd = new ExternalDBCommand();

            cmd.requestingUsername = myUsername;

            string json = JsonConvert.SerializeObject(cmd);

            var         httpClient = new HttpClient();
            HttpContent contents   = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage resp = await httpClient.PostAsync(FETCH_ALL_URL, contents);

            if ((resp != null) && (resp.IsSuccessStatusCode))
            {
                //
                // We need to parse the results - somehow convert back into an array of IEMembers....
                //
                var dateTimeConverter = new IsoDateTimeConverter();

                string jsonReply = await resp.Content.ReadAsStringAsync();

                ExternalDBReply reply = JsonConvert.DeserializeObject <ExternalDBReply>(jsonReply, dateTimeConverter);

                return(reply.members.ToList <IEMember>());
            }
            return(new List <IEMember>());
        }
コード例 #3
0
ファイル: ExternalDBService.cs プロジェクト: andyboniface/IE
        public async Task <IEMember> AddNewMember(string myUsername, IEMember member)
        {
            ExternalDBCommand cmd = new ExternalDBCommand();

            cmd.requestingUsername = myUsername;
            cmd.member             = member;

            var    dateTimeConverter = new IsoDateTimeConverter();
            string json = JsonConvert.SerializeObject(cmd, dateTimeConverter);

            var         httpClient = new HttpClient();
            HttpContent contents   = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage resp = await httpClient.PostAsync(ADD_NEW_MEMBER_URL, contents);

            if ((resp != null) && (resp.IsSuccessStatusCode))
            {
                //
                // We need to parse the results - somehow convert back into an array of IEMembers....
                //
                string jsonReply = await resp.Content.ReadAsStringAsync();

                IEMember replyMember = JsonConvert.DeserializeObject <IEMember>(jsonReply, dateTimeConverter);
                return(replyMember);
            }
            return(null);
        }