예제 #1
0
        public static T AttachToContext <T>(this InternetShopDbContext context, T entity)
            where T : class
        {
            var result = context.Add(entity).Entity;

            context.SaveChanges();

            return(result);
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }