Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE public.users
- (
- iduser uuid NOT NULL,
- username character varying,
- password character varying
- )
- public class UserLogin : BaseEntity
- {
- public Guid IdUser { get; set; } = new Guid();
- public String UserName { get; set; }
- public String Password { get; set; }
- }
- public class UserLoginRepository : IRepository<UserLogin>
- {
- private string connectionString;
- public UserLoginRepository(IConfiguration configuration)
- {
- connectionString = configuration.GetValue<string>("DBInfo:ConnectionString");
- }
- internal IDbConnection Connection
- {
- get
- {
- return new NpgsqlConnection(connectionString);
- }
- }
- public void Add(UserLogin item)
- {
- using (IDbConnection dbConnection = Connection)
- {
- dbConnection.Open();
- dbConnection.Execute("SELECT iduser from users where username = @UserName AND password = @Password", item);
- }
- }
- public UserLogin FindByID(Guid id)
- {
- using (IDbConnection dbConnection = Connection)
- {
- dbConnection.Open();
- return dbConnection.Query<UserLogin>("SELECT * FROM users WHERE id = @Id", new { Id = id }).FirstOrDefault();
- }
- }
- }
- }
- public class HomeController : Controller
- {
- private readonly UserLoginRepository uRepository;
- public HomeController(IConfiguration configuration)
- {
- uRepository = new UserLoginRepository(configuration);
- }
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult Authorization()
- {
- return View();
- }
- // POST: UserLogin/Authorization
- [HttpPost]
- public IActionResult Authorization(UserLogin user)
- {
- if (ModelState.IsValid)
- {
- uRepository.Add(user);
- return RedirectToAction("UserPage");
- }
- return View(user);
- }
- public IActionResult UserPage()
- {
- return View();
- }
- // GET: /UserLogin/UserPage/1
- [HttpGet]
- public IActionResult UserPage(Guid? id)
- {
- if (id == null)
- {
- return NotFound();
- }
- UserLogin obj = uRepository.FindByID(id.Value);
- if (obj == null)
- {
- return NotFound();
- }
- return View(obj);
- }
- }
- @model WebApplication4.Entites.UserLogin
- @{
- ViewData["Title"] = "Create";
- }
- <h2>Create</h2>
- <form asp-action="Authorization">
- <div class="form-horizontal">
- <h4>Пожалуйста, войдите в систему: </h4>
- <hr />
- <div asp-validation-summary="ModelOnly" class="text-danger"></div>
- <div class="form-group">
- <label asp-for="UserName" class="col-md-2 control-label"></label>
- <div class="col-md-10">
- <input asp-for="UserName" class="form-control" />
- <span asp-validation-for="UserName" class="text-danger" />
- </div>
- </div>
- <div class="form-group">
- <label asp-for="Password" class="col-md-2 control-label"></label>
- <div class="col-md-10">
- <input asp-for="Password" class="form-control" />
- <span asp-validation-for="Password" class="text-danger" />
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Authorization" class="btn btn-default" />
- </div>
- </div>
- </div>
- </form>
- <div>
- <a asp-action="Index">Back to List</a>
- </div>
- @model IEnumerable<WebApplication4.Entites.UserLogin>
- @{
- ViewData["Title"] = "Index";
- }
- <h2>Index</h2>
- <table class="table">
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.UserName)
- </th>
- <th>
- @Html.DisplayNameFor(model => model.Password)
- </th>
- <th></th>
- </tr>
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.UserName)
- </td>
- <td>
- @Html.DisplayFor(modelItem => item.Password)
- </td>
- <td>
- <a asp-action="Edit" asp-route-id="@item.IdUser">Edit</a> |
- <a asp-action="Delete" asp-route-id="@item.IdUser" onclick="return confirm('Are sure wants to delete?');">Delete</a>
- </td>
- </tr>
- }
- </table>
Add Comment
Please, Sign In to add comment