narsil/Tanshu.Accounts.Repository/BusinessLayer/UserBI.cs

61 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using NHibernate;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Repository
{
public class UserBI : FluentBase<User>
{
public UserBI()
: base()
{ }
public UserBI(bool useTransaction)
: base(useTransaction)
{ }
public UserBI(ISession session)
: base(session)
{ }
public UserBI(ISession session, bool useTransaction)
: base(session, useTransaction)
{ }
public IList<User> GetFilteredUsers(Dictionary<string, string> filter)
{
return Session.QueryOver<User>()
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
.List();
}
public bool ChangePassword(User userData, string newPassword)
{
var dbUser = Get(x => x.Name == userData.Name && x.Password == userData.Password);
if (dbUser == null)
return false;
dbUser.Password = newPassword;
Session.Update(dbUser);
return true;
}
public User ValidateUser(string name, string password)
{
return Get(x => x.Name == name && x.Password == password);
}
public User MsrValidateUser(string msrString)
{
return Get(x => x.MsrString == msrString);
}
public IList<User> ListActive(DateTime startDate, DateTime finishDate)
{
const string query = @"
select distinct(u) from Voucher v
inner join v.User u
where v.Date >= :startDate and v.Date <= :finishDate
order by u.Name";
return Session.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.List<User>();
}
}
}