public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.productId)
            {
                return(BadRequest());
            }

            _context.Entry(product).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutBill(int id, Bill bill)
        {
            if (id != bill.billId)
            {
                return(BadRequest());
            }

            _context.Entry(bill).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BillExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Bill> > Checkout(Payment pay)
        {
            Bill bill = new Bill();

            bill.billDate    = DateTime.Now;
            bill.billStatus  = "Chưa giao hàng";
            bill.billPayment = pay.pay;
            bill.billNote    = pay.note;
            Users user = getUserId(pay.fullName, pay.userPhone);

            bill.userId = user.userId;
            _context.Bills.Add(bill);
            await _context.SaveChangesAsync();

            var         idBill = bill.billId;
            List <Cart> lst    = pay.cart;

            foreach (var item in lst)
            {
                BillDetail billDetail = new BillDetail();
                billDetail.billId    = idBill;
                billDetail.productId = item.product.productId;
                billDetail.price     = (decimal)item.product.productPrice;
                billDetail.quantity  = item.quantity;

                _context.Bill_details.Add(billDetail);
                await _context.SaveChangesAsync();
            }
            return(Ok());
        }
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.categoryId)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public async Task <IActionResult> PutUsers(int id, Users users)
        {
            if (id != users.userId)
            {
                return(BadRequest());
            }

            _context.Entry(users).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
        public async Task <ActionResult <Users> > UserRegistration(Users user)
        {
            user.isAdmin = 0;
            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUsers", new { id = user.userId }, user));
        }
Пример #7
0
        public async Task <ActionResult <BillDetail> > DeleteBillDetail(int id)
        {
            var billDetail = await _context.Bill_details.FindAsync(id);

            if (billDetail == null)
            {
                return(NotFound());
            }

            _context.Bill_details.Remove(billDetail);
            await _context.SaveChangesAsync();

            return(billDetail);
        }