Exemplo 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();
        }
Exemplo 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));
        }
Exemplo 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();
        }
Exemplo n.º 5
0
 public StudentService(UniversityContext ctx) : base(ctx)
 {
     _ctx = ctx;
     if (_ctx == null)
     {
         throw new ArgumentNullException(nameof(UniversityContext));
     }
     dbSet = _ctx.Set <Student>();
 }
Exemplo n.º 6
0
 public GenericService(UniversityContext ctx)
 {
     _ctx = ctx;
     if (_ctx == null)
     {
         throw new ArgumentNullException(nameof(UniversityContext));
     }
     dbSet = _ctx.Set <T>();
 }
Exemplo 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>();
 }
Exemplo n.º 9
0
 public Repository(UniversityContext context)
 {
     this.context = context;
     entities     = context.Set <T>();
 }
 public GenericRepository(UniversityContext ctx)
 {
     _ctx   = ctx;
     _dbSet = ctx.Set <T>();
 }
Exemplo n.º 11
0
 public GenericRepository(UniversityContext _context)
 {
     this.context = _context;
     this.table   = context.Set <T>();
 }
Exemplo 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());
 }
Exemplo n.º 13
0
 public StudentRepository(UniversityContext universityContext)
 {
     UniversityContext = universityContext;
     DbSet             = UniversityContext.Set <Student>();
 }
Exemplo n.º 14
0
 public virtual async Task AddAsync(TEntity entity)
 {
     await context.Set <TEntity>().AddAsync(entity);
 }
Exemplo n.º 15
0
 public async Task <int> Count()
 {
     return(await universityContext.Set <TEntity>().CountAsync());
 }