コード例 #1
0
 public override Task <int> DeleteMany(List <int> ids, UserToken userToken)
 {
     throw new NotImplementedException();
 }
コード例 #2
0
ファイル: ProfileDAL.cs プロジェクト: cesmii/ProfileDesigner
        protected void MapToEntityNodeSetFiles(ref Profile entity, List <NodeSetFileModel> files, UserToken userToken)
        {
            //init interfaces obj for new scenario
            if (entity.NodeSetFiles == null)
            {
                entity.NodeSetFiles = new List <NodeSetFile>();
            }

            //this shouldn't happen...unless creating from within system. If all items removed, then it should be a collection w/ 0 items.
            if (files == null)
            {
                return;
            }

            // Remove items no longer used
            // Use counter from end of collection so we can remove and not mess up loop iterator
            if (entity.NodeSetFiles.Any())
            {
                var length = entity.NodeSetFiles.Count - 1;
                for (var i = length; i >= 0; i--)
                {
                    var current = entity.NodeSetFiles[i];

                    //remove if no longer present
                    var source = files.Find(v => v.ID.Equals(current.ID) || v.FileName == current.FileName);
                    if (source == null)
                    {
                        entity.NodeSetFiles.RemoveAt(i);
                    }
                    else
                    {
                        _nodeSetFileDAL.MapToEntityPublic(ref current, source, userToken);
                    }
                }
            }

            // Loop over interfaces passed in and only add those not already there
            foreach (var file in files)
            {
                if ((file.ID ?? 0) == 0 || entity.NodeSetFiles.Find(x => x.ID.Equals(file.ID) || x.FileName == file.FileName) == null)
                {
                    var fileEntity = _nodeSetFileDAL.CheckForExisting(file, userToken);
                    if (fileEntity == null)
                    {
                        throw new Exception($"NodeSetFile must be added explicitly");
                        //fileEntity = new NodeSetFile
                        //{
                        //    ID = null,
                        //    AuthorId = entity.AuthorId,
                        //};
                    }
                    _nodeSetFileDAL.MapToEntityPublic(ref fileEntity, file, userToken);
                    entity.NodeSetFiles.Add(fileEntity);
                }
            }
        }
コード例 #3
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 public virtual int Count(Expression <Func <TEntity, bool> > predicate, UserToken userToken)
 {
     return(_repo.FindByCondition(predicate).Count());
 }
コード例 #4
0
        /// <summary>
        /// This should be used when getting all sites and the calling code should pass in the where clause.
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public override DALResult <LookupDataTypeModel> Where(Expression <Func <LookupDataType, bool> > predicate, UserToken user, int?skip, int?take,
                                                              bool returnCount = true, bool verbose = false)
        {
            return(base.Where(predicate, user, skip, take, returnCount, verbose, q => q
                              ////put the order by and where clause before skip.take so we skip/take on filtered/ordered query
                              //var query = _repo.FindByCondition(predicate)
                              .Where(l => l.IsActive)
                              .OrderBy(l => l.DisplayOrder)
                              .ThenBy(l => l.Name)
                              ));
            //var count = returnCount ? query.Count() : 0;
            ////query returns IincludableQuery. Jump through the following to find right combo of skip and take
            ////Goal is to have the query execute and not do in memory skip/take
            //IQueryable<LookupDataType> data;
            //if (skip.HasValue && take.HasValue) data = query.Skip(skip.Value).Take(take.Value);
            //else if (skip.HasValue) data = query.Skip(skip.Value);
            //else if (take.HasValue) data = query.Take(take.Value);
            //else data = query;

            //DALResult<LookupDataTypeModel> result = new DALResult<LookupDataTypeModel>();
            //result.Count = count;
            //result.Data = MapToModels(data.ToList(), verbose);
            //result.SummaryData = null;
            //return result;
        }
