private PostWCF postWCFChanger(Post post)
        {
            var t = new PostWCF();

            t.Content = post.Content;
            t.Date    = post.Date;
            t.Title   = post.Title;
            t.User    = post.User;
            return(t);
        }
Esempio n. 2
0
        public async Task <string> AddPost(PostWCF post)
        {
            var jsonObject = JsonConvert.SerializeObject(post);
            var content    = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await _client.PostAsync("Blog/AddPost", content);

            if (response.IsSuccessStatusCode)
            {
                var wcfResponse = await response.Content.ReadAsAsync <string>();

                return(wcfResponse);
            }
            return("Error");
        }
Esempio n. 3
0
        // Posts

        public string AddPost(PostWCF post)
        {
            logger.Info("Registeres POST request - attempting to add new post.");
            var response = _userController.Exist(JObject.Parse("{\"username\": \"" + post.User + "\"}"));

            if ((Boolean)response["exist"])
            {
                var calories = getCalories(post.Content);
                var content1 = post.Content + " Counted calories:" + calories;
                var postDB   = new Post()
                {
                    User = post.User, Content = content1, Date = post.Date, Title = post.Title
                };
                _blogContext.Posts.Add(postDB);
                _blogContext.SaveChanges();
                logger.Info("New post added.");
                return("Post added");
            }
            else
            {
                logger.Info("Cannot add Post - there is no such user.");
                return("There is no such user");
            }
        }