That code still makes no sense:
Account account = new Account();
Declare a variable to hold an instance of the
Account
class, and set it to a new instance of the
Account
class.
db.Accounts.Where(...).Select(...).SingleOrDefault();
Declare and execute a LINQ query.
Throw away the result.
if (account == null) { ... }
You know it's not
null
. You set it to a new instance of the
Account
class, and you've never updated it.
account.IsActive = true;
You're updating a blank instance of the class, which is not connected to your database.
db.SaveChanges();
There are no changes to save, because you have not changed any entities connected to your database.
As I mentioned in the comments to your previous question, use:
Account account = db.Accounts.SingleOrDefault(...);
Combining that with Maciej's solution gives:
public JsonResult VerifyOTP(int otp)
{
using (var db = new OfficeEntities())
{
Account account = db.Accounts.SingleOrDefault(x => x.Otp == otp);
if (account == null)
{
return Json(false);
}
account.IsActive = true;
db.SaveChanges();
return Json(true);
}
}