public IHttpActionResult Read(string id) { var article = ArticlesRepository.Get(id); if (article != null) { return(Ok(article)); } else { return(NotFound()); } }
public IHttpActionResult Create(string id, string name, string content) { var exists = ArticlesRepository.Get(id) != null; if (exists) { return(StatusCode(HttpStatusCode.Conflict)); } else { ArticlesRepository.Add(id, name, content); return(Ok()); } }
public ActionResult DeleteConfirmed(int id) { var article = _repo.Get(id); //#region Delete Article Image //if (article.Image != null) //{ // if (System.IO.File.Exists(Server.MapPath("/Files/ArticleImages/Image/" + article.Image))) // System.IO.File.Delete(Server.MapPath("/Files/ArticleImages/Image/" + article.Image)); // if (System.IO.File.Exists(Server.MapPath("/Files/ArticleImages/Thumb/" + article.Image))) // System.IO.File.Delete(Server.MapPath("/Files/ArticleImages/Thumb/" + article.Image)); //} //#endregion _repo.Delete(id); return(RedirectToAction("Index")); }
public BlogDetailDto GetBlogArticleDetail(int id) { var repos = new ArticlesRepository(_context, new LogsRepository(_context)); var detail = repos.Get(id); var blogDto = new BlogDetailDto(detail, _currentLang); var categories = _context.ArticleCategories.Where(w => !w.IsDeleted).Select(s => new BlogCategoryModel { Id = s.Id, Title = _currentLang == (int)Language.Farsi ? s.Title : s.EnglishTitle }).ToList(); blogDto.Categories.AddRange(categories); blogDto.RecentBlogs = repos.GetArticles().Select(s => new BlogViewModel(s, _currentLang)).ToList(); return(blogDto); }
public IHttpActionResult Delete(string id) { var existArticle = ArticlesRepository.Get(id) != null; if (existArticle) { var succesfullyRemoved = ArticlesRepository.Delete(id); if (succesfullyRemoved) { return(Ok()); } else { return(StatusCode(HttpStatusCode.InternalServerError)); } } else { return(NotFound()); } }
public IHttpActionResult Update(string id, string name, string content) { var article = ArticlesRepository.Get(id); if (article != null) { var success = ArticlesRepository.Update(id, name, content); if (success) { return(Ok()); } else { return(StatusCode(HttpStatusCode.InternalServerError)); } } else { return(NotFound()); } }
public async Task <IActionResult> UploadImage(int id, [FromForm] IFormFile file) { if (file == null) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response <ArticleDetailDto>() { Succeeded = false, Message = "لطفا تصویر مقاله را آپلود کنید" })); } if (await _repo.Get(id) == null) { return(StatusCode(StatusCodes.Status500InternalServerError, new Response <ArticleDetailDto>() { Succeeded = false, Message = "مقاله پیدا نشد" })); } var result = await _repo.UploadArticleImage(id, file); return(Ok(new Response <ArticleDetailDto>(result) { Message = "تصویر با موفقیت آپلود شد" })); }
public IQueryable <Article> GetArticles() { return(articles.Get().Include(x => x.Store)); }