public void updateBooktitle(int id, string newName) { var res = db.Saches.Where(x => x.ID == id).FirstOrDefault(); res.TenSach = newName; db.SaveChanges(); }
//public IList<PublisherNameOnly> getPublisherNameFromBookTitle(string booktitle) //{ // var bt = new SqlParameter("@bookTitle", booktitle); // var res = db.Database.SqlQuery<PublisherNameOnly>("proc_getPublisherNameFromBookTitle @bookTitle", bt).ToList() ; // return res; //} public void updatePublisherName(int id, string newname) { var res = db.NhaXuatBans.Where(x => x.ID == id).FirstOrDefault(); res.TenNXB = newname; db.SaveChanges(); }
public int updateCategoryName(int id, string newname) { var res = db.ChuDes.Where(x => x.ID == id).FirstOrDefault(); res.TenCD = newname; db.SaveChanges(); return(res.ID); }
public int Create(CreateBookShopDto createBookShopDto) { var bookShopEntity = _mapper.Map <BookShop>(createBookShopDto); _dbContext.BookShops.Add(bookShopEntity); _dbContext.SaveChanges(); return(bookShopEntity.Id); }
public int updateAuthor(string hoten, string diachi, string tieusu, string dienthoai, int id) { var u = db.TacGias.Where(x => x.ID == id).FirstOrDefault(); u.HoTenTG = hoten; u.DiaChi = diachi; u.TieuSu = tieusu; u.DienThoai = dienthoai; db.SaveChanges(); return(u.ID); }
public ActionResult Create([Bind(Include = "Id,Name,Author,Description,Year,Price")] Book book) { if (ModelState.IsValid) { book.Id = Guid.NewGuid(); db.Books.Add(book); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Create([Bind(Include = "Id,Sum,DateCreated,IsPaid")] ShoppingCart shoppingCart) { if (ModelState.IsValid) { shoppingCart.Id = Guid.NewGuid(); db.ShoppingCarts.Add(shoppingCart); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(shoppingCart)); }
public bool Add(Order item) { try { _context.Add(item); _context.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public int Create(int bookShopId, CreateBookDto createBookDto) { _bookServiceGuard.CheckBookShopExistsById(bookShopId); var bookEntity = _mapper.Map <Book>(createBookDto); bookEntity.BookShopId = bookShopId; _dbContext.Books.Add(bookEntity); _dbContext.SaveChanges(); return(bookEntity.Id); }
public int deletePhieuNhap(int id) { var res = db.PhieuNhaps.Where(x => x.ID == id).FirstOrDefault(); if (res != null) { db.PhieuNhaps.Remove(res); db.SaveChanges(); return(1); } else { return(0); } }
public static void SeedBooks(BookShopDbContext context) { var books = GetBooks(); context.Set <Book>().AddRange(books); context.SaveChanges(); }
public string insertDonHang(DonHang dh) { dh.DaThanhToan = true; dh.TinhTrangGiaoHang = true; dh.NgayDat = DateTime.Now; dh.NgayGiao = DateTime.Now; db.DonHangs.Add(dh); db.SaveChanges(); return(dh.ID.ToString()); }
private static void Seed(BookShopDbContext db) { var books = BookGenerator.CreateBooks(); db.Books.AddRange(books); db.SaveChanges(); Console.WriteLine("Sample data inserted successfully."); }
public int insertThamGia(int bookID, int authorID) { ThamGia thamgia = new ThamGia() { MaSach = bookID, MaTG = authorID }; db.ThamGias.Add(thamgia); db.SaveChanges(); return(thamgia.MaTG); }
public void Delete(int bookId) { var book = this.db.Books.Find(bookId); if (book == null) { return; } this.db.Remove(book); db.SaveChanges(); }
public void Delete(int categoryId) { var category = this.db.Categories.Find(categoryId); if (category == null) { return; } this.db.Remove(category); db.SaveChanges(); }
public bool Insert(OrderDetail detail) { try { db.OrderDetails.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
public bool Insert(ChiTietHoaDon chitiet) { try { db.ChiTietHoaDons.Add(chitiet); db.SaveChanges(); return(true); } catch { return(false); } }
public void insertToCart(string bookTitle, int qty, int amount, int price, int stock) { GioHang g = new GioHang(); g.BookTitle = bookTitle; g.Qty = qty; g.Amount = amount; g.Price = price; g.Stock = stock; db.GioHangs.Add(g); db.SaveChanges(); }
public void Seed() { if (_dbContext.Database.CanConnect()) { var pendingMigrations = _dbContext.Database.GetPendingMigrations(); if (pendingMigrations != null && pendingMigrations.Any()) { _dbContext.Database.Migrate(); } if (!_dbContext.BookShops.Any()) { var mainBookShop = GetMainBookShop(); _dbContext.BookShops.AddRange(mainBookShop); _dbContext.SaveChanges(); } } }
public long Insert(TinTuc entity) { db.TinTucs.Add(entity); db.SaveChanges(); return(entity.matt); }
//Update by Kien public int insertUser(User u) { db.Users.Add(u); db.SaveChanges(); return(u.ID); }
public int insertCustomer(KhachHang kh) { db.KhachHangs.Add(kh); db.SaveChanges(); return(kh.ID); }
public long Insert(LoaiSach entity) { db.LoaiSaches.Add(entity); db.SaveChanges(); return(entity.IDLoai); }
public int SaveChanges() { return(_context.SaveChanges()); }
public static void Reinitialize(BookShopDbContext context) { context.Set <Book>().RemoveRange(GetBooks()); context.SaveChanges(); Initialize(context); }
public static void Initialize(BookShopDbContext context) { SeedBooks(context); context.SaveChanges(); }
public long Insert(Account entity) { db.Accounts.Add(entity); db.SaveChanges(); return(entity.ID); }
//public long Insert(HoaDon entity) //{ // db.HoaDons.Add(entity); // db.SaveChanges(); // return entity.MaHoaDon; //} public int Insert(HoaDon hoadon) { db.HoaDons.Add(hoadon); db.SaveChanges(); return(hoadon.MaHoaDon); }
public long Insert(User entity) { db.Users.Add(entity); db.SaveChanges(); return(entity.ID); }