Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UserBasicManager.cs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Data.Entity;
  3. using iiie.Authentication.Business.JWT;
  4. using iiie.Authentication.DBO;
  5. using iiie.Logs.DBO;
  6. using iiie.WebApiUtils.BusinessManager;
  7. using iiie.WebApiUtils.DBO;
  8. namespace iiie.Authentication.DataAccess
  9. {
  10. /// <summary>
  11. /// Manage basic user informations
  12. /// </summary>
  13. public class UserBasicManager : SqlServerManager<T_Users, UserGet, UserAdd, UserEdit, UserEntities, UserBasicManager>
  14. {
  15. public override DbSet<T_Users> GetTable(UserEntities db)
  16. {
  17. return db.T_Users;
  18. }
  19. public override UserGet DbToDboGet(T_Users obj)
  20. {
  21. var user = new UserGet
  22. {
  23. Firstname = obj.firstname,
  24. Id = obj.id,
  25. Lastname = obj.lastname,
  26. ProfileId = obj.profile_id,
  27. Role = obj.role,
  28. Username = obj.username
  29. };
  30. user.SetHash(obj.password);
  31. user.SetSalt(obj.salt);
  32. return user;
  33. }
  34. public override OpResult<bool> DboAddToDb(UserAdd obj, T_Users add)
  35. {
  36. add.username = obj.Username;
  37. add.password = PasswordHash.CreateHash(obj.GetPlainTextPrivate());
  38. add.salt = PasswordHash.GetSalt();
  39. add.role = obj.Role;
  40. add.firstname = obj.Firstname;
  41. add.lastname = obj.Lastname;
  42. add.profile_id = obj.ProfileId;
  43. return OpResult<bool>.Ok(true);
  44. }
  45. public override OpResult<bool> DboEditToDb(UserEdit obj, T_Users edit)
  46. {
  47. if (obj.Private != null)
  48. {
  49. edit.salt = PasswordHash.GetSalt();
  50. edit.password = PasswordHash.CreateHash(obj.GetPlainTextPrivate());
  51. }
  52. edit.firstname = obj.Firstname;
  53. edit.lastname = obj.Lastname;
  54. edit.role = obj.Role;
  55. return OpResult<bool>.Ok(true);
  56. }
  57. public static OpResult<UserGet> GetSingleByUsername(string username)
  58. {
  59. return GetSingle(x => x.username.ToLower() == username.ToLower());
  60. }
  61. public static OpResult<DboGetMultiple<UserGet>> GetMultipleSearch(string query, int page = 0, int perPage = Int32.MaxValue)
  62. {
  63. return GetMultiple(x => x.firstname.ToLower().Contains(query) || x.lastname.ToLower().Contains(query)
  64. || x.username.ToLower().Contains(query), x => x.username, page, perPage);
  65. }
  66. }
  67. }