Ejemplo n.º 1
0
        public IList <T> ExecuteCriteria(Dictionary <String, Object> criteriaList)
        {
            List <T> retVal = new List <T>();

            using (ISession session = HibernateHelper.OpenSession())
            {
                try
                {
                    ICriteria result = session.CreateCriteria(_ClassType);
                    foreach (KeyValuePair <String, Object> criteria in criteriaList)
                    {
                        result.Add(Restrictions.Eq(criteria.Key, criteria.Value));
                    }
                    IList rResult = result.List();
                    foreach (Object data in rResult)
                    {
                        retVal.Add((T)data);
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    session.Disconnect();
                    session.Close();
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        public IHttpActionResult PostBook(Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                using (ISession session = HibernateHelper.OpenSession())
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        foreach (var author in book.Authors)
                        {
                            author.Book = book;
                        }
                        session.Save(book);
                        transaction.Commit();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(CreatedAtRoute("DefaultApi", new { id = book.Id }, book));
        }
Ejemplo n.º 3
0
 public T Get(int id)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         return(session.Get <T>(id));
     }
 }
Ejemplo n.º 4
0
        public Boolean DeleteAll()
        {
            AbstractEntityPersister metadata = HibernateHelper.SessionFactory.GetClassMetadata(typeof(T)) as NHibernate.Persister.Entity.AbstractEntityPersister;
            String table = metadata.TableName;

            using (ISession session = HibernateHelper.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {
                        string deleteAll = String.Format("Delete From \"{0}\"", table);
                        session.CreateSQLQuery(deleteAll).ExecuteUpdate();
                        transaction.Commit();
                        return(true);
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(false);
                    }
                    finally
                    {
                        session.Disconnect();
                        session.Close();
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public Boolean Save(T server)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 session.Save(server);
                 transaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 transaction.Rollback();
                 return(false);
             }
             finally
             {
                 session.Disconnect();
                 session.Close();
             }
         }
     }
 }
Ejemplo n.º 6
0
 public IList <T> GetAll()
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         return(session.CreateCriteria(_ClassType).List <T>());
     }
 }
Ejemplo n.º 7
0
        public IList <Vacancy> SortDown(string attr)
        {
            using (ISession session = HibernateHelper.OpenSession())
            {
                IList <Vacancy> QueryResult;
                switch (attr)
                {
                case "Должность":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.Name).Desc.List());

                case "Описание":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.Description).Desc.List());

                case "Время":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.Time).Desc.List());

                case "Имя компании":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.CompanyName).Desc.List());

                case "Оплата":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.Pay).Desc.List());

                case "Состояние":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.OpenVacancy).Desc.List());

                case "Требования":
                    return(QueryResult = session.QueryOver <Vacancy>().OrderBy(x => x.Request).Desc.List());

                default:
                    break;
                }
                return(null);
            }
        }
Ejemplo n.º 8
0
        public IList <Condidate> SortDown(string attr)
        {
            using (ISession session = HibernateHelper.OpenSession())
            {
                IList <Condidate> QueryResult;
                switch (attr)
                {
                case "ФИО":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.FIO).Desc.List());

                case "Дата рождения":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.DataBirth).Desc.List());

                case "Опыт работы":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.experience).Desc.List());

                case "Навык":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.Skill).Desc.List());

                case "Мобильный телефон":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.Telephone).Desc.List());

                case "Город проживания":
                    return(QueryResult = session.QueryOver <Condidate>().OrderBy(x => x.City).Desc.List());

                default:
                    break;
                }
                return(null);
            }
        }
Ejemplo n.º 9
0
        public IList <T> ExecuteSqlQuery(String sql)
        {
            List <T> retVal = new List <T>();

            using (ISession session = HibernateHelper.OpenSession())
            {
                try
                {
                    ISQLQuery sqlQuery = session.CreateSQLQuery(sql);
                    IList     rResult  = sqlQuery.List();
                    foreach (Object data in rResult)
                    {
                        retVal.Add((T)data);
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    session.Disconnect();
                    session.Close();
                }
            }

            return(retVal);
        }
Ejemplo n.º 10
0
 public List <Vacancy> GetVacancy(string NameEmploye)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Vacancy>().Where(x => x.NameAutor.Contains(NameEmploye)).ToList();
         return(QueryResult);
     }
 }
Ejemplo n.º 11
0
 public Users GetId(int id)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.QueryOver <Users>().Where(x => x.Id == id).SingleOrDefault();
         return(QueryResult);
     }
 }
Ejemplo n.º 12
0
 public Users GetLogin(string Login)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.QueryOver <Users>().Where(x => x.Login == Login).SingleOrDefault();
         return(QueryResult);
     }
 }
Ejemplo n.º 13
0
 public Vacancy GetVacancyForId(int id)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Vacancy>().Where(x => x.Id == id).SingleOrDefault();
         return(QueryResult);
     }
 }
Ejemplo n.º 14
0
 public List <Users> GetALL()
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Users>().ToList();
         return(QueryResult);
     }
 }
Ejemplo n.º 15
0
 public List <Condidate> GetCandidateRequest(string name)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Condidate>().Where(x => x.Skill == name).ToList();
         return(QueryResult);
     }
 }
Ejemplo n.º 16
0
 public List <Vacancy> GetVacancyAll()
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Vacancy>().ToList();
         return(QueryResult);
     }
 }
Ejemplo n.º 17
0
 public List <Condidate> GetAll()
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.Query <Condidate>().ToList();
         return(QueryResult);
     }
 }
Ejemplo n.º 18
0
 public Condidate GetLogin(string Login)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var QueryResult = session.QueryOver <Condidate>().Where(x => x.NameAutor == Login).SingleOrDefault();
         return(QueryResult);
     }
 }
Ejemplo n.º 19
0
 public void Delete(Vacancy vacancy)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(vacancy);
             transaction.Commit();
         }
     }
 }
Ejemplo n.º 20
0
 public void Delete(Condidate Con)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(Con);
             transaction.Commit();
         }
     }
 }
Ejemplo n.º 21
0
 public void Delete(Users user)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(user);
             transaction.Commit();
         }
     }
 }
Ejemplo n.º 22
0
 public IHttpActionResult GetBook(int id)
 {
     using (ISession session = HibernateHelper.OpenSession())
     {
         var book = session.Query <Book>().FirstOrDefault(x => x.Id == id);
         if (book == null)
         {
             return(NotFound());
         }
         return(Ok(book));
     }
 }
Ejemplo n.º 23
0
 // GET: api/Books
 public IList <Book> GetBooks()
 {
     try
     {
         using (ISession session = HibernateHelper.OpenSession())
         {
             var queryResult = session.QueryOver <Book>().List();
             return(queryResult);
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 24
0
        public IHttpActionResult DeleteBook(int id)
        {
            using (ISession session = HibernateHelper.OpenSession())
            {
                var book = session.QueryOver <Book>().Where(x => x.Id == id).SingleOrDefault();

                if (book == null)
                {
                    return(NotFound());
                }

                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(book);
                    transaction.Commit();
                }

                return(Ok(book));
            }
        }
Ejemplo n.º 25
0
 public IHttpActionResult PutBook(int id, Book book)
 {
     try
     {
         if (ModelState.IsValid)
         {
             using (ISession session = HibernateHelper.OpenSession())
             {
                 using (ITransaction transaction = session.BeginTransaction())
                 {
                     session.Update(book);
                     transaction.Commit();
                 }
             }
             return(StatusCode(HttpStatusCode.NoContent));
         }
         return(BadRequest(ModelState));
     }
     catch (Exception)
     {
         throw;
     }
 }