// GET: Periodical
        public ActionResult Index(string sortOrder)
        {
            var modelBL   = _periodical.GetAll().ToList();
            var modelView = _mapper.Map <IEnumerable <PeriodicalModel> >(modelBL);

            if (!User.IsInRole("Admin"))
            {
                var hz = _topic.GetAll().Where(x => x.Name.Contains("XXX")).FirstOrDefault();
                modelView = modelView.Where(p => p.TopicId != hz.Id);
            }

            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            switch (sortOrder)
            {
            case "name_desc":
                modelView = modelView.OrderByDescending(s => s.Name);
                break;

            case "Number":
                modelView = modelView.OrderBy(s => s.NumberOfPublications);
                break;

            case "number_desc":
                modelView = modelView.OrderByDescending(s => s.NumberOfPublications);
                break;

            default:
                modelView = modelView.OrderBy(s => s.Name);
                break;
            }

            return(View(modelView));
        }
Esempio n. 2
0
        public ActionResult Json()
        {
            var periodiaclBL   = _periodical.GetAll().ToList();
            var periodiaclView = _mapper.Map <IEnumerable <PeriodicalModel> >(periodiaclBL);

            var filteredData = periodiaclView.Select(c => new { c.Id, c.Name, c.ImageName });

            var listOfData = JsonConvert.SerializeObject(filteredData, Formatting.None,
                                                         new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Json(listOfData, JsonRequestBehavior.AllowGet));
        }
 public IEnumerable <PeriodicalDto> Get()
 {
     return(_periodicalService.GetAll().ToDto());
 }