Ejemplo n.º 1
0
        public virtual TEntity Update(TEntity entity, ref IMDResponse res)
        {
            if (!RuleRepository <TEntity> .IsValid(entity, ref res) || !dbSet.Any(e => e.Id == entity.Id))
            {
                return(null);
            }
            try
            {
                entity.ModifiedDate = DateTime.Now;
                entity.ModifiedById = CurrentUser.UserId;
                entity.Version++;
                var CanIDo = RuleRepository <TEntity> .ProcessModifiers(CurrentUser.Role, ref entity, false);

                if (!CanIDo)
                {
                    return(null);
                }
                Attach(entity);
                Entities = null;
            }
            catch (Exception ex) {
                res.Error(ex, entity);
                return(null);
            }
            return(entity);
        }
Ejemplo n.º 2
0
        protected IQueryable <TEntity> ApplyFilter(IQueryable <TEntity> query,
                                                   Expression <Func <TEntity, bool> > filter = null,
                                                   Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > orderBy = null,
                                                   int?skip = null,
                                                   int?take = null)
        {
            var rolefilter = RuleRepository <TEntity> .GetExpressions(CurrentUser.Role);

            if (rolefilter != null)
            {
                query = query.Where(rolefilter);
            }
            if (filter != null)
            {
                query = query.Where(filter);
            }
            if (orderBy != null)
            {
                query = orderBy(query);
            }
            if (skip.HasValue)
            {
                query = query.Skip(skip.Value);
            }
            if (take.HasValue)
            {
                query = query.Take(take.Value);
            }
            return(query);
        }
Ejemplo n.º 3
0
        public virtual TEntity Insert(TEntity entity, ref IMDResponse res)
        {
            if (!RuleRepository <TEntity> .IsValid(entity, ref res))
            {
                return(null);
            }
            try
            {
                entity.CreatedById = CurrentUser.UserId;
                entity.CreatedDate = DateTime.Now;
                var CanIDo = RuleRepository <TEntity> .ProcessModifiers(CurrentUser.Role, ref entity, true);

                if (!CanIDo)
                {
                    return(null);
                }
                dbSet.Add(entity);
                Entities = null;
            }
            catch (Exception ex) { res.Error(ex, entity); return(null); }
            return(entity);
        }