Пример #1
0
        public async Task <IActionResult> Update(TestTable model)
        {
            if (ModelState.IsValid)
            {
                //using (_context) <- this is dependency injection
                using (var context = new TestTableContext())
                {
                    TestTable user = new TestTable
                    {
                        Name = model.Name,
                        Id   = model.Id
                    };

                    context.TestTable.Update(user);
                    context.SaveChanges();
                    await context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
Пример #2
0
        public async Task <IActionResult> Add(TestTable model)
        {
            if (ModelState.IsValid)
            {
                //using (_context) <- this is dependency injection
                using (var context = new TestTableContext())
                {
                    TestTable user = new TestTable
                    {
                        Name = model.Name,
                        Id   = model.Id
                    };

                    //Only use AddSync So if you use a value generator that might need to access the DB to get new values to assign to new entries, such as the SequenceHiLo generator, then use AddAsync().
                    context.TestTable.Add(user);

                    await context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Error", "Home"));
            }
        }
 public TestTableController(TestTableContext context)
 {
     this._context = context;
 }
Пример #4
0
 public AnalysisController(TestTableContext context)
 {
     this._context = context;
 }
 public TestTableRepository(TestTableContext context)
 {
     Context = context;
 }
Пример #6
0
 public UnitOfWork()
 {
     Context    = new TestTableContext();
     TestTables = new TestTableRepository(Context);
 }