Example #1
0
        public Guid GetRackItemLevelId()
        {
            using (ISession session = NhibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var  ItemId = GetItemId();
                    Item item   = session.Get <Item>(ItemId);

                    var  RackId = GetRackId();
                    Rack rack   = session.Get <Rack>(RackId);

                    RackItemLevel rackItemLevel = new RackItemLevel
                    {
                        CurrentQuantity = 10,
                        InQuantity      = 5,
                        OutQuantity     = 10,
                        Rack            = rack,
                        Item            = item
                    };

                    session.Save(rackItemLevel);
                    transaction.Commit();

                    rackItemLevel = session.Get <RackItemLevel>(rackItemLevel.Id);
                    return(rackItemLevel.Id);
                }
            }
        }
Example #2
0
        bool IBaseDao <User, long> .Delete(User entity)
        {
            ITransaction transaction = null;

            try
            {
                ISession session = null;
                session     = NhibernateHelper.OpenSession();
                transaction = session.BeginTransaction();

                var obj = session.Get <User>(entity.Id);
                if (obj != null)
                {
                    session.Delete(obj);
                }

                transaction.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                return(false);
            }
        }
Example #3
0
        bool IUserManager.IsPasswordChanged(User entity)
        {
            bool         isPasswordchanged = false;
            ITransaction transaction       = null;

            try
            {
                ISession session = null;
                session = NhibernateHelper.OpenSession();

                var usr = session.CreateCriteria(typeof(User))
                          .Add(Restrictions.Eq("UserName", entity.UserName))
                          .List <User>().FirstOrDefault();
                if (usr != null)
                {
                    if (usr.OldPassword == entity.OldPassword)
                    {
                        usr.NewPassword   = entity.NewPassword;
                        usr.OldPassword   = entity.NewPassword;
                        isPasswordchanged = true;
                    }
                    transaction = session.BeginTransaction();
                    session.SaveOrUpdate(usr);
                    transaction.Commit();
                    session.Flush();
                }
                return(isPasswordchanged);
            }
            catch
            {
                transaction.Rollback();
                return(isPasswordchanged);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            using (var session = NhibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem
                    {
                        NetPrice  = 30,
                        UnitPrice = 50,
                        Quantity  = 900
                    };

                    session.Save(purchaseOrderItem);
                    transaction.Commit();

                    List <PurchaseOrderItem> purchase = session.Query <PurchaseOrderItem>()
                                                        .Where(x => x.Quantity == 900).ToList();

                    foreach (var p in purchase)
                    {
                        Console.WriteLine(p.Id);
                    }
                    Console.ReadKey();
                }
            }
        }
Example #5
0
        public bool IsUserCreated(User entity)
        {
            bool         isUserCreated = false;
            ITransaction transaction   = null;
            User         usr           = new User();

            try
            {
                ISession session = null;
                session = NhibernateHelper.OpenSession();

                var comp = session.CreateCriteria(typeof(User))
                           .Add(Restrictions.Eq("UserName", entity.UserName))
                           .List <User>().FirstOrDefault();
                if (comp != null)
                {
                    isUserCreated = false;
                }
                else
                {
                    transaction   = session.BeginTransaction();
                    isUserCreated = true;

                    session.Save(entity);
                    transaction.Commit();
                    session.Flush();
                }
                return(isUserCreated);
            }
            catch
            {
                transaction.Rollback();
                return(false);
            }
        }
Example #6
0
        public void RackTest()
        {
            using (var session = NhibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    /*var rack = new Rack
                     * {
                     *  Name = "First",
                     *  Code = 10,
                     *  Limit = 700,
                     *  Location = "First Flat"
                     * };*/

                    Guid racckId = GetRackId();
                    Rack rack    = session.Get <Rack>(racckId);

                    session.Save(rack);
                    transaction.Commit();

                    var res = session.Get <Rack>(rack.Id);
                    Assert.AreEqual(rack.Limit, 700);
                }
            }
        }
Example #7
0
        public void PurchaseOrderItemTest()
        {
            using (var session = NhibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var  itemId = GetItemId();
                    Item item   = session.Get <Item>(itemId);

                    var  racckId = GetRackId();
                    Rack rack    = session.Get <Rack>(racckId);

                    PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem
                    {
                        NetPrice  = 30,
                        UnitPrice = 50,
                        Quantity  = 900,
                        Item      = item,
                        Rack      = rack
                    };

                    session.Save(purchaseOrderItem);
                    transaction.Commit();

                    var res = session.Get <PurchaseOrderItem>(purchaseOrderItem.Id);
                    Assert.AreEqual(purchaseOrderItem.NetPrice, res.NetPrice);
                }
            }
        }
Example #8
0
 public ActionResult Edit(int id)
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var oteller = session.Query <Models.Otel>().FirstOrDefault(x => x.Id == id);
         return(View(oteller));
     }
 }
Example #9
0
 public ActionResult Listele()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var oteller = session.Query <Models.Otel>().ToList();
         return(View(oteller));
     }
 }
Example #10
0
 // GET: Sube
 public ActionResult Index()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var subeler = session.Query <Models.Sube>().ToList();
         return(View(subeler));
     }
 }
 // GET: CRUD/Edit/5
 public ActionResult Edit(int id)
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         var task = session.Get <Task>(id);
         return(View(task));
     }
 }
 // GET: CRUD
 public ActionResult Index()
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         var tasks = session.QueryOver <Task>().List();
         return(View(tasks));
     }
 }
Example #13
0
 /// <summary>
 /// 获取所有该类型的对象列表
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static ICollection <T> GetAll <T>()
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         IList <T> list = session.CreateCriteria(typeof(T)).List <T>();
         return(list);
     }
 }
