narsil/Tanshu.Accounts.Repository/BusinessLayer/UserBI.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

61 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using NHibernate;
using Tanshu.Accounts.Entities.Auth;
namespace Tanshu.Accounts.Repository
{
public class UserBI : FluentGenericBase<User>
{
public UserBI()
: base()
{ }
public UserBI(bool beginTransaction)
: base(beginTransaction)
{ }
public UserBI(ISession session)
: base(session)
{ }
public UserBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public IList<User> GetFilteredUsers(Dictionary<string, string> filter)
{
return Query()
.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>();
}
}
}