title: Let users edit/delete only their own content (in generic repositories)
body: <p>I want to let users only manage their own content(edit/delete/list of things... and everything need to admin panel for their own content). In my project I use <strong>unitOfwork</strong> and <strong>GenericRepositories</strong> and i have <strong>BaseRepositoy</strong>  for implementing the rest of the repositories(to avoid duplicate codes); I know I must implement user repository and use it in other repositories for getting user and continuing the operation ..., but i want to know if there's any way to <strong>implement BaseRepository</strong>?<strong>or another way to avoid manipulating repositories and writing duplicate code?</strong></p>
  
  <pre><code>namespace ServiceLayer.Repository
  {
      public abstract class BaseRepository&lt;T&gt; : IBaseRepository&lt;T&gt; where T : BaseModel
      {
          private readonly IDbSet&lt;T&gt; _t;
          private readonly IUnitOfWork _unitOfWork;
          private IQueryable&lt;T&gt; _db;
          protected BaseRepository(IUnitOfWork unitOfWork)
          {
              _unitOfWork = unitOfWork;
              _t = _unitOfWork.Set&lt;T&gt;();
              _db = _t;
          }
          public virtual (IQueryable&lt;T&gt; List, int? PageId, int? PageCount) GetAll(int? pageId, Expression&lt;Func&lt;T, bool&gt;&gt;[] searchExpression, params Expression&lt;Func&lt;T, object&gt;&gt;[] includeExpressions)
          {
  
  
              if (includeExpressions != null &amp;&amp; includeExpressions.Any())
              {
                  foreach (var expression in includeExpressions)
                  {
                      _db = _db.Include(expression);
                  }
              }
              if (searchExpression != null &amp;&amp; searchExpression.Any())
              {
                  foreach (var expression in searchExpression)
                  {
                      _db = _db.Where(expression);
                  }
              }
  
              if (pageId == null) return (_db, null, null);
  
              if (pageId &lt;= 0)
                  pageId = 1;
  
              int take = 5;
              int skip = ((int)pageId - 1) * take;
              int count = _db.Count();
              int pageCount = count / take;
  
  
  
              var list = _db.OrderByDescending(x =&gt; x.Id).Skip(skip).Take(take);
              return (list, (int)pageId, pageCount);
          }
  
  
          public virtual T Get(long id, params Expression&lt;Func&lt;T, object&gt;&gt;[] includeExpression)
          {
              if (includeExpression == null) return _t.Find(id);
  
              foreach (var expression in includeExpression)
              {
                  _db = _db.Include(expression);
              }
              return _db.SingleOrDefault(x =&gt; x.Id == id);
          }
  
          public virtual List&lt;T&gt; GetIdsArray(long?[] ids, params Expression&lt;Func&lt;T, object&gt;&gt;[] includeExpression)
          {
              if (ids == null) return null;
              if (includeExpression == null) return _t.Where(x =&gt; ids.Contains(x.Id)).ToList();
              foreach (var expression in includeExpression)
              {
                  _db = _db.Include(expression);
              }
              return _db.Where(x =&gt; ids.Contains(x.Id)).ToList();
          }
  
          public virtual T Update(T obj)
          {
              _unitOfWork.MarkAsChanged(obj);
              _unitOfWork.SaveAllChanges();
              return obj;
          }
  
          public virtual T Add(T obj)
          {
              _t.Add(obj);
              _unitOfWork.SaveAllChanges();
              return obj;
          }
  
          public virtual int Remove(T obj)
          {
              _t.Remove(obj);
              return _unitOfWork.SaveAllChanges();
          }
  
          public virtual int RemoveIdsArray(long?[] objs)
          {
              if (objs == null || objs.Length &lt;= 0) return -5;
              var objects = GetIdsArray(objs, null);
              foreach (var o in objects)
              {
                  _t.Remove(o);
              }
              return _unitOfWork.SaveAllChanges();
          }
  
  
          public virtual (string[] fieldName, IEnumerable&lt;string&gt; DisplayAttribute) GetAllNameAndTitleOfDbTable()
          {
              var fieldName = typeof(T).GetProperties(BindingFlags.DeclaredOnly |
                                                      BindingFlags.Public |
                                                      BindingFlags.Instance)
                  .Select(property =&gt; property.Name)
                  .ToArray();
              var name = typeof(T).GetProperties(BindingFlags.DeclaredOnly |
                                                 BindingFlags.Public |
                                                 BindingFlags.Instance).Select(property =&gt;
                  ((DisplayAttribute)property.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault())
                  ?.Name).ToArray();
              return (fieldName, name);
          }
      }
  }
  </code></pre>