Ejemplo n.º 1
0
        /// <summary>
        /// Method to select a <see cref="PictureEntity"/> by its unique identifier or primar key.
        /// </summary>
        /// <param name="query">A <see cref="IQueryable"/> query of <see cref="PictureEntity"/>.</param>
        /// <param name="op">The <see cref="PictureOptionsSelect"/> options filters.</param>
        /// <returns>A <see cref="PictureEntity"/> or null if not found.</returns>
        private PictureEntity SingleIdOrNull(IQueryable <PictureEntity> query, PictureOptionsSelect op)
        {
            PictureEntity entity = query.SingleOrDefault(x => x.PictureId == op.PrimaryKey);

            // Check if user is found, return null instead of default.
            if (entity != null && entity.AlbumId == 0)
            {
                return(null);
            }

            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method to select a <see cref="PictureEntity"/>.
        /// </summary>
        /// <param name="op">Picture entities select options to perform query.</param>
        /// <param name="nullable"></param>
        /// <returns>An Picture entity or null if not found.</returns>
        /// <exception cref="ArgumentNullException">Occurs if Picture Select Options are null <see cref="PictureOptionsSelect"/></exception>
        public PictureEntity Select(PictureOptionsSelect op, bool nullable = false)
        {
            log.Debug($"{GetType().Name}.{MethodBase.GetCurrentMethod().Name} : {op?.GetType()}");

            if (op == null)
            {
                ArgumentNullException e = Exceptions.GetArgumentNull(nameof(op), typeof(PictureOptionsSelect));
                log.Error($"{GetType().Name}.{MethodBase.GetCurrentMethod().Name} : {e.Output()}");
                throw e;
            }

            if (!SetSafeUser(op.UserId))
            {
                return(null);
            }

            // Initialize query.
            IQueryable <PictureEntity> query = Connector.Pictures;

            // Load dependencies if required.
            QueryDependencies(ref query, op);

            if (op.PrimaryKey > 0)
            {
                query = query.Where(x => x.PrimaryKey == op.PrimaryKey);
            }

            if (!op.Alias.IsNullOrWhiteSpace())
            {
                query = query.Where(x => x.Alias == op.Alias);
            }

            // Filter by User.
            //if (entity != null && user != null)
            //{
            //    SectionEntity section = null;

            //    foreach (AlbumsInSections sectDep in entity.AlbumsInSections)
            //    {
            //        IQueryable<SectionEntity> sections = Connector.Sections;
            //        sections = sections.Include(x => x.SectionsInAclGroups);
            //        SectionEntity s = sections.SingleOrDefault(x => x.PrimaryKey == sectDep.SectionId);

            //        if (s.PrimaryKey == 0)
            //        {
            //            return null;
            //        }

            //        foreach (SectionsInAclGroups aclgDep in s.SectionsInAclGroups)
            //        {
            //            section = GetUserSection(aclgDep.SectionId, user);
            //            if (section != null && section.PrimaryKey > 0) break;
            //        }

            //        if (section != null && section.PrimaryKey > 0) break;
            //    }

            //    if (section == null)
            //    {
            //        return null;
            //    }
            //}

            return(SingleDefaultOrNull(query, nullable));
        }