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());
 }
示例#4
0
        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)));
        }
示例#5
0
        public IActionResult Post(Reservation reservation)
        {
            _coffeeShopDbContext.Reservations.Add(reservation);
            _coffeeShopDbContext.SaveChanges();

            return(StatusCode(StatusCodes.Status201Created));
        }
示例#6
0
 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)));
 }
示例#7
0
        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());
 }
示例#9
0
        /// <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();
        }
示例#10
0
 public IActionResult AddUser(RegisterUser user)
 {
     if (ModelState.IsValid && user != null)
     {
         _context.Add(user);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(user));
     }
 }
示例#11
0
        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)));
 }
示例#13
0
 public int Insert(Event entity)
 {
     db.Events.Add(entity);
     db.SaveChanges();
     return(entity.EventID);
 }
示例#14
0
 public int Insert(Employee entity)
 {
     db.Employees.Add(entity);
     db.SaveChanges();
     return(entity.EmployeeID);
 }
示例#15
0
 public int Insert(Product entity)
 {
     db.Products.Add(entity);
     db.SaveChanges();
     return(entity.ProductID);
 }
示例#16
0
 public void SuaPhanCa(PhanCa phanca)
 {
     _conText.phanca.Update(phanca);
     _conText.SaveChanges();
 }
示例#17
0
 public IActionResult RegisterUser()
 {
     _context.SaveChanges();
     return(View());
 }
示例#18
0
 public void SuaBangLuong(BangLuong bangluong)
 {
     _conText.bangluong.Update(bangluong);
     _conText.SaveChanges();
 }
示例#19
0
 public void SuaCTHD(CTHD cthd)
 {
     _conText.cthd.Update(cthd);
     _conText.SaveChanges();
 }
示例#20
0
 public int Insert(Shop entity)
 {
     db.Shops.Add(entity);
     db.SaveChanges();
     return(entity.ShopID);
 }
示例#21
0
 public int Insert(Category entity)
 {
     db.Categories.Add(entity);
     db.SaveChanges();
     return(entity.CategoryID);
 }
示例#22
0
 public void SuaMenu(Menu menu)
 {
     _conText.menu.Update(menu);
     _conText.SaveChanges();
 }
示例#23
0
 public int Insert(Shipper entity)
 {
     db.Shippers.Add(entity);
     db.SaveChanges();
     return(entity.ShipperID);
 }
示例#24
0
 public int Insert(News entity)
 {
     db.News.Add(entity);
     db.SaveChanges();
     return(entity.NewsID);
 }
示例#25
0
 public int Insert(OrderDetail entity)
 {
     db.OrderDetails.Add(entity);
     db.SaveChanges();
     return(entity.OrderDetailID);
 }
示例#26
0
 public void SuaHoaDon(HoaDon hoadon)
 {
     _conText.hoadon.Update(hoadon);
     _conText.SaveChanges();
 }
示例#27
0
 public int Insert(BillDetail entity)
 {
     db.BillDetails.Add(entity);
     db.SaveChanges();
     return(entity.BillID);
 }
示例#28
0
 public void SuaNhanVien(NhanVien nhanvien)
 {
     _conText.nhanvien.Update(nhanvien);
     _conText.SaveChanges();
 }
 public void SuaChiTietNhap(ChiTietNhap chitietnhap)
 {
     _conText.chitietnhap.Update(chitietnhap);
     _conText.SaveChanges();
 }
示例#30
0
 public int Insert(Order entity)
 {
     db.Orders.Add(entity);
     db.SaveChanges();
     return(entity.OrderID);
 }