示例#1
0
        public string AddFeeder(Feeder feeder)
        {
            feeder.OwnerID = _currentUserData.GetUser().UserID;
            Response response = _feederDAO.AddFeeder(feeder);

            if (response == null)
            {
                return("shit happens");
            }

            Feeder newFeeder = new Feeder(response.body);

            _currentUserData.AddFeeder(newFeeder);
            string message = response.headers["message"];

            return(message);
        }
示例#2
0
        public FeedersResponse GetFeeders()
        {
            string requestString = JsonSerializer.Serialize <User>(_currentUserData.GetUser());

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(GetFeedersURL);

            request.Headers.Add(apiKeyHeader);
            request.Method = "POST";
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(requestString);
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }

            HttpWebResponse httpWebResponse = (HttpWebResponse)request.GetResponse();
            FeedersResponse response;

            try
            {
                using (Stream stream = httpWebResponse.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        string responseString = reader.ReadToEnd();
                        response = JsonSerializer.Deserialize <FeedersResponse>(responseString);
                    }
                }
            }
            catch (JsonException e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
            httpWebResponse.Close();

            return(response);
        }