コード例 #5
0
 protected override void MapToEntity(ref LookupDataType entity, LookupDataTypeModel model, UserToken userToken)
 {
     entity.OwnerId      = model.OwnerId;
     entity.Name         = model.Name;
     entity.Code         = model.Code;
     entity.DisplayOrder = model.DisplayOrder;
     entity.IsNumeric    = model.IsNumeric;
     entity.UseMinMax    = model.UseMinMax;
     entity.UseEngUnit   = model.UseEngUnit;
     if (model.CustomTypeId != 0)
     {
         entity.CustomTypeId = model.CustomTypeId != 0 ? model.CustomTypeId : null;
     }
     if (model.CustomType != null)
     {
         var customTypeEntity = entity.CustomType;
         if (customTypeEntity == null)
         {
             customTypeEntity = _profileTypeDefinitionDAL.CheckForExisting(model.CustomType, userToken);
             if (customTypeEntity == null)
             {
                 _profileTypeDefinitionDAL.Add(model.CustomType, userToken).Wait();
                 customTypeEntity = _profileTypeDefinitionDAL.CheckForExisting(model.CustomType, userToken);
             }
             entity.CustomType = customTypeEntity;
         }
     }
 }
コード例 #6
0
        protected override DALResult <TModel> Where(Expression <Func <TEntity, bool> > predicate, UserToken user, int?skip = null, int?take = null, bool returnCount = false, bool verbose = false,
                                                    Func <IQueryable <TEntity>, IQueryable <TEntity> > additionalQuery     = null)
        {
            var query = _repo.FindByCondition(predicate).Where(e => e.OwnerId == null || e.OwnerId == user.UserId);

            if (additionalQuery != null)
            {
                query = additionalQuery(query);
            }
            var count = returnCount ? query.Count() : 0;

            //CODE REVIEW From another class: is this optimization really needed?
            //query returns IincludableQuery. Jump through the following to find right combo of skip and take
            //Goal is to have the query execute and not do in memory skip/take
            IQueryable <TEntity> data;

            if (skip.HasValue && take.HasValue)
            {
                data = query.Skip(skip.Value).Take(take.Value);
            }
            else if (skip.HasValue)
            {
                data = query.Skip(skip.Value);
            }
            else if (take.HasValue)
            {
                data = query.Take(take.Value);
            }
            else
            {
                data = query;
            }
            //if (skip.HasValue) query = query.Skip(skip.Value);
            //if (take.HasValue) query = query.Take(take.Value);
            DALResult <TModel> result = new DALResult <TModel>();

            result.Count       = count;
            result.Data        = MapToModels(data.ToList(), verbose);
            result.SummaryData = null;
            return(result);
        }
コード例 #7
0
        protected void MapToEntityProfileWarnings(ref ImportLog entity, List <Models.ImportProfileWarningModel> warnings, UserToken userToken)
        {
            //init for new scenario
            if (entity.ProfileWarnings == null)
            {
                entity.ProfileWarnings = new List <ImportProfileWarning>();
            }

            // Remove attribs no longer used
            // Use counter from end of collection so we can remove and not mess up loop iterator
            if (entity.ProfileWarnings.Count > 0)
            {
                var length = entity.ProfileWarnings.Count - 1;
                for (var i = length; i >= 0; i--)
                {
                    var currentId = entity.ProfileWarnings[i].ID;

                    //remove if no longer present - shouldn't happen with import warnings
                    var source = warnings?.Find(x => x.ID.Equals(currentId));
                    if (source == null)
                    {
                        entity.ProfileWarnings.RemoveAt(i);
                    }
                    else
                    {
                        //do nothing
                    }
                }
            }

            // Loop over warnings passed in and only add those not already there
            if (warnings != null)
            {
                foreach (var msg in warnings)
                {
                    if ((msg.ID ?? 0) == 0 || entity.ProfileWarnings.Find(up => up.ID.Equals(msg.ID)) == null)
                    {
                        entity.ProfileWarnings.Add(new ImportProfileWarning
                        {
                            Message   = msg.Message,
                            ProfileId = msg.ProfileId,
                            Created   = DateTime.UtcNow
                        });
                    }
                }
            }
        }
