Example #1
0
        public static void save(bom Part)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {

                    session.Save(Part);

                    session.Transaction.Commit();

                }

            }
        }
Example #2
0
        internal static void InsertPart(bom part)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {

                // retreive all stores and display them
                using (var transaction = session.BeginTransaction())
                {

                    session.SaveOrUpdate(part);

                    transaction.Commit();

                }

            }
        }
Example #3
0
        public static string saveAll(List<inventory> Inventory, string masterItem)
        {
            if (masterItem == "undefined") { masterItem = null; }
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                try{

                    using (session.BeginTransaction())
                    {
                        IList<bom> BOM=null;
                        if (masterItem != null)
                        {
                            BOM = session.CreateCriteria(typeof(bom)).List<bom>();
                            BOM = BOM.Where(x => x.item == masterItem).ToList();
                        }

                        if(BOM!=null){

                            foreach (inventory item in Inventory)
                            {
                                bom bomItem = BOM.Where(x => x.component == item.item).FirstOrDefault();
                                if (bomItem == null && item.bomQty > 0)
                                {
                                    bomItem = new bom();
                                    bomItem.component = item.item;
                                    bomItem.qty = item.bomQty;
                                    bomItem.item = masterItem;
                                    session.Save(bomItem);
                                }
                                else if(item.bomQty>0)
                                {
                                    bomItem.qty = item.bomQty;
                                    session.SaveOrUpdate(bomItem);
                                }
                                else if (item.bomQty==0 && bomItem != null)
                                {
                                    var queryString = string.Format("delete {0} where id = :id", typeof(bom));
                                    session.CreateQuery(queryString)
                                           .SetParameter("id", bomItem.id)
                                           .ExecuteUpdate();
                                }

                            }

                        }
                        else
                        {
                            foreach (inventory item in Inventory)
                            {
                                session.SaveOrUpdate(item);
                            }
                        }

                        session.Transaction.Commit();

                        return "Inventory saved. ";

                    }

                }
                catch(Exception ex)
                {
                    return "Inventory update FAILURE. " + ex.Message + ex.InnerException;
                }

            }
        }