コード例 #1
0
 public ActionResult Edit(OrderDetailModel orderDetailModel)
 {
     if (ModelState.IsValid)
     {
         var orderDetail = new OrderDetail
         {
             ID        = orderDetailModel.ID,
             ProductID = orderDetailModel.ProductID,
             OrderID   = orderDetailModel.OrderID,
             Quantity  = orderDetailModel.Quantity,
             Price     = orderDetailModel.Price
         };
         var result = OrderDetailsBLL.UpdateOrderDetaiL(orderDetail);
         if (result > 0)
         {
             SetAlert("Sửa user thành công", "success");
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("", "Cập nhật user không thành công");
         }
     }
     return(View(orderDetailModel));
 }
コード例 #2
0
        public bool Insert(OrderDetailsBLL odbll)
        {
            bool IsSuccess = false;

            SqlConnection con = new SqlConnection(_con.connection);
            string        sql = "INSERT INTO[dbo].[Orders]" +
                                "([ORDERDATE]" +
                                ",[PAYDATE]" +
                                ",[CUSTOMERID]" +
                                ",[USERID]" +
                                ",[PAYMENTMODE]" +
                                ",[AMOUNTPAID]" +
                                ",[DISCOUNT]" +
                                ",[STATUS]" +
                                ",[COMMENT])" +
                                "VALUES" +
                                "(@ORDERDATE" +
                                ",@PAYDATE" +
                                ",@CUSTOMERID" +
                                ",@USERID" +
                                ",@PAYMENTMODE" +
                                ",@AMOUNTPAID" +
                                ",@DISCOUNT" +
                                ",@STATUS" +
                                ",@COMMENT)";

            try
            {
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@ORDERDATE", odbll.OrderDate);
                cmd.Parameters.AddWithValue("@PAYDATE", odbll.PayDate);
                cmd.Parameters.AddWithValue("@CUSTOMERID", odbll.CustomerID);
                cmd.Parameters.AddWithValue("@USERID", odbll.UserID);
                cmd.Parameters.AddWithValue("@PAYMENTMODE", odbll.PaymentMode);
                cmd.Parameters.AddWithValue("@AMOUNTPAID", odbll.AmountPaid);
                cmd.Parameters.AddWithValue("@DISCOUNT", odbll.OrderDate);
                cmd.Parameters.AddWithValue("@STATUS", odbll.Status);
                cmd.Parameters.AddWithValue("@COMMENT", odbll.Comment);
                con.Open();
                int i = cmd.ExecuteNonQuery();
                if (i > 0)
                {
                    IsSuccess = true;
                }
                else
                {
                    IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Data Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }finally
            {
                con.Close();
            }
            return(IsSuccess);
        }
コード例 #3
0
        public ActionResult Edit(int ID)
        {
            var orderDetail      = OrderDetailsBLL.GetOrderDetail(ID);
            var orderDetailModel = new OrderDetailModel
            {
                ID        = orderDetail.ID,
                ProductID = orderDetail.ProductID,
                OrderID   = orderDetail.OrderID,
                Quantity  = orderDetail.Quantity,
                Price     = orderDetail.Price
            };

            return(View(orderDetail));
        }
コード例 #4
0
        public ActionResult Payment()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    decimal total  = 0;
                    int     result = 0;

                    if (Session[CommonConstants.USER_SESSION] == null)
                    {
                        return(Redirect("/dang-nhap"));
                    }
                    var userLogin = Session[CommonConstants.USER_SESSION] as UserLogin;
                    var user      = UserBLL.GetUserByID(userLogin.UserName);
                    var order     = new Order
                    {
                        ShipName    = user.Name,
                        ShipMobile  = user.Phone,
                        ShipAddress = user.Address,
                        ShipEmail   = user.Email
                    };
                    OrderBLL.InsertOrder(order);
                    var cart = Session[CommonConstants.CART_SESSION] as List <CartItem>;
                    for (int i = 0; i < cart.Count; i++)
                    {
                        var orderDetails = new OrderDetail
                        {
                            ProductID = cart[i].ProductID,
                            OrderID   = order.ID,
                            Quantity  = cart[i].Quantity,
                            Price     = cart[i].Price
                        };
                        result = OrderDetailsBLL.InsertOrderDetails(orderDetails);
                        total += (cart[i].Price * cart[i].Quantity);
                    }
                    if (result > 0)
                    {
                        Session[CommonConstants.USER_SESSION] = null;
                        //string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/NewOrder.html"));
                        //content = content.Replace("{{CustomerName}}", user.Name);
                        //content = content.Replace("{{Phone}}", user.Phone);
                        //content = content.Replace("{{Email}}", user.Email);
                        //content = content.Replace("{{Address}}", user.Address);
                        //content = content.Replace("{{Total}}", total.ToString("N0"));
                        //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                        //var mailHelper = new MailHelper();
                        //mailHelper.SendEmail(user.Email, "Đơn hàng mới từ OnlineShop", content);
                        //mailHelper.SendEmail(toEmail, "Đơn hàng mới từ OnlineShop", content);
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
                return(Redirect("/hoan-thanh"));
            }
            ViewBag.Cart = Cart();

            return(View());
        }
コード例 #5
0
 // POST: api/OrderDetails
 public bool Post([FromBody] ORDERDETAILS details) => OrderDetailsBLL.InsertOrderDetails(details);
コード例 #6
0
 // GET: api/OrderDetails/5
 public IEnumerable <ORDERDETAILS> Get(int id) => OrderDetailsBLL.GetOrdeDetails(id);
コード例 #7
0
 // GET: api/OrderDetails
 public IEnumerable <ORDERDETAILS> Get() => OrderDetailsBLL.GetAllOrderDetails();
コード例 #8
0
 public ActionResult Delete(int ID)
 {
     OrderDetailsBLL.DeleteOrderDetail(ID);
     return(RedirectToAction("Index"));
 }
コード例 #9
0
        public ActionResult Index()
        {
            var orderDetails = OrderDetailsBLL.GetOrderDetails();

            return(View(orderDetails));
        }