コード例 #1
0
        public async Task <IActionResult> Create()
        {
            var authors = await _authorsService.ReadAll();

            var publishings = await _publishingsService.ReadAll();

            var technologies = await _technologiesService.ReadAll();

            authors.Sort(delegate(AuthorModel model, AuthorModel authorModel)
            {
                return(string.Compare(model.Surname, authorModel.Surname, StringComparison.Ordinal));
            });

            publishings.Sort(delegate(PublishingModel model, PublishingModel publishingModel)
            {
                return(string.Compare(model.Name, publishingModel.Name, StringComparison.Ordinal));
            });

            technologies.Sort(delegate(TechnologyModel model, TechnologyModel technologyModel)
            {
                return(string.Compare(model.Name, technologyModel.Name, StringComparison.Ordinal));
            });

            ViewBag.authors      = authors.ToSelectListItems();
            ViewBag.publishings  = publishings.ToSelectListItems();
            ViewBag.technologies = technologies.ToSelectListItems();

            return(View());
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            var technologies = await _technologiesService.ReadAll();

            List <SelectListItem> technologyList = new List <SelectListItem>();

            foreach (var technology in technologies)
            {
                SelectListItem item = new SelectListItem()
                {
                    Text  = technology.Name,
                    Value = technology.TechnologyGuid.ToString()
                };
                technologyList.Add(item);
            }

            ViewBag.technology = technologyList;


            List <SelectListItem> authorList = new List <SelectListItem>();
            var allBooks = await _booksService.ReadAll();

            var books = allBooks.Where(a => a.TechnologyModel.TechnologyGuid == technologies.First().TechnologyGuid).ToList();
            List <AuthorModel> authors = new List <AuthorModel>();

            foreach (var book in books)
            {
                authors.AddRange(book.AuthorModel);
            }

            foreach (var author in authors)
            {
                SelectListItem item = new SelectListItem()
                {
                    Text  = $"{author.Surname} {author.Name}",
                    Value = author.AuthorGuid.ToString()
                };
                authorList.Add(item);
            }

            ViewBag.author = authorList;

            return(View());
        }
コード例 #3
0
        public async Task <List <StatisticModel> > Statistic()
        {
            var technologies = await _technologiesService.ReadAll();

            List <StatisticModel> result = new List <StatisticModel>();

            foreach (var technology in technologies)
            {
                result.Add(new StatisticModel()
                {
                    Count      = _context.Books.Count(a => a.TechnologyGuid == technology.TechnologyGuid),
                    Technology = technology
                });
            }
            return(result);
        }
コード例 #4
0
        public async Task <IActionResult> ReadAll()
        {
            var result = await _technologiesService.ReadAll();

            return(View(result));
        }