public IActionResult Get(long id, string TagName)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var q = _tags.GetTags(id, TagName);

                    if (q != null)
                    {
                        return(Ok(q));
                    }

                    else
                    {
                        return(NoContent());
                    }
                }
                else
                {
                    return(BadRequest(id + TagName));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.InnerException.ToString()));
            }
        }
        public async Task <IActionResult> Get([FromQuery] string sort, [FromQuery] string search)
        {
            var tags = await _tagServices.GetTags(sort, search);

            if (sort != null)
            {
                switch (sort.ToLower())
                {
                case "name":
                    tags = tags.OrderBy(t => t.Name).ToList();
                    break;

                case "newest":
                    tags = tags.OrderByDescending(t => t.CreatedOn).ToList();
                    break;

                case "oldest":
                    tags = tags.OrderBy(t => t.CreatedOn).ToList();
                    break;

                default:
                    break;
                }
            }
            if (search != null)
            {
                tags = tags.Where(t => t.Name.ToLower().Contains(search.ToLower())).ToList();
            }
            if (tags.Count == 0)
            {
                return(NotFound(new { message = "No tags found." }));
            }
            return(Ok(tags));
        }
Example #3
0
        public ActionResult AddTagToArticle(int id)
        {
            SelectList tags = new SelectList(tagServices.GetTags(), "Text", "Text");

            ViewBag.tags = tags;
            ViewBag.id   = id;
            return(View());
        }
Example #4
0
        public async Task <IActionResult> Index(string sort, string search, int?pageNumber)
        {
            ViewData["CurrentSort"]        = sort;
            ViewData["SortByName"]         = sort == "name" ? "name_desc" : "name";
            ViewData["SortByDate"]         = sort == "newest" ? "oldest" : "newest";
            ViewData["SortByReportsCount"] = sort == "reports" ? "reports_asc" : "reports";
            ViewData["Search"]             = search;
            ViewData["PageNumber"]         = pageNumber;
            var tags = await _tagServices.GetTags(sort, search);

            int pageSize = 10;

            return(View(await tags.ToPagedListAsync(pageNumber ?? 1, pageSize)));
        }
 public ActionResult Tags(int page = 1, int pageSize = 20, string filter = null)
 {
     return(View(tagServices.GetTags(page, pageSize, filter)));
 }