Example #1
0
 public static Account FindAccount(int ID)
 {
     using (var db = new BookContext())
     {
         var acc = db.Accounts.Find(ID);
         if (acc != null)
         {
             db.Dispose();
             return(acc);
         }
         db.Dispose();
         return(null);
     }
 }
Example #2
0
 public static Account FindAccount(string UserName)
 {
     using (var db = new BookContext())
     {
         var acc = db.Accounts.Where(a => a.UserName.Equals(UserName)).Single();
         if (acc != null)
         {
             db.Dispose();
             return(acc);
         }
         db.Dispose();
         return(null);
     }
 }
 public static Bill FindBill(int ID)
 {
     using (var db = new BookContext())
     {
         var bill = db.Bills.Find(ID);
         if (bill != null)
         {
             db.Dispose();
             return(bill);
         }
         db.Dispose();
         return(null);
     }
 }
Example #4
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _db.Dispose();
     }
 }
Example #5
0
 public static List <Account> FindAccountWithRole(string Role)
 {
     using (var db = new BookContext())
     {
         var listacc = db.Accounts
                       .Where(a => a.Role.Description.Equals(Role))
                       .OrderBy(a => a.Point).ToList();
         if (listacc != null)
         {
             db.Dispose();
             return(listacc);
         }
         db.Dispose();
         return(null);
     }
 }
Example #6
0
 public static void EditFullBook(int ID, string Name, string PublishingCompany,
                                 DateTime PublishingDate, string Size, int NumberOfPages, string CoverType,
                                 int BookTypeID, int AuthorID, string Image, double Price, int Discount)
 {
     using (var db = new BookContext())
     {
         var sach = db.Books.Find(ID);
         if (sach != null)
         {
             sach.Price             = Price;
             sach.Name              = Name;
             sach.PublishingCompany = PublishingCompany;
             sach.PublishingDate    = PublishingDate;
             sach.Size              = Size;
             sach.NumberOfPages     = NumberOfPages;
             sach.CoverType         = CoverType;
             sach.BookTypeID        = BookTypeID;
             sach.AuthorID          = AuthorID;
             sach.Image             = Image;
             sach.Discount          = Discount;
             db.Entry(sach).State   = EntityState.Modified;
             db.SaveChanges();
         }
         db.Dispose();
     }
 }
Example #7
0
        public ActionResult Remove(int Id)
        {
            BookContext db = new BookContext();

            try
            {
                Book bookToRemove = db.Books.Find(Id);

                if (bookToRemove != null)
                {
                    db.Books.Remove(bookToRemove);
                    db.SaveChanges();
                    @ViewBag.ResultMessage = Resourses.strings.BookRemoved;
                }
                else
                {
                    @ViewBag.ResultMessage = Resourses.strings.BookNotFound;
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog("LibAdminLog.txt", ex.Message);
                ViewBag.ResultMessage = Resourses.strings.BookRemovalError;
            }
            finally
            {
                db.Dispose();
            }

            return(View("Result"));
        }
 //Add a Bill Detail
 public static void AddCartDetail(int BillID, int BookID, int Count)
 {
     using (var db = new BookContext())
     {
         var billdetail = db.BillDetails.Where(bd => (bd.BillID == BillID && bd.BookID == BookID && bd.IsDeleted == false))
                          .FirstOrDefault();
         var book = db.Books.Find(BookID);
         if (billdetail == null)
         {
             billdetail = new BillDetail(BillID, BookID, Count);
             db.BillDetails.Add(billdetail);
         }
         else
         {
             billdetail.Count += Count;
         }
         //caculate total price of Bill detail from book price
         double AddValue = book.ReducePrice * Count;
         billdetail.Price += AddValue;
         //caculate cost of Bill
         var bill = db.Bills.Find(BillID);
         bill.TotalCost += AddValue;
         //update database
         db.Entry(bill).State = EntityState.Modified;
         db.SaveChanges();
         db.Dispose();
     }
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Example #10
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
Example #11
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _bookContext.Dispose();
     }
     base.Dispose(disposing);
 }
Example #12
0
 public static List <BookType> ListBookType()
 {
     using (var db = new BookContext())
     {
         var list = db.BookTypes.Where(b => b.IsDeleted == false).ToList();
         db.Dispose();
         return(list);
     }
 }
 protected override void Dispose(bool disposing)
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
     base.Dispose(disposing);
 }
 public static List <Log> ListLog()
 {
     using (var db = new BookContext())
     {
         var list = db.Logs.Include(x => x.Account).ToList();
         db.Dispose();
         return(list);
     }
 }