コード例 #8
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
        /// <summary>
        /// Get item by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual TModel GetById(int id, UserToken userToken)
        {
            var entity = _repo.FindByCondition(u => u.ID == id).FirstOrDefault();

            return(MapToModel(entity));
        }
コード例 #9
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
        public virtual List <TModel> GetAll(UserToken userToken, bool verbose = false)
        {
            var result = _repo.GetAll().ToList();

            return(MapToModels(result, verbose));
        }
コード例 #10
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 public virtual Task <int?> Add(TModel model, UserToken userToken)
 {
     throw new NotImplementedException();
 }
コード例 #11
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 protected virtual void MapToEntity(ref TEntity entity, TModel model, UserToken userToken)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 protected virtual IQueryable <TEntity> GetAllEntities(UserToken userToken)
 {
     return(_repo.GetAll());
 }
コード例 #13
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 protected virtual IQueryable <TEntity> FindByCondition(UserToken userToken, Expression <Func <TEntity, bool> > predicate, bool cacheOnly = false)
 {
     return(_repo.FindByCondition(predicate, cacheOnly));
 }
コード例 #14
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 public virtual int Count(UserToken userToken)
 {
     return(_repo.GetAll().Count());
 }
コード例 #15
0
        /// <summary>
        /// Get item by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public override TModel GetById(int id, UserToken userToken)
        {
            var entity = _repo.FindByCondition(u => u.ID == id && (u.OwnerId == null || u.OwnerId == userToken.UserId)).FirstOrDefault();

            return(MapToModel(entity));
        }
コード例 #16
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
 public virtual DALResult <TModel> Where(Expression <Func <TEntity, bool> > predicate, UserToken user, int?skip = null, int?take = null, bool returnCount = false, bool verbose = false)
 {
     return(Where(predicate, user, skip, take, returnCount, verbose, null));
 }
コード例 #17
0
        public override List <TModel> GetAll(UserToken userToken, bool verbose = false)
        {
            var result = _repo.FindByCondition(u => u.OwnerId == null || u.OwnerId == userToken.UserId).ToList();

            return(MapToModels(result, verbose));
        }
コード例 #18
0
 public override int Count(Expression <Func <TEntity, bool> > predicate, UserToken userToken)
 {
     return(_repo.FindByCondition(predicate).Where(u => u.OwnerId == null || u.OwnerId == userToken.UserId).Count());
 }
コード例 #19
0
 protected override void MapToEntity(ref ImportLog entity, ImportLogModel model, UserToken userToken)
 {
     //only update file list, owner, created on add
     //entity.Name = model.Name;
     entity.StatusId = (int)model.Status;
     if (model.Completed.HasValue)
     {
         entity.Completed = model.Completed;
     }
     MapToEntityMessages(ref entity, model.Messages, userToken);
     MapToEntityProfileWarnings(ref entity, model.ProfileWarnings, userToken);
 }
コード例 #20
0
 public override int Count(UserToken userToken)
 {
     return(_repo.GetAll().Where(u => u.OwnerId == null || u.OwnerId == userToken.UserId).Count());
 }
コード例 #21
0
        /// <summary>
        /// Get all lookup items (no paging)
        /// </summary>
        /// <param name="orgId"></param>
        /// <returns></returns>
        public override List <LookupDataTypeModel> GetAll(UserToken userToken, bool verbose = false)
        {
            DALResult <LookupDataTypeModel> result = GetAllPaged(userToken, verbose: verbose);

            return(result.Data);
        }
コード例 #22
0
 protected override IQueryable <TEntity> FindByCondition(UserToken userToken, Expression <Func <TEntity, bool> > predicate, bool cacheOnly = false)
 {
     return(_repo.FindByCondition(predicate, cacheOnly).Where(u => u.OwnerId == null || u.OwnerId == userToken.UserId || userToken.UserId == -1));
 }
コード例 #23
0
 public void MapToEntityPublic(ref LookupDataType entity, LookupDataTypeModel model, UserToken userToken)
 {
     MapToEntity(ref entity, model, userToken);
 }
