//[ValidateAntiForgeryToken]
        public async Task <ApiReturnResult> Create(StudentDto student)
        {
            if (!ModelState.IsValid)
            {
                var modelErrors = ModelState.AllModelStateErrors();
                return(new ApiReturnResult()
                {
                    IsValidate = false,
                    ErrorLists = modelErrors.ToList()
                });
            }
            var studentModel = new Student()
            {
                LastName       = student.LastName,
                FirstMidName   = student.FirstMidName,
                EnrollmentDate = student.EnrollmentDate
            };

            _context.Add(studentModel);
            await _context.SaveChangesAsync();

            return(new ApiReturnResult()
            {
                IsValidate = true
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Price,Rating")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(
            [Bind("EnrollmentDate,FirstMidName,LastName")] Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("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(student));
        }