Beispiel #1
0
 public IEnumerable <PostViewModel> GetPostsByUserNameWithoutCategory(string userName)
 {
     try
     {
         var result = PostServiceHttpClient.GetAsync(ADDRESS + "getuserpostswithoutcategory/" + userName).Result;
         return(result.Content.ReadAsAsync <IEnumerable <PostViewModel> >().Result);
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }
Beispiel #2
0
 public IEnumerable <PostViewModel> GetUserPostsByUserName(string userName)
 {
     try
     {
         var result = PostServiceHttpClient.GetAsync(ADDRESS + "getuserpostsbyusername/" + userName).Result;
         return(result.Content.ReadAsAsync <PostViewModel[]>().Result.ToEnumerable());
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }
Beispiel #3
0
 public IEnumerable <PostViewModel> GetUserPosts(int userId)
 {
     try
     {
         var result = PostServiceHttpClient.GetAsync(ADDRESS + "getuserposts/" + userId).Result;
         return(result.Content.ReadAsAsync <IEnumerable <PostViewModel> >().Result);
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }
Beispiel #4
0
 public int DeletePost(PostViewModel postViewModel)
 {
     try
     {
         var result = PostServiceHttpClient.PostAsync(ADDRESS + "deletepost", new StringContent(JsonConvert.SerializeObject(postViewModel), Encoding.UTF8, "application/json")).Result;
         return(result.Content.ReadAsAsync <int>().Result);
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }
Beispiel #5
0
 public PostViewModel GetPost(int postId)
 {
     try
     {
         var result = PostServiceHttpClient.GetAsync(ADDRESS + "getpost/" + postId).Result;
         return(result.Content.ReadAsAsync <PostViewModel>().Result);
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }
Beispiel #6
0
 public int UpdatePost(PostViewModel postViewModel, List <CategoryViewModel> categoryViewModelList)
 {
     try
     {
         postViewModel.Categories = categoryViewModelList.ToArray();
         var result = PostServiceHttpClient.PostAsync(ADDRESS + "updatepost", new StringContent(JsonConvert.SerializeObject(postViewModel), Encoding.UTF8, "application/json")).Result;
         return(result.Content.ReadAsAsync <int>().Result);
     }
     catch (FaultException ex)
     {
         throw new ApplicationException(ex.Message);
     }
 }