public List <User> SearchUserByName(string name, StaticResource.UseType userType) { DynamicParameters parameters = new DynamicParameters(); parameters.Add("@UserType", (int)userType); string sql = $@"SELECT [User].First_Name, [User].Last_Name, [User].Address, [User].User_Id, [User].NIC, [User].Birthday, [User].Gender, [User].EMP_Id, [User].User_Type FROM dbo.[User] WHERE ( [User].First_Name LIKE '%{name}%' OR [User].Last_Name LIKE '%{name}%' OR [User].NIC LIKE '%{name}%' ) AND [User].User_Type = @UserType ORDER BY [User].First_Name ASC;" ; return(_unitOfWork.Connection.Query <User>(sql, parameters, _unitOfWork.Transaction).AsList()); }
public int AddNewEmployee(User user, StaticResource.UseType useType) { if (useType == StaticResource.UseType.EMPLOYEE_USER) { using (DalSession dalSession = new DalSession()) { UnitOfWork unitOfWork = dalSession.UnitOfWork(); unitOfWork.Begin(); try { user.User_Id = Guid.NewGuid().ToString(); _employeeRepo = new EmployeeRepo(unitOfWork); if (_employeeRepo.AddEMP((Employee)user) == 1) { unitOfWork.Commit(); return(1); } else { unitOfWork.Rollback(); return(0); } } catch { unitOfWork.Rollback(); throw; } } } else if (useType == StaticResource.UseType.ADMIN_USER) { using (DalSession dalSession = new DalSession()) { UnitOfWork unitOfWork = dalSession.UnitOfWork(); unitOfWork.Begin(); try { user.User_Id = Guid.NewGuid().ToString(); _adminRepository = new AdminRepository(unitOfWork); if (_adminRepository.AddAdminUser((AdminUser)user) == 1) { unitOfWork.Commit(); return(1); } else { unitOfWork.Rollback(); return(0); } } catch { unitOfWork.Rollback(); throw; } } } else if (useType == StaticResource.UseType.CLIENT_USER) { using (DalSession dalSession = new DalSession()) { UnitOfWork unitOfWork = dalSession.UnitOfWork(); unitOfWork.Begin(); try { user.User_Id = Guid.NewGuid().ToString(); _clientRepository = new ClientRepository(unitOfWork); if (_clientRepository.AddClient((Client)user) == 1) { unitOfWork.Commit(); return(1); } else { unitOfWork.Rollback(); return(0); } } catch { unitOfWork.Rollback(); throw; } } } else { throw new System.Exception(); } }