如何使用 ASP.NET MVC 中的 EntityFramework6.Npgsql 从 Postgres 数据库获取数据?
how to get data from Postgres data base with EntityFramework6.Npgsql in ASP.NET MVC?
我正在ASP.NET MVC中使用Npgsql和EntityFramework6.Npgsql创建一个登录应用程序,我想实现一个通过标识号找回密码的功能,即用户点击按钮“我忘记了密码”,然后他必须输入识别码,程序会检查它是否存在或是否正确,然后显示更改密码的用户信息。
用户的型号class:
public partial class user
{
public int id { get; set; }
[Display(Name = "Id number")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the id number")]
public string idnumber { get; set; }
[Display(Name = "Name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the name")]
public string fname { get; set; }
[Display(Name = "Last name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the last name)]
public string lname { get; set; }
[Display(Name = "Password")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary a pass")]
[DataType(DataType.Password)]
[MinLength(6, ErrorMessage = "Min six letters")]
public string pass { get; set; }
[Display(Name = "Confirm pass")]
[DataType(DataType.Password)]
[Compare("pass", ErrorMessage = "The pass don't match")]
public string check_pass { get; set; }
[Display(Name = "Email")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary an email")]
[DataType(DataType.EmailAddress)]
public string email { get; set; }
}
所以,在[HttpGet]
中,识别号是由程序获取的,[HttpPost]
中的信息是通过识别号更改的,或者应该这样做。
[HttpGet]
public ActionResult recoverPass()
{
return View();
}
[HttpPost]
public ActionResult recoverPass(userPassRecover user)
{
using(inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
{
var u = dc.user.Where(a => a.cedula == user.cedula).FirstOrDefault();
dc.user.Remove(u);
dc.user.Add(user);
dc.SaveChanges();
return View();
}
}
我真的不知道该怎么做,欢迎任何建议
如果有人遇到同样的问题:
[HttpGet]
public ActionResult recoverPass()
{
return View();
}
[HttpPost]
public ActionResult recoverPass(userRecoverPass user)
{
using (inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
{
var u = dc.user.Where(a => a.idnumber == user.idnumber)?.FirstOrDefault();
if (u != null)
{
u.pass = user.newpass;
dc.SaveChanges();
}
return RedirectToAction("login");
}
}
其中 ʻuserRecoverPass` 对象是仅请求信息以执行密码更改的模型。
我正在ASP.NET MVC中使用Npgsql和EntityFramework6.Npgsql创建一个登录应用程序,我想实现一个通过标识号找回密码的功能,即用户点击按钮“我忘记了密码”,然后他必须输入识别码,程序会检查它是否存在或是否正确,然后显示更改密码的用户信息。
用户的型号class:
public partial class user
{
public int id { get; set; }
[Display(Name = "Id number")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the id number")]
public string idnumber { get; set; }
[Display(Name = "Name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the name")]
public string fname { get; set; }
[Display(Name = "Last name")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary the last name)]
public string lname { get; set; }
[Display(Name = "Password")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary a pass")]
[DataType(DataType.Password)]
[MinLength(6, ErrorMessage = "Min six letters")]
public string pass { get; set; }
[Display(Name = "Confirm pass")]
[DataType(DataType.Password)]
[Compare("pass", ErrorMessage = "The pass don't match")]
public string check_pass { get; set; }
[Display(Name = "Email")]
[Required(AllowEmptyStrings = false, ErrorMessage = "It's necessary an email")]
[DataType(DataType.EmailAddress)]
public string email { get; set; }
}
所以,在[HttpGet]
中,识别号是由程序获取的,[HttpPost]
中的信息是通过识别号更改的,或者应该这样做。
[HttpGet]
public ActionResult recoverPass()
{
return View();
}
[HttpPost]
public ActionResult recoverPass(userPassRecover user)
{
using(inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
{
var u = dc.user.Where(a => a.cedula == user.cedula).FirstOrDefault();
dc.user.Remove(u);
dc.user.Add(user);
dc.SaveChanges();
return View();
}
}
我真的不知道该怎么做,欢迎任何建议
如果有人遇到同样的问题:
[HttpGet]
public ActionResult recoverPass()
{
return View();
}
[HttpPost]
public ActionResult recoverPass(userRecoverPass user)
{
using (inventarioEntitiesDBA dc = new inventarioEntitiesDBA())
{
var u = dc.user.Where(a => a.idnumber == user.idnumber)?.FirstOrDefault();
if (u != null)
{
u.pass = user.newpass;
dc.SaveChanges();
}
return RedirectToAction("login");
}
}
其中 ʻuserRecoverPass` 对象是仅请求信息以执行密码更改的模型。