public string AddProduct(ProductModel newProduct) { var newEntity = dbContext.Add <ProductModel>(newProduct).Entity; dbContext.SaveChanges(); return(newEntity.Name); }
public int AddOrder(OrderModel newOrder) { newOrder.OrderNumber = Orders.Count() + 1; var entity = dbContext.Add <OrderModel>(newOrder).Entity; dbContext.SaveChanges(); return(entity.OrderNumber); }
public IActionResult Register(User newUser) { if (ModelState.IsValid) { _context.User.Add(newUser); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View()); }
public IActionResult ThemNhanVienData(NhanVienView nhanvienView)//thêm đối tượng xuống database { ViewBag.Error = "1"; if (ModelState.IsValid) { using (var db = new CoffeeShopDbContext()) { var luong = new BangLuong { MaNV = nhanvienView.nhanvienDTO.MaNV.ToString(), TienThuong = 0, TamUng = 0, Luong = 0 }; db.bangluong.Add(luong); db.SaveChanges(); } _nhanvienServices.themNhanVien(nhanvienView.nhanvienDTO); ViewBag.Success = "Đã thêm thành công"; //return Redirect(nameof(ThemNhanVien)); return(RedirectToAction("Index", "NhanVien")); } ViewBag.Error = "0"; return(View(nameof(ThemNhanVien))); }
public IActionResult Post(Reservation reservation) { _coffeeShopDbContext.Reservations.Add(reservation); _coffeeShopDbContext.SaveChanges(); return(StatusCode(StatusCodes.Status201Created)); }
public IActionResult ThemPhanCaData(PhanCaView phancaView)//thêm đối tượng xuống database { ViewBag.Error = "1"; if (ModelState.IsValid) { using (var db = new CoffeeShopDbContext()) { var update = (from u in db.bangluong where u.MaNV == phancaView.phancaDTO.MaNV select u).Single(); if (phancaView.phancaDTO.HeSoLuong == 1) { update.Luong += phancaView.phancaDTO.SoGio * 20000; } else { update.Luong += phancaView.phancaDTO.SoGio * 30000; } db.SaveChanges(); } _phancaServices.themPhanCa(phancaView.phancaDTO); ViewBag.Success = "Đã thêm thành công"; //return Redirect(nameof(ThemPhanCa)); return(RedirectToAction("Index", "PhanCa")); } ViewBag.Error = "0"; return(View(nameof(ThemPhanCa))); }
public IActionResult AddItem(int Id) { RegisterUser account = JsonConvert.DeserializeObject <RegisterUser>(HttpContext.Session.GetString("ActiveUser")); var item = AvalableItems[Id].Price; if (account.Funds - item >= 0) { foreach (var user in _context.RegisterUser.ToList()) { if (user.Id == account.Id) { user.Funds -= item; HttpContext.Session.SetString("ActiveUser", JsonConvert.SerializeObject(user)); _context.RegisterUser.Update(user); _context.SaveChanges(); return(RedirectToAction("Index")); } } } Response.Cookies.Append("Funds", account.Funds.ToString()); Response.Cookies.Append("Price", item.ToString()); return(RedirectToAction("InsufficentFunds")); }
public IActionResult MakeNewUser(User newUser) { if (ModelState.IsValid) { _context.User.Add(newUser); _context.SaveChanges(); return(RedirectToAction("Shop")); } return(View()); }
/// <summary> /// The AddToCart /// </summary> /// <param name="coffee">The coffee<see cref="Coffee"/></param> /// <param name="amount">The amount<see cref="int"/></param> public void AddToCart(Coffee coffee, int amount) { var shoppingCartItem = _context.ShoppingCartItems.SingleOrDefault(s => s.Coffee.ID == coffee.ID && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Coffee = coffee, Amount = 1 }; _context.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _context.SaveChanges(); }
public IActionResult AddUser(RegisterUser user) { if (ModelState.IsValid && user != null) { _context.Add(user); _context.SaveChanges(); return(RedirectToAction("Index")); } else { return(View(user)); } }
public void DeleteEmployee(Guid employeeId) { var employeeToDelete = Employees.FirstOrDefault(e => e.Id.Equals(employeeId)); if (employeeToDelete == null) { return; } employeeToDelete.DateDeleted = DateTime.Now; dbContext.SaveChanges(); }
public IActionResult ThemChiTietNhapData(ChiTietNhapView chitietnhapView)//thêm đối tượng xuống database { ViewBag.Error = "1"; if (ModelState.IsValid) { using (var db = new CoffeeShopDbContext()) { var update = (from u in db.menu where u.MaMon == chitietnhapView.chitietnhapDTO.MaMon select u).Single(); update.SoLuongTon += chitietnhapView.chitietnhapDTO.SoLuong; db.SaveChanges(); } _chitietnhapServices.themChiTietNhap(chitietnhapView.chitietnhapDTO); ViewBag.Success = "Đã thêm thành công"; //return Redirect(nameof(ThemChiTietNhap)); return(RedirectToAction("Index", "ChiTietNhap")); } ViewBag.Error = "0"; return(View(nameof(ThemChiTietNhap))); }
public int Insert(Event entity) { db.Events.Add(entity); db.SaveChanges(); return(entity.EventID); }
public int Insert(Employee entity) { db.Employees.Add(entity); db.SaveChanges(); return(entity.EmployeeID); }
public int Insert(Product entity) { db.Products.Add(entity); db.SaveChanges(); return(entity.ProductID); }
public void SuaPhanCa(PhanCa phanca) { _conText.phanca.Update(phanca); _conText.SaveChanges(); }
public IActionResult RegisterUser() { _context.SaveChanges(); return(View()); }
public void SuaBangLuong(BangLuong bangluong) { _conText.bangluong.Update(bangluong); _conText.SaveChanges(); }
public void SuaCTHD(CTHD cthd) { _conText.cthd.Update(cthd); _conText.SaveChanges(); }
public int Insert(Shop entity) { db.Shops.Add(entity); db.SaveChanges(); return(entity.ShopID); }
public int Insert(Category entity) { db.Categories.Add(entity); db.SaveChanges(); return(entity.CategoryID); }
public void SuaMenu(Menu menu) { _conText.menu.Update(menu); _conText.SaveChanges(); }
public int Insert(Shipper entity) { db.Shippers.Add(entity); db.SaveChanges(); return(entity.ShipperID); }
public int Insert(News entity) { db.News.Add(entity); db.SaveChanges(); return(entity.NewsID); }
public int Insert(OrderDetail entity) { db.OrderDetails.Add(entity); db.SaveChanges(); return(entity.OrderDetailID); }
public void SuaHoaDon(HoaDon hoadon) { _conText.hoadon.Update(hoadon); _conText.SaveChanges(); }
public int Insert(BillDetail entity) { db.BillDetails.Add(entity); db.SaveChanges(); return(entity.BillID); }
public void SuaNhanVien(NhanVien nhanvien) { _conText.nhanvien.Update(nhanvien); _conText.SaveChanges(); }
public void SuaChiTietNhap(ChiTietNhap chitietnhap) { _conText.chitietnhap.Update(chitietnhap); _conText.SaveChanges(); }
public int Insert(Order entity) { db.Orders.Add(entity); db.SaveChanges(); return(entity.OrderID); }