コード例 #1
0
        public async Task <IActionResult> GetAuthor(Guid id)
        {
            try
            {
                if (id == Guid.Empty)
                {
                    return(BadRequest("invalid id"));
                }
                var author = await _authorServ.GetAuthorById(id);

                if (author == null)
                {
                    return(BadRequest("Author doesn't exist."));
                }

                var userViewModel = new AuthorListDto()
                {
                    Id         = author.Id,
                    AuthorName = author.AuthorName,
                    CreatedOn  = author.CreatedOn,
                    ModifiedOn = author.ModifiedOn
                };
                return(Ok(userViewModel));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
        public async Task <ServiceResult <AuthorListDto> > GetAllAuthors(PagingParams pagingParams)
        {
            try
            {
                var authorList = _unitOfWork.Repository <Author>().GetAll()
                                 .Include(c => c.BookAuthors)
                                 .ThenInclude(v => v.Book)
                                 .Select(b => new AuthorDto
                {
                    Name  = b.Name,
                    Year  = b.Year,
                    Books = b.BookAuthors.Select(ba => ba.Book.Title).ToList()
                });

                var paginatedList = await PaginatedList <AuthorDto>
                                    .CreateAsync(authorList, pagingParams.PageNumber, pagingParams.PageSize);

                var paginationDto = new PaginationDto
                {
                    HasNextPage     = paginatedList.HasNextPage,
                    HasPreviousPage = paginatedList.HasPreviousPage,
                    TotalPages      = paginatedList.TotalPages,
                    PageIndex       = paginatedList.PageIndex
                };

                var authorListDto = new AuthorListDto
                {
                    Authors    = paginatedList,
                    Pagination = paginationDto
                };

                return(Success(authorListDto));
            }
            catch
            {
                return(Error <AuthorListDto>("Can't receive all authors"));
            }
        }
コード例 #3
0
        public AuthorViewModel(AuthorListDto loggedAuthor, AddMultipleManuscriptService addMultipleManuscriptService, ListFrontAuthorService listFrontAuthorService) : this(new EfCoreContext())
        {
            InputManuscriptTitle          = "";
            LoggedAuthor                  = loggedAuthor;
            AuthorFirstName               = loggedAuthor.Name.Split(' ').First() + "!";
            _addMultipleManuscriptService = addMultipleManuscriptService;
            _listFrontAuthorService       = listFrontAuthorService;

            ManuscriptToAdd = new AddMultipleManuscriptDto
            {
                ManuscriptTitle = "",
            };

            _manuscriptService       = new ListManuscriptService(_context);
            _notificationService     = new ListNotificationService(_context);
            _authorManuscriptService = new ListAuthorManuscriptService(_context);

            var manuscripts       = _manuscriptService.GetManuscriptList().ToList();
            var notifications     = _notificationService.GetNotificationList().ToList();
            var authorManuscripts = _authorManuscriptService.GetAuthorManuscriptList().ToList();

            ManuscriptList       = new ObservableCollection <ManuscriptListDto>(manuscripts);
            NotificationList     = new ObservableCollection <NotificationListDto>(notifications);
            AuthorManuscriptList = new ObservableCollection <AuthorManuscriptListDto>(authorManuscripts);

            var notificationCounter = 1;

            foreach (var notification in NotificationList)
            {
                if (loggedAuthor.AuthorId == notification.AuthorId)
                {
                    notification.Message = notificationCounter + ". " + notification.Message;
                    notificationCounter++;
                    LoggedNotificationList.Add(notification);
                }
            }
            notificationCounter = 0;

            var manuscriptCounter = 1;
            var manuscriptIdBag   = new List <int>();

            foreach (var authorManuscript in AuthorManuscriptList)
            {
                if (authorManuscript.AuthorId == loggedAuthor.AuthorId)
                {
                    manuscriptIdBag.Add(authorManuscript.ManuscriptId);
                }
            }

            foreach (var manuscript in manuscriptIdBag)
            {
                foreach (var parentManuscript in ManuscriptList)
                {
                    if (manuscript == parentManuscript.ManuscriptId)
                    {
                        parentManuscript.ManuscriptTitle = manuscriptCounter + ". " + parentManuscript.ManuscriptTitle;
                        manuscriptCounter++;
                        LoggedManuscriptList.Add(parentManuscript);
                    }
                }
            }
            manuscriptIdBag.Clear();
            manuscriptCounter = 0;

            FrontAuthorList = GetAuthorSelectionList();
        }