public Obj.PreservationTask GetPreservationTask(Guid idTask, bool fillRelations = true)
        {
            Obj.PreservationTask retval = null;

            try
            {
                System.Data.Objects.ObjectQuery <Model.PreservationTask> query = db.PreservationTask;
                if (fillRelations)
                {
                    query = query.Include(x => x.Archive)
                            .Include(x => x.PreservationTaskType)
                            .Include(x => x.PreservationTask1)
                            .Include(x => x.PreservationTask1.First().Archive)
                            .Include(x => x.PreservationTask1.First().PreservationTaskType);
                }
                Model.PreservationTask preservationTask = query.Where(x => x.IdPreservationTask == idTask).SingleOrDefault();

                if (preservationTask != null)
                {
                    retval = preservationTask.Convert(DEFAULT_LEVEL, DEFAULT_DEEP_LEVEL);
                }
            }
            finally
            {
                Dispose();
            }

            return(retval);
        }
Example #2
0
        /// <summary>
        ///		No Metadata Documentation available.
        /// </summary>
        /// <param name="apiContext"></param>
        /// <param name="querySettings"></param>
        /// <param name="imageTypes"></param>
        /// <returns></returns>
        public static Helpers.ActionResult Get(Helpers.ApiContext apiContext, Helpers.QuerySettings <Entities.ImageType> querySettings, out System.Collections.Generic.List <Entities.ImageType> imageTypes)
        {
            // API doesn't allow null parameters.
            if (apiContext == null)
            {
                throw new System.ArgumentNullException("apiContext");
            }
            if (querySettings == null)
            {
                throw new System.ArgumentNullException("querySettings");
            }

            // Verify user is authorized to perform action, otherwise throw exception.
            Security.SecurityHandler.SetApiContext(apiContext);
            Helpers.ActionResult result = Helpers.ActionResult.Factory(true);

            try
            {
                Model.OrmsContext context = (Model.OrmsContext)apiContext.CurrentContext;

                // make entities query and set the NoTracking option to stop tracking of entities by entity framework
                System.Data.Objects.ObjectQuery <Entities.ImageType> query = context.ImageTypes;
                query.MergeOption = System.Data.Objects.MergeOption.NoTracking;

                // include entities
                foreach (System.String include in querySettings.IncludedEntities)
                {
                    query = query.Include(include);
                }

                // execute the query with query settings applied
                imageTypes = query
                             .Where(querySettings.GetWhereExpression())
                             .OrderBy(querySettings.SortExpression)
                             .Skip(querySettings.ResultsStartIndex)
                             .Take(querySettings.MaxResultsSize)
                             .ToList();
            }
            catch (System.Exception ex)
            {
                object forDebugging = ex;
                throw;    // Helpers.Exceptions.GetEntityException.Factory(ex);
            }

            return(result);
        }