示例#1
0
        public async Task <IActionResult> Create([Bind("ID,FactoryName,Address")] Factory factory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(factory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(factory));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Title,Description,Color,Price")] Furniture furniture)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(furniture);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex*/)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists ");
            }
            return(View(furniture));
        }