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); }
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)); }
public T Get(int id) { using (ISession session = HibernateHelper.OpenSession()) { return(session.Get <T>(id)); } }
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(); } } } }
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(); } } } }
public IList <T> GetAll() { using (ISession session = HibernateHelper.OpenSession()) { return(session.CreateCriteria(_ClassType).List <T>()); } }
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); } }
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); } }
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); }
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); } }
public Users GetId(int id) { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.QueryOver <Users>().Where(x => x.Id == id).SingleOrDefault(); return(QueryResult); } }
public Users GetLogin(string Login) { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.QueryOver <Users>().Where(x => x.Login == Login).SingleOrDefault(); return(QueryResult); } }
public Vacancy GetVacancyForId(int id) { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.Query <Vacancy>().Where(x => x.Id == id).SingleOrDefault(); return(QueryResult); } }
public List <Users> GetALL() { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.Query <Users>().ToList(); return(QueryResult); } }
public List <Condidate> GetCandidateRequest(string name) { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.Query <Condidate>().Where(x => x.Skill == name).ToList(); return(QueryResult); } }
public List <Vacancy> GetVacancyAll() { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.Query <Vacancy>().ToList(); return(QueryResult); } }
public List <Condidate> GetAll() { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.Query <Condidate>().ToList(); return(QueryResult); } }
public Condidate GetLogin(string Login) { using (ISession session = HibernateHelper.OpenSession()) { var QueryResult = session.QueryOver <Condidate>().Where(x => x.NameAutor == Login).SingleOrDefault(); return(QueryResult); } }
public void Delete(Vacancy vacancy) { using (ISession session = HibernateHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(vacancy); transaction.Commit(); } } }
public void Delete(Condidate Con) { using (ISession session = HibernateHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(Con); transaction.Commit(); } } }
public void Delete(Users user) { using (ISession session = HibernateHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Delete(user); transaction.Commit(); } } }
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)); } }
// 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; } }
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)); } }
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; } }