示例#1
0
        /// <summary>
        /// This method returns a int primarykeyId  for an entity.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="cRMContext"></param>
        /// <param name="columnSelector"></param>
        /// <returns></returns>
        public static int?GetMaxPK <TEntity>(CRMContext cRMContext, Func <TEntity, int> columnSelector) where TEntity : class
        {
            int?GetMaxId = 0;


            var entityClass = cRMContext?.Set <TEntity>();

            if (entityClass.Count() == 0)
            {
                GetMaxId = 1;
            }
            else
            {
                GetMaxId = cRMContext?.Set <TEntity>().Max(columnSelector);
                if (GetMaxId == null || GetMaxId <= 0)
                {
                    GetMaxId = 1;
                }
                else
                {
                    GetMaxId = GetMaxId + 1;
                }
            }


            return(GetMaxId);
        }
 public override void Delete(UserPartition obj)
 {
     using (CRMContext context = new CRMContext())
     {
         UserPartition p = context.Set <UserPartition>().Find(obj.id);
         context.Entry(p).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public override void Delete(Activity obj)
 {
     using (CRMContext context = new CRMContext())
     {
         Activity p = context.Set <Activity>().Find(obj.id);
         context.Entry(p).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
示例#4
0
 public GenericRepository(CRMContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
示例#5
0
 public UserRepository()
 {
     db    = new CRMContext();
     dbSet = db.Set <T>();
 }
示例#6
0
 public void Add(T entity)
 {
     _context.Set <T>().Add(entity);
 }