Example #14
0
 public ActionResult Listele()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var zup = session.Query <Models.dukkan>().ToList();
         return(View(zup));
     }
 }
Example #15
0
 public ActionResult Listele()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var banks = session.Query <Models.Banka>().ToList();
         return(View(banks));
     }
 }
Example #16
0
 public ActionResult Edit(int id)
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var bank = session.Query <Models.Banka>().FirstOrDefault(x => x.Id == id);
         return(View(bank));
     }
 }
Example #17
0
 public ActionResult Index()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var sad = session.Query <Models.urun>().ToList();
         return(View(sad));
     }
 }
Example #18
0
 // GET: Banka
 public ActionResult Index()
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var banks = session.Query <Models.Banka>().Fetch(x => x.Subeler).ToList();
         return(View(banks));
     }
 }
Example #19
0
 public ICollection <Runoob_tbl> GetAllUser()
 {
     using (ISession session = NhibernateHelper.OpenSession()) //using 代表用完session就释放
     {
         ICriteria criteria = session.CreateCriteria(typeof(Runoob_tbl));
         return(criteria.List <Runoob_tbl>());
     }
 }
Example #20
0
 public ICollection <User> GetAllUsers()
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         ICriteria criteria = session.CreateCriteria(typeof(User));
         return(criteria.List <User>());
     }
 }
Example #21
0
 public ActionResult Edit(int id)
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var dukkan = session.Query <Models.dukkan>().FirstOrDefault(x => x.Id_Zup == id);
         return(View(dukkan));
     }
 }
Example #22
0
        Ticket IBaseDao <Ticket, long> .FindById(long id)
        {
            ISession session = null;

            session = NhibernateHelper.OpenSession();

            return(session.CreateCriteria(typeof(Ticket))
                   .Add(Restrictions.Eq("Id", id)).List <Ticket>().FirstOrDefault());
        }
Example #23
0
        public ActionResult Listele2()
        {
            using (var session = NhibernateHelper.OpenSession())
            {
                //var sube = session.Get<Models.Sube>(1);
                //var bnkF = session.Query<Models.Banka>().Where(x=> x.Id == 1).FirstOrDefault();
                var bnkYeni = new Models.Banka()
                {
                    Ad = "Yeni Banka", Sehir = "Bursa", Telefon = "0422212123"
                };

                var Sube = new Models.Sube()
                {
                    Ad = "Sube Yeni", Telefon = "02125334444"
                };
                Sube.Banka = bnkYeni;

                //var sube = new Models.Sube();
                //sube.Ad = "Nilufer";
                //sube.Telefon = "02122121218";
                //sube.Banka = bnkYeni;

                //bnkYeni.Subeler.Add(sube);

                session.SaveOrUpdate(Sube);
                session.Flush();

                //var banka = session.Query<Models.Banka>().Where(x => x.Ad == "A Bankası").FirstOrDefault();
                //sube.Banka = banka;


                //var t = banka.Subeler;
                //linq query

                //bnk.Ad = "E bankası";
                //bnk.Sube = "Kadıköy";
                //var bnkQ = session.Query<Models.Banka>().Where(x => x.Sehir == "Istanbul").ToList();
                //rollback
                //commit

                //var bnk = new Models.Banka()
                //{
                //    Ad = "H Bankası",
                //    Telefon = "312 2121211",
                //    Sehir = "Ankara"
                //};

                //var bnk = session.Query<Models.Banka>().FirstOrDefault(x => x.Id == 7);

                //session.SaveOrUpdate(bnk);

                //session.Delete(bnk);
            }


            return(View(Models.OgrenciVeri.VeriListe));
        }
Example #24
0
 public Runoob_tbl GetByUserName(string userName)              //查询userName
 {
     using (ISession session = NhibernateHelper.OpenSession()) //using 代表用完session就释放
     {
         ICriteria criteria = session.CreateCriteria(typeof(Runoob_tbl));
         criteria.Add(Restrictions.Eq("Username", userName));
         return(criteria.UniqueResult <Runoob_tbl>());
     }
 }
Example #25
0
 public ActionResult Create(Models.dukkan Dukkan)
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         session.SaveOrUpdate(Dukkan);
         session.Flush();
     }
     return(RedirectToAction("Index"));
 }
Example #26
0
 public User GetById(int id)
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         //进行操作
         User user = session.Get <User>(id);
         return(user);
     }
 }
Example #27
0
 public User GetById(int id)//查询条件不会更改数据所以不需要使用事务
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         //进行操作
         User user = session.Get <User>(id);//删除数据
         return(user);
     }
 }
Example #28
0
        Company ICompanyManager.FindCompanyById(long companyId)
        {
            ISession session = null;

            session = NhibernateHelper.OpenSession();

            var obj = session.Get <Company>((Int32)companyId);

            return(obj);
        }
Example #29
0
 public ActionResult Delete(int id)
 {
     using (var session = NhibernateHelper.OpenSession())
     {
         var yoket = session.Query <Models.Otel>().FirstOrDefault(x => x.Id == id);
         session.Delete(yoket);
         session.Flush();
     }
     return(RedirectToAction("Index"));
 }
Example #30
0
 public User GetByUsername(string username)
 {
     using (ISession session = NhibernateHelper.OpenSession())
     {
         //Restrictions.Eq()表示添加查询条件
         // criteria.UniqueResult<User>();得到唯一的结果,返回的是User对象
         User user = session.CreateCriteria(typeof(User)).Add(Restrictions.Eq("Username", username)).UniqueResult <User>();//创建一个配置文件
         return(user);
     }
 }