Beispiel #1
0
 public void ProcessContinue(int id, Reader reader)
 {
     using (var db = new SSLSEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 Borrow borrow = db.Borrow.FirstOrDefault(c => c.BookId == id && c.ReaderId == reader.Id);
                 borrow.ShouldReturnDate = DateTime.Now.AddDays(30);
                 db.SaveChanges();
                 dbContextTransaction.Commit();
             }
             catch (Exception)
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }
Beispiel #2
0
        //归还业务

        /*
         * 归还业务应该只改写borrow的数据状态,至于罚款业务有专门的ProcessPayFine负责
         */
        public void ProcessReturn(Book book, Reader reader)
        {
            //db是一个具有各项模型属性的上下文类
            using (var db = new 校园自助图书管理系统Entities())
            {
                //创建事务
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        //由于本图书馆不允许一位读者同时有两本相同的书尚未归还,因此borrow唯一
                        Borrow borrow = db.Borrow.FirstOrDefault(br => br.BookId == book.Id && br.Reader.Id == reader.Id && br.ReturnTime == null);
                        borrow.ReturnTime = DateTime.Now;
                        borrow.Overdays   = DateTime.Now.Day - borrow.DateShouldBeReturn.Day;
                        db.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }
Beispiel #3
0
        //缴纳罚款业务

        /*
         * 根据Id找到数据库中对应的Fine数据行,修改其FinePrice
         */
        public void ProcessPayFine(Reader reader, int Id)
        {
            using (var db = new 校园自助图书管理系统Entities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Reader re   = db.Reader.FirstOrDefault(r => r.Id == reader.Id);
                        Fine   fine = db.Fine.FirstOrDefault(f => f.Id == Id);
                        Borrow br   = db.Borrow.FirstOrDefault(b => b.FineId == Id);
                        re.Price      -= fine.FinePrice;
                        fine.FinePrice = 0;
                        br.NeedtoFine  = "已缴清";
                        db.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }