public ResponseResultDto <bool> UpdateArticle(MsgArticleDto article) { ResponseResultDto <bool> result = new ResponseResultDto <bool>(); try { int count = this.articleRepository.Query(p => p.Id == article.Id).Count(); if (count <= 0) { result.ErrorMessage = "记录不存在或已删除"; } else { MsgArticleEntity entity = new MsgArticleEntity() { Id = article.Id, Author = article.Author, CategoryId = article.CategoryId, CreatedTime = article.CreatedTime, MsgContent = article.MsgContent, Title = article.Title }; this.articleRepository.Update(entity); result.IsSuccess = this.articleRepository.SaveChanged() > 0; result.Result = result.IsSuccess; } } catch (Exception ex) { result.IsSuccess = false; result.ErrorMessage = "服务错误"; } return(result); }
public ResponseResultDto <bool> AddArticle(MsgArticleDto article) { ResponseResultDto <bool> result = new ResponseResultDto <bool>(); try { MsgArticleEntity entity = new MsgArticleEntity() { Id = article.Id, Author = article.Author, CategoryId = article.CategoryId, CreatedTime = article.CreatedTime, MsgContent = article.MsgContent, Title = article.Title }; this.articleRepository.Insert(entity); result.IsSuccess = this.articleRepository.SaveChanged() > 0; result.Result = result.IsSuccess; } catch (Exception ex) { result.IsSuccess = false; result.ErrorMessage = "服务错误"; } return(result); }
public IActionResult InsertOrUpdate(MsgArticleDto article) { object result = null; ResponseResultDto <bool> response = null; if (article.Id <= 0) { response = articleService.AddArticle(article); } else { response = articleService.UpdateArticle(article); } result = new { success = response.IsSuccess, error = response.ErrorMessage }; return(Json(result)); }