Пример #1
0
        /// <summary>
        /// Remove Author.
        /// </summary>
        /// <param name="request">The Author Request Pivot to remove.</param>
        public void DeleteAuthor(AuthorRequestPivot request)
        {
            if (request?.AuthorPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Author author = _unitOfWork.AuthorRepository.GetById(request.AuthorPivot.AuthorId);

            _unitOfWork.AuthorRepository.Delete(author);
            _unitOfWork.Save();
        }
Пример #2
0
        /// <summary>
        /// Change Author values.
        /// </summary>
        /// <param name="request">The Author Request Pivot to change.</param>
        public void UpdateAuthor(AuthorRequestPivot request)
        {
            if (request?.AuthorPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Author author = _unitOfWork.AuthorRepository.GetById(request.AuthorPivot.AuthorId);

            author.AuthorFirstName = request.AuthorPivot.AuthorFirstName;
            author.AuthorLastName  = request.AuthorPivot.AuthorLastName;
            _unitOfWork.Save();
        }
Пример #3
0
        /// <summary>
        /// Create new Author.
        /// </summary>
        /// <param name="request">The Author Request Pivot to add.</param>
        /// <returns>Author Response Pivot created.</returns>
        public AuthorResponsePivot CreateAuthor(AuthorRequestPivot request)
        {
            if (request?.AuthorPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            Author author = request.AuthorPivot.ToEntity();

            _unitOfWork.AuthorRepository.Insert(author);
            _unitOfWork.Save();
            return(new AuthorResponsePivot
            {
                AuthorPivot = author.ToPivot()
            });
        }
Пример #4
0
        /// <summary>
        /// Search Author by id.
        /// </summary>
        /// <param name="request">The Author Request Pivot to retrive.</param>
        /// <returns>Author Response Pivot response.</returns>
        public AuthorResponsePivot FindAuthors(AuthorRequestPivot request)
        {
            if (request?.AuthorPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            List <AuthorPivot> results = new List <AuthorPivot>();
            AuthorPivot        result  = new AuthorPivot();

            switch (request.FindAuthorPivot)
            {
            case FindAuthorPivot.AuthorId:
                result = _unitOfWork.AuthorRepository.GetById(request.AuthorPivot.AuthorId)?.ToPivot();
                break;
            }
            return(new AuthorResponsePivot
            {
                AuthorPivotList = results,
                AuthorPivot = result
            });
        }