public IEntity Get(long id) { using (ISession session = NHHelper.OpenSession()) { return(session.Get <T>(id)); } }
public IList <IDoc> GetAll() { using (ISession session = NHHelper.OpenSession()) { var docs = session.Query <IDoc>().ToList(); return(docs); } }
public IDoc Get(string name) { using (ISession session = NHHelper.OpenSession()) { var doc = session.QueryOver <Doc>() .And(d => d.Name == name) .SingleOrDefault(); return(doc); } }
public IUser Get(string login) { using (ISession session = NHHelper.OpenSession()) { var user = session.QueryOver <User>() .And(u => u.Login == login) .SingleOrDefault(); return(user); } }
public IList <IDoc> GetList(string name) { using (ISession session = NHHelper.OpenSession()) { var docs = session.QueryOver <IDoc>() .WhereRestrictionOn(d => d.Name).IsLike($"%{name}%") .List <IDoc>(); return(docs); } }
public bool Check(string login, string password) { using (ISession session = NHHelper.OpenSession()) { //var criteria = session.CreateCriteria<User>(); //criteria.Add(Restrictions.Eq("Login", login)); //criteria.Add(Restrictions.Eq("Password", password)); //var user = criteria.UniqueResult<User>(); var user = session.QueryOver <User>() .And(u => u.Login == login) .And(u => u.Password == password) .SingleOrDefault(); return(user != null); } }
public IList <IDoc> GetList(DateTime date) { using (ISession session = NHHelper.OpenSession()) { //DateTime searchDate; //CultureInfo culture = CultureInfo.CurrentCulture; //DateTimeStyles styles = DateTimeStyles.None; IList <IDoc> docs = null; //if (DateTime.TryParse(date, culture, styles, out searchDate)) { docs = session.QueryOver <IDoc>() .Where(d => d.Date.Date == date) .List <IDoc>(); } return(docs); } }
public void Save(T entity) { using (ISession session = NHHelper.OpenSession()) { using (ITransaction tr = session.BeginTransaction()) { try { session.SaveOrUpdate(entity); } catch (Exception) { tr.Rollback(); return; } tr.Commit(); } } }