12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Data.Entity;
- using iiie.Authentication.Business.JWT;
- using iiie.Authentication.DBO;
- using iiie.Logs.DBO;
- using iiie.WebApiUtils.BusinessManager;
- using iiie.WebApiUtils.DBO;
-
- namespace iiie.Authentication.DataAccess
- {
- /// <summary>
- /// Manage basic user informations
- /// </summary>
- public class UserBasicManager : SqlServerManager<T_Users, UserGet, UserAdd, UserEdit, UserEntities, UserBasicManager>
- {
- public override DbSet<T_Users> GetTable(UserEntities db)
- {
- return db.T_Users;
- }
-
- public override UserGet DbToDboGet(T_Users obj)
- {
- var user = new UserGet
- {
- Firstname = obj.firstname,
- Id = obj.id,
- Lastname = obj.lastname,
- ProfileId = obj.profile_id,
- Role = obj.role,
- Username = obj.username
- };
- user.SetHash(obj.password);
- user.SetSalt(obj.salt);
- return user;
- }
-
- public override OpResult<bool> DboAddToDb(UserAdd obj, T_Users add)
- {
- add.username = obj.Username;
- add.password = PasswordHash.CreateHash(obj.GetPlainTextPrivate());
- add.salt = PasswordHash.GetSalt();
- add.role = obj.Role;
- add.firstname = obj.Firstname;
- add.lastname = obj.Lastname;
- add.profile_id = obj.ProfileId;
- return OpResult<bool>.Ok(true);
- }
-
- public override OpResult<bool> DboEditToDb(UserEdit obj, T_Users edit)
- {
- if (obj.Private != null)
- {
- edit.salt = PasswordHash.GetSalt();
- edit.password = PasswordHash.CreateHash(obj.GetPlainTextPrivate());
- }
- edit.firstname = obj.Firstname;
- edit.lastname = obj.Lastname;
- edit.role = obj.Role;
- return OpResult<bool>.Ok(true);
- }
-
- public static OpResult<UserGet> GetSingleByUsername(string username)
- {
- return GetSingle(x => x.username.ToLower() == username.ToLower());
- }
-
- public static OpResult<DboGetMultiple<UserGet>> GetMultipleSearch(string query, int page = 0, int perPage = Int32.MaxValue)
- {
- return GetMultiple(x => x.firstname.ToLower().Contains(query) || x.lastname.ToLower().Contains(query)
- || x.username.ToLower().Contains(query), x => x.username, page, perPage);
- }
- }
- }
|