Example #1
0
        /// <summary>
        /// Search PublicationTranslation by id.
        /// </summary>
        /// <param name="request">The PublicationTranslation Request Pivot to retrive.</param>
        /// <returns>PublicationTranslation Response Pivot response.</returns>
        public PublicationTranslationResponsePivot FindPublicationTranslations(PublicationTranslationRequestPivot request)
        {
            if (request?.PublicationTranslationPivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            List <PublicationTranslationPivot> results = new List <PublicationTranslationPivot>();
            PublicationTranslationPivot        result  = new PublicationTranslationPivot();

            switch (request.FindPublicationTranslationPivot)
            {
            case FindPublicationTranslationPivot.PublicationTranslationId:
                result = _unitOfWork.PublicationTranslationRepository
                         .Get(
                    p => p.PublicationTranslationId ==
                    request.PublicationTranslationPivot.PublicationTranslationId, null,
                    "Publication,Language")?.FirstOrDefault().ToPivot();
                break;

            case FindPublicationTranslationPivot.PublicationId:
                results = _unitOfWork.PublicationTranslationRepository
                          .Get(p => p.PublicationId == request.PublicationTranslationPivot.PublicationId, null,
                               "Publication,Language")?.ToList().ToPivotList();
                break;
            }
            return(new PublicationTranslationResponsePivot
            {
                PublicationTranslationPivotList = results,
                PublicationTranslationPivot = result
            });
        }
 /// <summary>
 /// From PublicationTranslationPivot to PublicationTranslation.
 /// </summary>
 /// <param name="publicationTranslationPivot">publicationTranslationPivot to assemble.</param>
 /// <returns>PublicationTranslation result.</returns>
 public static PublicationTranslation ToEntity(this PublicationTranslationPivot publicationTranslationPivot)
 {
     if (publicationTranslationPivot == null)
     {
         return(null);
     }
     return(new PublicationTranslation
     {
         PublicationTranslationId = publicationTranslationPivot.PublicationTranslationId,
         PublicationSummary = publicationTranslationPivot.PublicationSummary,
         Publication = publicationTranslationPivot.Publication.ToEntity(),
         PublicationTitle = publicationTranslationPivot.PublicationTitle,
         PublicationFile = publicationTranslationPivot.PublicationFile,
         Language = publicationTranslationPivot.Language.ToEntity(),
         PublicationId = publicationTranslationPivot.PublicationId,
         LanguageId = publicationTranslationPivot.LanguageId
     });
 }
        /// <summary>
        /// Search PublicationTheme.
        /// </summary>
        /// <param name="request">The PublicationTheme Request Pivot to retrive.</param>
        /// <returns>PublicationTheme Response Pivot response.</returns>
        public PublicationThemeResponsePivot FindPublicationThemes(PublicationThemeRequestPivot request)
        {
            if (request?.PublicationThemePivot == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

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

            List <PublicationTranslationPivot> publicationTranslationPivotList = new List <PublicationTranslationPivot>();
            PublicationTranslationPivot        publicationTranslationPivot     = new PublicationTranslationPivot();

            List <ThemeTranslationPivot> themeTranslationPivotList = new List <ThemeTranslationPivot>();
            ThemeTranslationPivot        themeTranslationPivot     = new ThemeTranslationPivot();

            switch (request.FindPublicationThemePivot)
            {
            case FindPublicationThemePivot.PublicationThemeId:
                result = _unitOfWork.PublicationThemeRepository
                         .Get(p => p.PublicationThemeId == request.PublicationThemePivot.PublicationThemeId)
                         ?.FirstOrDefault().ToPivot();

                themeTranslationPivot = _unitOfWork.ThemeTranslationRepository
                                        .Get(t => t.ThemeId == request.PublicationThemePivot.ThemeId).FirstOrDefault().ToPivot();

                publicationTranslationPivot = _unitOfWork.PublicationTranslationRepository
                                              .Get(p => p.PublicationId == request.PublicationThemePivot.PublicationId).FirstOrDefault()
                                              .ToPivot();
                break;

            case FindPublicationThemePivot.PublicationId:
                results = _unitOfWork.PublicationThemeRepository
                          .Get(p => p.PublicationId == request.PublicationThemePivot.PublicationId)?.ToList()
                          .ToPivotList();

                if (results != null)
                {
                    foreach (PublicationThemePivot publicationThemePivot in results)
                    {
                        publicationTranslationPivotList.AddRange(_unitOfWork.PublicationTranslationRepository
                                                                 .Get(p => p.PublicationId == publicationThemePivot.PublicationId).ToList()
                                                                 .ToPivotList());

                        themeTranslationPivotList.AddRange(_unitOfWork.ThemeTranslationRepository
                                                           .Get(t => t.ThemeId == publicationThemePivot.ThemeId).ToList()
                                                           .ToPivotList());
                    }
                }
                break;

            case FindPublicationThemePivot.ThemeId:
                results = _unitOfWork.PublicationThemeRepository
                          .Get(p => p.ThemeId == request.PublicationThemePivot.ThemeId)?.ToList().ToPivotList();

                if (results != null)
                {
                    foreach (PublicationThemePivot publicationThemePivot in results)
                    {
                        publicationTranslationPivotList.AddRange(_unitOfWork.PublicationTranslationRepository
                                                                 .Get(p => p.PublicationId == publicationThemePivot.PublicationId).ToList()
                                                                 .ToPivotList());

                        themeTranslationPivotList.AddRange(_unitOfWork.ThemeTranslationRepository
                                                           .Get(t => t.ThemeId == publicationThemePivot.ThemeId).ToList()
                                                           .ToPivotList());
                    }
                }
                break;

            case FindPublicationThemePivot.PublicationIdAndThemeId:
                result = _unitOfWork.PublicationThemeRepository
                         .Get(
                    p => p.ThemeId == request.PublicationThemePivot.ThemeId &&
                    p.PublicationId == request.PublicationThemePivot.PublicationId
                    )?.FirstOrDefault().ToPivot();

                themeTranslationPivot = _unitOfWork.ThemeTranslationRepository
                                        .Get(t => t.ThemeId == request.PublicationThemePivot.ThemeId).FirstOrDefault().ToPivot();

                publicationTranslationPivot = _unitOfWork.PublicationTranslationRepository
                                              .Get(p => p.PublicationId == request.PublicationThemePivot.PublicationId).FirstOrDefault()
                                              .ToPivot();
                break;
            }
            return(new PublicationThemeResponsePivot
            {
                PublicationTranslationPivotList = publicationTranslationPivotList,
                PublicationTranslationPivot = publicationTranslationPivot,

                ThemeTranslationPivotList = themeTranslationPivotList,
                ThemeTranslationPivot = themeTranslationPivot,

                PublicationThemePivotList = results,
                PublicationThemePivot = result
            });
        }