Esempio n. 1
0
 public void add_item(Item item)
 {
     using (var session = Database_controller.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Save(item);
             transaction.Commit();
         }
     }
 }
 public void delete_item(Publisher item)
 {
     using (var session = Database_controller.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Delete(item);
             transaction.Commit();
         }
     }
 }
Esempio n. 3
0
 public List <Book> get_items()
 {
     using (var session = Database_controller.OpenSession())
     {
         using (session.BeginTransaction())
         {
             return((List <Book>)session.CreateCriteria(typeof(Book))
                    .List <Book>());
         }
     }
 }
Esempio n. 4
0
 public void test_initialize()
 {
     Database_controller.set_session_factory(
         Fluently.Configure()
         .Database(
             MsSqlConfiguration.MsSql2012.ConnectionString(@"Server=(localdb)\MSSQLLocalDB;Database=my_equipment_tests;Integrated Security=true;")
             )
         .Mappings(m =>
                   m.FluentMappings.AddFromAssemblyOf <Item>()
                   ).ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
         .BuildSessionFactory());
 }
Esempio n. 5
0
        public Genre get_item_from_row(DataGridViewRow row)
        {
            int id = (int)row.Cells[get_id_column_number()].Value;

            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    return(session.CreateCriteria <Genre>().Add(Expression.Like("id", id)).SetMaxResults(1).List <Genre>().First());
                }
            }
        }
 public void update_item(Headphone item)
 {
     using (var session = Database_controller.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.SaveOrUpdate(item);
             transaction.Commit();
         }
         ;
     }
 }
Esempio n. 7
0
        public List <Item> get_items_only()
        {
            List <Item> items = new List <Item>();

            using (var session = Database_controller.OpenSession())
            {
                items = session.Query <Item>()
                        .Where(c => !(session.Query <Headphone>().Select(x => x.id)).Contains(c.id))
                        .ToList();
            }


            return(items);
        }
Esempio n. 8
0
        public void delete_item(int id)
        {
            using (var session = Database_controller.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var queryString = string.Format("delete Item where id = :id");
                    session.CreateQuery(queryString)
                    .SetParameter("id", id)
                    .ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }
Esempio n. 9
0
        public List <Genre> get_items()
        {
            List <Genre> genres = new List <Genre>();


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    genres = (List <Genre>)session.CreateCriteria(typeof(Genre))
                             .List <Genre>();
                }
            }
            return(genres);
        }
Esempio n. 10
0
        public void delete_item(int id)
        {
            using (var session = Database_controller.OpenSession())
            {
                Genre item;

                using (var transaction = session.BeginTransaction())
                {
                    item = (Genre)session.CreateCriteria(typeof(Genre))
                           .List <Genre>().Where(b => b.id == id).ToList().First();
                    session.Delete(item);
                    transaction.Commit();
                }
            }
        }
Esempio n. 11
0
        public List <Book> get_books_with_fetches()
        {
            using (var session = Database_controller.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    return((List <Book>)session.QueryOver <Book>()
                           .Fetch(x => x.authors).Eager
                           .Fetch(x => x.publisher).Eager
                           .Fetch(x => x.genre).Eager
                           .List <Book>());

                    tx.Commit();
                }
            }
        }
Esempio n. 12
0
        public List <Item> get_items()
        {
            List <Item> items = new List <Item>();


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    items = (List <Item>)session.CreateCriteria(typeof(Item))
                            .List <Item>();
                }
            }


            return(items);
        }
Esempio n. 13
0
        public List <Headphone> get_items()
        {
            List <Headphone> headphones = new List <Headphone>();


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    headphones = (List <Headphone>)session.CreateCriteria(typeof(Headphone))
                                 .List <Headphone>();
                }
            }


            return(headphones);
        }
Esempio n. 14
0
        public List <Author> get_items()
        {
            List <Author> authors = new List <Author>();


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    authors = (List <Author>)session.CreateCriteria(typeof(Author))
                              .List <Author>();
                }
            }


            return(authors);
        }
Esempio n. 15
0
        public List <Publisher> get_items()
        {
            List <Publisher> publishers = new List <Publisher>();


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    publishers = (List <Publisher>)session.CreateCriteria(typeof(Publisher))
                                 .List <Publisher>();
                }
            }


            return(publishers);
        }
Esempio n. 16
0
        public List <Book_view> get_books()
        {
            List <Book> items = new List <Book>();

            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    items = (List <Book>)session.QueryOver <Book>()

                            .Fetch(SelectMode.Fetch, c => c.authors)
                            .Fetch(SelectMode.FetchLazyProperties, x => x.publisher)
                            .Fetch(SelectMode.FetchLazyProperties, x => x.genre)
                            .TransformUsing(Transformers.DistinctRootEntity)
                            .List <Book>();
                }
            }

            List <Book_view> book_querry = items.Select(x => new Book_view(x.id, x.book_name, String.Join(";", x.authors.Select(m => m.first_name + " " + m.last_name).ToArray()), x.date_borrowed, x.date_returned, x.description, x.rating, x.genre.name, x.publisher.name, x.has_been_readed)).ToList();



            return(book_querry);
        }
Esempio n. 17
0
        private Book get_item_from_form()
        {
            book_context = book_context ?? new Book();
            string   book_name     = book_name_textbox.Text;
            DateTime date_borrow   = new DateTime();
            DateTime date_returned = new DateTime();

            remove_id_from_changed_authors();
            //List<Author> authors = get_authors_from_string(authors_textbox.Text).ToList();
            book_context.authors = authors_list;
            Genre     genre           = new Genre(genre_textbox.Text);
            string    description     = description_textbox.Text;
            Publisher publisher       = new Publisher(publisher_textbox.Text);
            float     rating          = float.Parse(rating_textbox.Text);
            bool      was_been_readed = is_readed_checkbox.Checked;



            if (!return_date_checkbox.Checked)
            {
                date_returned = returned_date_picker.Value;
                book_context.date_returned = date_returned;
            }
            if (!borrow_date_checkbox.Checked)
            {
                date_borrow = borrow_date_picker.Value;
                book_context.date_borrowed = date_borrow;
            }



            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    IList <Genre> tmp = session.CreateCriteria(typeof(Genre))
                                        .List <Genre>().Where(g => g.name.Equals(genre_textbox.Text)).ToList();
                    if (tmp.Count == 0)
                    {
                        book_context.genre = new Genre(genre_textbox.Text);
                    }
                    else
                    {
                        book_context.genre = new Genre(tmp.First().id, genre_textbox.Text);
                    }
                }
            }


            using (var session = Database_controller.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    IList <Publisher> tmp = session.CreateCriteria(typeof(Publisher))
                                            .List <Publisher>().Where(g => g.name.Equals(publisher_textbox.Text)).ToList();
                    if (tmp.Count == 0)
                    {
                        book_context.publisher = new Publisher(publisher_textbox.Text);
                    }
                    else
                    {
                        book_context.publisher = new Publisher(tmp.First().id, tmp.First().name);
                    }
                }
            }



            book_context.rating          = rating;
            book_context.has_been_readed = was_been_readed;
            book_context.book_name       = book_name;
            book_context.description     = description;



            return(book_context);
        }