Ejemplo n.º 1
0
        public IHttpActionResult Read(string id)
        {
            var article = ArticlesRepository.Get(id);

            if (article != null)
            {
                return(Ok(article));
            }
            else
            {
                return(NotFound());
            }
        }
Ejemplo n.º 2
0
        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());
            }
        }
Ejemplo n.º 3
0
        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"));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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());
            }
        }
Ejemplo n.º 6
0
        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());
            }
        }
Ejemplo n.º 7
0
        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 = "تصویر با موفقیت آپلود شد"
            }));
        }
Ejemplo n.º 8
0
 public IQueryable <Article> GetArticles()
 {
     return(articles.Get().Include(x => x.Store));
 }