Esempio n. 1
0
        public int Delete(User entity)
        {
            _dbContext.Set <User>().Remove(entity);
            int a = _dbContext.SaveChanges();

            return(a);
        }
        public async Task Delete(int id)
        {
            var entity = await GetById(id);

            if (entity == null)
            {
                throw new Exception("The entity is null");
            }

            universityContext.Set <TEntity>().Remove(entity);
            await universityContext.SaveChangesAsync();
        }
Esempio n. 3
0
        // GET: Students/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var student = await _context.Student.FindAsync(id);

            if (student == null)
            {
                return(NotFound());
            }
            ViewData["AddressId"] = new SelectList(_context.Set <Address>(), "Id", "Id", student.AddressId);
            return(View(student));
        }
Esempio n. 4
0
        public async Task Delete(int id)
        {
            // Obtener la entidad por un id
            var entity = await GetById(id);

            // Se valida si existe
            if (entity == null)
            {
                throw new Exception("La entidad es nula.");
            }

            // Elimina la entidad no el task con el código Linkq
            universityContext.Set <TEntity>().Remove(entity);

            await universityContext.SaveChangesAsync();
        }
Esempio n. 5
0
 public StudentService(UniversityContext ctx) : base(ctx)
 {
     _ctx = ctx;
     if (_ctx == null)
     {
         throw new ArgumentNullException(nameof(UniversityContext));
     }
     dbSet = _ctx.Set <Student>();
 }
Esempio n. 6
0
 public GenericService(UniversityContext ctx)
 {
     _ctx = ctx;
     if (_ctx == null)
     {
         throw new ArgumentNullException(nameof(UniversityContext));
     }
     dbSet = _ctx.Set <T>();
 }
Esempio n. 7
0
 public Repository(UniversityContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }
 public GenericRepository(UniversityContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
Esempio n. 9
0
 public Repository(UniversityContext context)
 {
     this.context = context;
     entities     = context.Set <T>();
 }
 public GenericRepository(UniversityContext ctx)
 {
     _ctx   = ctx;
     _dbSet = ctx.Set <T>();
 }
Esempio n. 11
0
 public GenericRepository(UniversityContext _context)
 {
     this.context = _context;
     this.table   = context.Set <T>();
 }
Esempio n. 12
0
 // GET: Courses/Create
 public IActionResult Create()
 {
     ViewData["FirstTeacherId"]  = new SelectList(_context.Set <Teacher>(), "Id", "FullName");
     ViewData["SecondTeacherId"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName");
     return(View());
 }
Esempio n. 13
0
 public StudentRepository(UniversityContext universityContext)
 {
     UniversityContext = universityContext;
     DbSet             = UniversityContext.Set <Student>();
 }
Esempio n. 14
0
 public virtual async Task AddAsync(TEntity entity)
 {
     await context.Set <TEntity>().AddAsync(entity);
 }
Esempio n. 15
0
 public async Task <int> Count()
 {
     return(await universityContext.Set <TEntity>().CountAsync());
 }