Example #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,CreationDate,Description")] Skill skill)
        {
            if (ModelState.IsValid)
            {
                _context.Add(skill);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(skill));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("Name,SurName,Age,HiringDate")] Employee employee) // removed Id
        {
            try                                                                                           // added try-catch
            {
                if (ModelState.IsValid)
                {
                    _context.Add(employee);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(employee));
        }