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())); } }
public ArticleModel Update(ArticleModel articleModelToUpdate) { var updated = _unitOfWorkRepository.Articles.Update(articleModelToUpdate.ToArticle()); return(updated.ToArticleModel()); }
public async Task <IHttpActionResult> Update(ArticleModel article) { await repository.Update(article.ToArticle()); return(Ok()); }
public ArticleModel Add(ArticleModel articleModel) { var addedArticle = _unitOfWorkRepository.Articles.Add(articleModel.ToArticle()); return(addedArticle.ToArticleModel()); }