コード例 #24
0
 protected override IQueryable <TEntity> GetAllEntities(UserToken userToken)
 {
     return(_repo.GetAll().Where(u => u.OwnerId == null || u.OwnerId == userToken.UserId));
 }
コード例 #25
0
ファイル: ProfileDAL.cs プロジェクト: cesmii/ProfileDesigner
 public void MapToEntityPublic(ref Profile entity, ProfileModel model, UserToken userToken)
 {
     MapToEntity(ref entity, model, userToken);
 }
コード例 #26
0
        //public virtual TModel GetByFunc(Expression<Func<TEntity, bool>> predicate, bool verbose)
        //{
        //    var tRes = _repo.FindByCondition(predicate)?.FirstOrDefault();
        //    return MapToModel(tRes);
        //}

        protected override Task <int?> AddAsync(TEntity entity, TModel model, UserToken userToken)
        {
            // For now: TargetTenantId 0 means write globally, otherwise write to user's scope
            entity.OwnerId = userToken.TargetTenantId == 0 ? null : userToken.UserId;
            return(base.AddAsync(entity, model, userToken));
        }
コード例 #27
0
ファイル: ProfileDAL.cs プロジェクト: cesmii/ProfileDesigner
        public override DALResult <ProfileModel> Where(Expression <Func <Profile, bool> > predicate, UserToken user, int?skip, int?take, bool returnCount = false, bool verbose = false)
        {
            return(base.Where(predicate, user, skip, take, returnCount, verbose, q => q
                              //var query = _repo.FindByCondition(predicate)
                              .OrderBy(x => x.Namespace).ThenByDescending(x => x.Version)
                              ));
            //var count = returnCount ? query.Count() : 0;
            ////query returns IincludableQuery. Jump through the following to find right combo of skip and take
            ////Goal is to have the query execute and not do in memory skip/take
            //IQueryable<Profile> data;
            //if (skip.HasValue && take.HasValue) data = query.Skip(skip.Value).Take(take.Value);
            //else if (skip.HasValue) data = query.Skip(skip.Value);
            //else if (take.HasValue) data = query.Take(take.Value);
            //else data = query;

            //DALResult<ProfileModel> result = new DALResult<ProfileModel>();
            //result.Count = count;
            //result.Data = MapToModels(data.ToList(), verbose);
            //result.SummaryData = null;
            //return result;
        }
コード例 #28
0
ファイル: BaseDAL.cs プロジェクト: cesmii/ProfileDesigner
        public virtual DALResult <TModel> Where(List <Expression <Func <TEntity, bool> > > predicates, UserToken user, int?skip = null, int?take = null,
                                                bool returnCount = false, bool verbose = false,
                                                params OrderByExpression <TEntity>[] orderByExpressions)
        {
            if (predicates == null)
            {
                predicates = new List <Expression <Func <TEntity, bool> > >();
            }

            //build up a query and append n predicates
            var query = _repo.GetAll().AsQueryable <TEntity>();

            foreach (var p in predicates)
            {
                query = query.Where(p).AsQueryable <TEntity>();
            }
            var count = returnCount ? query.Count() : 0;

            //append order by
            ApplyOrderByExpressions(ref query, orderByExpressions);

            //query returns IincludableQuery. Jump through the following to find right combo of skip and take
            //Goal is to have the query execute and not do in memory skip/take
            IQueryable <TEntity> data;

            if (skip.HasValue && take.HasValue)
            {
                data = query.Skip(skip.Value).Take(take.Value);
            }
            else if (skip.HasValue)
            {
                data = query.Skip(skip.Value);
            }
            else if (take.HasValue)
            {
                data = query.Take(take.Value);
            }
            else
            {
                data = query;
            }

            //put together the result
            DALResult <TModel> result = new DALResult <TModel>();

            result.Count       = count;
            result.Data        = MapToModels(data.ToList(), verbose);
            result.SummaryData = null;
            return(result);
        }