Example #15
0
 public static List <Account> ListAccount()
 {
     using (var db = new BookContext())
     {
         var list = db.Accounts.Include(acc => acc.Role)
                    .Where(acc => acc.IsDeleted == false).ToList();
         db.Dispose();
         return(list);
     }
 }
Example #16
0
 public static List <Account> Search(string SearchString)
 {
     using (var db = new BookContext())
     {
         var list = db.Accounts.Include(acc => acc.Role)
                    .Where(acc => acc.IsDeleted == false && (acc.FirstName.Contains(SearchString) || acc.LastName.Contains(SearchString) || acc.PhoneNumber.Contains(SearchString))).ToList();
         db.Dispose();
         return(list);
     }
 }
        protected override void Dispose(bool disposing)
        {
            if (_context != null)
            {
                _context.Dispose();
                _context = null;
            }

            base.Dispose(disposing);
        }
Example #18
0
 public static bool ChangePassword(string UserName, string Password, string NewPassword)
 {
     using (var db = new BookContext())
     {
         var account = db.Accounts.Where(acc => acc.UserName.Equals(UserName)).Single();
         if (account != null)
         {
             if (account.Password.Equals(Password))
             {
                 account.Password        = NewPassword;
                 db.Entry(account).State = EntityState.Modified;
                 db.SaveChanges(); db.Dispose();
                 return(true);
             }
         }
         db.Dispose();
         return(false);
     }
 }
 public static void DeletedBookType(int ID)
 {
     using (var db = new BookContext())
     {
         var a = db.BookTypes.Find(ID);
         a.IsDeleted       = true;
         db.Entry(a).State = EntityState.Modified;
         db.SaveChanges();
         db.Dispose();
     }
 }
Example #20
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing && _context != null)
         {
             _context.Dispose();
         }
     }
     _disposed = true;
 }
 public virtual void Dispose(bool disposing)
 {
     if (!this.disposed)
     {
         if (disposing)
         {
             db.Dispose();
         }
     }
     this.disposed = true;
 }
 public static List <Log> Search(string SearchString)
 {
     using (var db = new BookContext())
     {
         var list = db.Logs.Include(x => x.Account)
                    .Where(lg => lg.Activity.Contains(SearchString) || lg.Account.UserName.Contains(SearchString) ||
                           lg.Account.ID == int.Parse(SearchString)).ToList();//can than khong the chuyen string sang int la co bug
         db.Dispose();
         return(list);
     }
 }
 //Add Cart to bill
 public static void AddCartToBill(int AccountId)
 {
     using (var db = new BookContext())
     {
         var bill = db.Bills.Where(b => b.AccountID == AccountId).FirstOrDefault();
         bill.IsPaid          = true;
         db.Entry(bill).State = EntityState.Modified;
         db.SaveChanges();
         db.Dispose();
     }
 }
Example #24
0
 protected void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_db != null)
         {
             _db.Dispose();
             _db = null;
         }
     }
 }
Example #25
0
 public static void AddAuthor(string Name, string Description)
 {
     using (var db = new BookContext())
     {
         db.Authors.Add(new Author {
             Name = Name, Description = Description, IsDeleted = false
         });
         db.SaveChanges();
         db.Dispose();
     }
 }
 public static void ModifyBookType(int ID, string Name)
 {
     using (var db = new BookContext())
     {
         var a = db.BookTypes.Find(ID);
         a.Name            = Name;
         db.Entry(a).State = EntityState.Modified;
         db.SaveChanges();
         db.Dispose();
     }
 }
 public static Bill AddOnlyCart(int AccountId, DateTime FoundedDate)
 {
     using (var db = new BookContext())
     {
         var bill = new Bill(AccountId, FoundedDate);
         db.Bills.Add(bill);
         db.SaveChanges();
         db.Dispose();
         return(bill);
     }
 }
 public static void AddBookType(string Name)
 {
     using (var db = new BookContext())
     {
         db.BookTypes.Add(new BookType {
             Name = Name, IsDeleted = false
         });
         db.SaveChanges();
         db.Dispose();
     }
 }
 public static void Paid(int ID)
 {
     using (var db = new BookContext())
     {
         var a = db.Bills.Where(m => m.ID == ID).FirstOrDefault();
         a.IsPaid          = true;
         db.Entry(a).State = EntityState.Modified;
         db.SaveChanges();
         db.Dispose();
     }
 }
Example #30
0
 public static Book FindBook(int ID)
 {
     using (var db = new BookContext())
     {
         var sach = db.Books.Include(b => b.Author)
                    .Include(b => b.BookType)
                    .Where(b => b.ID == ID).FirstOrDefault();
         db.Dispose();
         return(sach);
     }
 }