public IActionResult addOrder([FromBody] TblOrderDTO order)
        {
            bool isValidToken = ValidateToken();

            if (isValidToken)
            {
                TblOrderDAO dao = TblOrderDAO.getInstance();
                try
                {
                    if (dao.AddOrder(order))
                    {
                        return(Ok(true));
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception)
                {
                    StatusCode(500);
                }
            }
            return(Unauthorized());
        }
Exemplo n.º 2
0
        public bool AddOrder(TblOrderDTO dto)
        {
            string sql = "INSERT tblOrder(idOrder, idCustomer, idEmployee, priceSum, discount, priceTotal, orderDate) " +
                         "VALUES(@idOrder, @idCustomer, @idEmp, @price, @discount, @priceTotal, @orderDate) ";

            try
            {
                cn = DBUtil.MakeConnect();
                if (cn != null)
                {
                    cmd = new SqlCommand(sql, cn);
                    cmd.Parameters.AddWithValue("@idOrder", dto.idOrder);
                    cmd.Parameters.AddWithValue("@idCustomer", dto.idCustomer);
                    cmd.Parameters.AddWithValue("@idEmp", dto.idEmployee);
                    cmd.Parameters.AddWithValue("@price", dto.priceSum);
                    cmd.Parameters.AddWithValue("@discount", dto.discount);
                    cmd.Parameters.AddWithValue("@priceTotal", dto.total);
                    cmd.Parameters.AddWithValue("@orderDate", dto.orderDate);

                    return(cmd.ExecuteNonQuery() > 0);
                }
            }
            catch (SqlException e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                DBUtil.CloseConnection(null, cn);
            }
            return(false);
        }
Exemplo n.º 3
0
        public bool AddOrder(TblOrderDTO dto)
        {
            HttpResponseMessage responseMessage = ApiConnection.loadPostJsonObject("order/add-order", dto, Program.TokenGlobal);

            if (responseMessage.IsSuccessStatusCode)
            {
                return(true);
            }
            return(false);
        }
        private void CreateOrder()
        {
            //create order id
            string      idOrder = Guid.NewGuid().ToString();
            TblOrderDTO order   = new TblOrderDTO()
            {
                idOrder    = idOrder,
                idEmployee = form.getEmployee().idEmployee,
                idCustomer = form.getCustomerId().Text,
                priceSum   = float.Parse(form.getAmount().Text),
                discount   = float.Parse(form.getDiscount().Text),
                total      = float.Parse(form.getCurrentAmount().Text),
                orderDate  = DateTime.Now,
            };

            bool isSuccess = orderModel.AddOrder(order);

            if (isSuccess)
            {
                //create order detail dto for insert to database
                List <TblOrderDetailDTO> itemList = new List <TblOrderDetailDTO>();
                foreach (var item in listProductOrder)
                {
                    TblOrderDetailDTO dto = new TblOrderDetailDTO()
                    {
                        idOrder   = idOrder,
                        idProduct = item.idProduct,
                        quantity  = item.quantity,
                        price     = item.price,
                    };
                    itemList.Add(dto);
                }

                CartDTO cart = new CartDTO(idOrder, itemList);
                isSuccess = orderModel.AddOrderDetail(cart);
                if (isSuccess)
                {
                    updateCustomerPoint();
                    MessageBox.Show(MessageUtil.CHECKOUT_SUCCESS);
                }
                else
                {
                    MessageBox.Show(MessageUtil.ERROR);
                }
            }
            else
            {
                MessageBox.Show(MessageUtil.ERROR);
            }
        }