public DetailResponse <ArticleDto> GetDetail(int?id) { int articleId = (int)id; var response = new DetailResponse <ArticleDto>(); if (id == null) { response.Code = MessageCode.NullPointer; response.Message = ErrorConstant.Get(MessageCode.NullPointer); response.Status = false; return(response); } Article article = _unitOfWork.Article.Table.Where(p => p.Id == articleId).FirstOrDefault(); if (article == null) { response.Code = MessageCode.BE0002; response.Message = ErrorConstant.Get(MessageCode.BE0002); response.Status = false; return(response); } response.Status = true; response.Data = mapToArticleResponse(article); return(response); }
public DetailResponse <int> Inactive(int?id) { try { int articleId = (int)id; Article article = findById(articleId); if (article == null) { return(new DetailResponse <int>() { Status = false, Code = MessageCode.NullPointer, Message = ErrorConstant.Get(MessageCode.NullPointer), Data = articleId }); } article.Inactive(); _unitOfWork.Article.Update(article); return(new DetailResponse <int>() { Status = true, Data = articleId }); } catch (VnsException exception) { return(new DetailResponse <int>() { Status = false, Code = MessageCode.Exception, Message = ErrorConstant.GetMessageWithData(MessageCode.Exception, exception.Message) }); } }
public JsonResult CreateArticle(ArticleDto article) { DetailResponse <ArticleDto> result = new DetailResponse <ArticleDto>(); if (article.Title == null) { result = new DetailResponse <ArticleDto> { Status = false, Data = article, Message = ErrorConstant.Get(MessageCode.BE0003) }; return(Json(result)); } if (article.Description == null) { result = new DetailResponse <ArticleDto> { Status = false, Data = article, Message = ErrorConstant.Get(MessageCode.BE0004) }; return(Json(result)); } result = _articleRepository.Insert(article); return(Json(result)); }
public DetailResponse <int> Approve(int?id) { var response = new DetailResponse <int>(); if (id == null) { response.Code = MessageCode.NullPointer; response.Message = ErrorConstant.Get(MessageCode.NullPointer); response.Status = false; return(response); } Article article = findById(id); if (article == null) { response.Data = (int)id; response.Code = MessageCode.BE0002; response.Message = ErrorConstant.Get(MessageCode.BE0002); response.Status = false; return(response); } article.ApproveEntity(); try { _unitOfWork.Article.Update(article); _unitOfWork.Article.SaveChanges(); response.Data = (int)id; response.Status = true; } catch (Exception exception) { response.Code = MessageCode.BE0001; response.Message = ErrorConstant.GetMessageWithData(MessageCode.BE0001, exception.Message); response.Status = false; } return(response); }
public string GetMessage(MessageCode code, string str) { return(str == null?ErrorConstant.Get(code) : ErrorConstant.GetMessageWithData(code, str)); }