public IEntity Get(long id)
 {
     using (ISession session = NHHelper.OpenSession())
     {
         return(session.Get <T>(id));
     }
 }
示例#2
0
        public IList <IDoc> GetAll()
        {
            using (ISession session = NHHelper.OpenSession())
            {
                var docs = session.Query <IDoc>().ToList();

                return(docs);
            }
        }
示例#3
0
        public IDoc Get(string name)
        {
            using (ISession session = NHHelper.OpenSession())
            {
                var doc = session.QueryOver <Doc>()
                          .And(d => d.Name == name)
                          .SingleOrDefault();

                return(doc);
            }
        }
示例#4
0
        public IUser Get(string login)
        {
            using (ISession session = NHHelper.OpenSession())
            {
                var user = session.QueryOver <User>()
                           .And(u => u.Login == login)
                           .SingleOrDefault();

                return(user);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        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();
         }
     }
 }