コード例 #1
0
        public bool ChangePassword(string indexNumber, ChangePasswordRequests request)
        {
            _context = new APBDContext();

            Student student;

            try
            {
                student = GetStudent(indexNumber, _context);
                if (!student.Password.Equals(request.OldPassword))
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }

            student.Password = request.NewPassword;
            _context.SaveChanges();

            /*var updatedStudent = new Student
             * {
             *  IndexNumber = indexNumber,
             *  Password = request.NewPassword
             * };
             *
             * _context.Attach(updatedStudent);
             * _context.Entry(updatedStudent).Property("Password").IsModified = true;
             * _context.SaveChanges();*/

            return(true);
        }
コード例 #2
0
ファイル: StudentsController.cs プロジェクト: s18014-pja/cw4
        public IActionResult ChangePassword(string indexNumber, string password, ChangePasswordRequests request)
        {
            if (!password.Equals("password"))
            {
                return(Ok(BadRequest("Błędny parametr")));
            }
            var response = _dbService.ChangePassword(indexNumber, request);

            return(response == true?Ok("Password changed") : Ok(BadRequest("Wrong old password")));
        }