Example #1
0
        public async Task <IActionResult> Create([FromBody] Student item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var checkForDuplicate = _context.Student
                                    .Where(r => r.FirstName == item.FirstName)
                                    .Where(r => r.LastName == item.LastName)
                                    .Where(r => r.StudentNumber == item.StudentNumber)
                                    .Count();

            if (checkForDuplicate < 1)
            {
                _context.Student.Add(item);
                await _context.SaveChangesAsync();

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