Пример #1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Address,UserRef,Age")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                var user = await _context.Users.FirstOrDefaultAsync(m => m.UserName == HttpContext.User.Identity.Name);

                customer.UserRef = user.Id;
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserRef"] = new SelectList(_context.Set <User>(), "Id", "Id", customer.UserRef);
            return(View(customer));
        }
        public override void Update(Client entity)
        {
            var client = entity ?? throw new ArgumentNullException(nameof(entity));
            var local  = _db.Set <Client>()
                         .Local
                         .FirstOrDefault(f => f.ClientId == entity.ClientId);

            if (local != null)
            {
                _db.Entry(local).State = EntityState.Detached;
            }
            _db.Entry(client).State = EntityState.Modified;
            _db.SaveChanges();
        }
Пример #3
0
        public BaseRepository(BankDbContext ctx)

        {
            _context = ctx;
            _dbset   = _context.Set <T>();
        }
Пример #4
0
 public virtual IQueryable <T> All(Expression <Func <T, bool> > query)
 {
     return(_context.Set <T>().Where(query));
 }
Пример #5
0
 public IEnumerable <T> GetAll()
 {
     return(dbContext.Set <T>()
            .AsEnumerable());
 }