Пример #1
0
        public async Task <IActionResult> Edit(int id, NewRegisteredStudent newRegisteredStudent)
        {
            if (id != newRegisteredStudent.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(newRegisteredStudent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewRegisteredStudentExists(newRegisteredStudent.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(newRegisteredStudent));
        }
Пример #2
0
        public async Task <IActionResult> Create(NewRegisteredStudent newRegisteredStudent)
        {
            if (ModelState.IsValid)
            {
                var checkUserName = _context.NewRegisteredStudent.Where(x => x.UserName == newRegisteredStudent.UserName).SingleOrDefault();
                if (checkUserName == null)
                {
                    newRegisteredStudent.Password = HashPassword(newRegisteredStudent.Password);//will assign the hash to the password field
                    _context.Add(newRegisteredStudent);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(StudentLogin))); //after seccuss registration pop up message
                }
                return(View(newRegisteredStudent));                 /*must an error be showed if the username exists*/
            }
            return(View(newRegisteredStudent));
        }