コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Category category)
        {
            var validateType = _context.Categories.Any(obj => obj.Description == category.Description);

            if (validateType)
            {
                ModelState.AddModelError("Description", "Este tipo já foi registrado");
            }

            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #2
0
 public async Task InsertAsync(Product obj)
 {
     _context.Add(obj);
     await _context.SaveChangesAsync();
 }