Exemplo n.º 1
0
        public void AddBook(CreateBookData data)
        {
            var authors = _authorsRepository.GetAuthors(data.AuthorIds);
            var book    = new Book(data.Title,
                                   data.PageNumber,
                                   new DateTime(data.PublishYear, 1, 1),
                                   data.ISBN,
                                   authors,
                                   data.Publisher
                                   );

            _booksRepository.AddBook(book);
        }
Exemplo n.º 2
0
        private async Task <NewsViewModel> BuildEditNewsFeedViewModel()
        {
            var newsFeedViewModel = new NewsViewModel();
            var elections         = await _electionsRepository.GetElectionsForNewsFeed();

            newsFeedViewModel.Elections = new List <SelectListItem>();
            foreach (var election in elections.Value)
            {
                var electionGroup = new SelectListGroup {
                    Name = election.ElectionName
                };
                foreach (var ballot in election.Ballots)
                {
                    newsFeedViewModel.Elections.Add(new SelectListItem(ballot.Name, ballot.BallotId.ToString())
                    {
                        Group = electionGroup
                    });
                }
            }
            newsFeedViewModel.Date = DateTime.Now;

            newsFeedViewModel.SelectedElectionId = null;
            var authors = await _authorsRepository.GetAuthors();

            newsFeedViewModel.Authors = authors.Select(a => new SelectListItem(a.Name, a.Id.ToString())).ToList();
            return(newsFeedViewModel);
        }
Exemplo n.º 3
0
        public async Task <Models.Author[]> GetAuthors()
        {
            var result = await _authorRepository.GetAuthors();

            Models.Author[] authors = _mapper.Map <Models.Author[]>(result);
            return(authors);
        }
 public IActionResult Get(int authorId)
 {
     if (!authorsRepository.AuthorExists(authorId))
     {
         return(NotFound());
     }
     return(Ok(authorsRepository.GetAuthors()));
 }
Exemplo n.º 5
0
        public IEnumerable <Author> GetAuthors(string orderBy, bool showBooks)
        {
            orderBy = orderBy.ToLower();
            if (!allowedOrderByQueries.Contains(orderBy))
            {
                throw new InvalidOperationException($"Invalid \" {orderBy} \" orderBy query param. The allowed values are {string.Join(",", allowedOrderByQueries)}");
            }

            var authors = authorsRepository.GetAuthors();

            foreach (var author in authors)
            {
                if (showBooks)
                {
                    author.books = authorsRepository.GetBooks().Where(b => b.AuthorId == author.Id);
                }
                else
                {
                    author.books = null;
                }
            }

            switch (orderBy)
            {
            case "id":
                return(authors.OrderBy(a => a.Id));

            case "name":
                return(authors.OrderBy(a => a.Name));

            case "lastname":
                return(authors.OrderBy(a => a.LastName));

            case "nationallity":
                return(authors.OrderBy(a => a.Name));

            default:
                return(authors);
            }
        }
Exemplo n.º 6
0
 public IActionResult GetAll()
 {
     return(Ok(authorsRepository.GetAuthors()));
 }
Exemplo n.º 7
0
 public AuthorViewer()
 {
     InitializeComponent();
     _Repository          = new AuthorsRepository();
     gvAuthors.DataSource = _Repository.GetAuthors();
 }