UserRepository.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using Dapper;
  2. using System.Data;
  3. using System.Linq;
  4. using WebAPIBase.Data.DapperORM.Interface;
  5. using WebAPIBase.Model;
  6. namespace WebAPIBase.Data.DapperORM.Class
  7. {
  8. public class UserRepository : BaseRepository, IUserRepository
  9. {
  10. public User ValidateUser(string username, string password)
  11. {
  12. using var db = GetSqlConnection();
  13. const string sql = @"select Id, Name, Surname, Email, Phone, LastLogon, CreatedOn, ActivationCode
  14. from User U
  15. where Login = @Login and Password = @Password";
  16. return db.Query<User>(sql, new { Login = username, Password = password }, commandType: CommandType.Text).FirstOrDefault();
  17. }
  18. public void InsertUser(string username, string password)
  19. {
  20. using var db = GetSqlConnection();
  21. const string sql = @"insert into User (Login, Password, CreatedOn, LastLogon) values (@Login, @Password, NOW(), NOW())";
  22. db.Execute(sql, new { Login = username, Password = password }, commandType: CommandType.Text);
  23. }
  24. }
  25. }