コード例 #1
0
        public async Task <ActionResult> Create(ArticleModel article)
        {
            if (!ModelState.IsValid)
            {
                return(View(article.ToArticle()));
            }
            try
            {
                using (var client = new HttpClient())
                {
                    StringContent content = new StringContent(
                        JsonConvert.SerializeObject(article, Formatting.None, new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    }),
                        Encoding.UTF8,
                        "application/json");

                    var response = await client.PostAsync($"{url}Add", content);

                    response.EnsureSuccessStatusCode();
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View(article.ToArticle()));
            }
        }
コード例 #2
0
        public ArticleModel Update(ArticleModel articleModelToUpdate)
        {
            var updated = _unitOfWorkRepository.Articles.Update(articleModelToUpdate.ToArticle());

            return(updated.ToArticleModel());
        }
コード例 #3
0
        public async Task <IHttpActionResult> Update(ArticleModel article)
        {
            await repository.Update(article.ToArticle());

            return(Ok());
        }
コード例 #4
0
        public ArticleModel Add(ArticleModel articleModel)
        {
            var addedArticle = _unitOfWorkRepository.Articles.Add(articleModel.ToArticle());

            return(addedArticle.ToArticleModel());
        }