Beispiel #1
0
        //[HttpPost]
        public RedirectToRouteResult AddItem(int ItemID, decimal Price, int Qtty = 1)
        {
            //int Qtty = 0;
            //int.TryParse(Request.Form["quantity"] + "", out Qtty);
            if (Session[Session.SessionID] == null)
            {
                Session[Session.SessionID] = new List <tbl_OrderDetail>();
            }

            List <tbl_OrderDetail> list = Session[Session.SessionID] as List <tbl_OrderDetail>;

            if (list.Find(a => a.ItemID == ItemID) != null)
            {
                var item = list.Find(a => a.ItemID == ItemID);
                item.Qty   += Qtty;
                item.Amount = item.Qty * item.Price;
            }
            else
            {
                tbl_OrderDetail ct = new tbl_OrderDetail();
                ct.ItemID    = ItemID;
                ct.tbl_Items = db.tbl_Items.Find(ItemID);
                ct.Qty       = Qtty;
                ct.Price     = Price;
                ct.Amount    = Qtty * Price;
                list.Add(ct);
            }
            TempData[Session.SessionID] = list;
            return(RedirectToAction("Details", "Order"));
        }
Beispiel #2
0
 public static string Insert(int AgentID, int OrderID, string SKU, int ProductID, int ProductVariableID, string ProductVariableDescrition, double Quantity,
                             double Price, int Status, double DiscountPrice, int ProductType, DateTime CreatedDate, string CreatedBy, bool IsCount)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_OrderDetail ui = new tbl_OrderDetail();
         ui.AgentID                   = AgentID;
         ui.OrderID                   = OrderID;
         ui.SKU                       = SKU;
         ui.ProductID                 = ProductID;
         ui.ProductVariableID         = ProductVariableID;
         ui.ProductVariableDescrition = ProductVariableDescrition;
         ui.Quantity                  = Quantity;
         ui.Price                     = Convert.ToDouble(Price);
         ui.Status                    = Status;
         ui.DiscountPrice             = DiscountPrice;
         ui.ProductType               = ProductType;
         ui.CreatedDate               = CreatedDate;
         ui.CreatedBy                 = CreatedBy;
         ui.IsCount                   = IsCount;
         dbe.tbl_OrderDetail.Add(ui);
         int kq = dbe.SaveChanges();
         return(kq.ToString());
     }
 }
        public void InsertOrderDetail(string OrderID, List <OrderDetail> lst_OrderDetail)
        {
            using (OnlineShoppingDataContext db = new OnlineShoppingDataContext())
            {
                foreach (OrderDetail obj_OrderDetail in lst_OrderDetail)
                {
                    tbl_OrderDetail tbl_detail = (from a in db.tbl_OrderDetails
                                                  where a.ProductID == obj_OrderDetail.ProductID && a.OrderID == OrderID
                                                  select a).FirstOrDefault();
                    if (tbl_detail != null)
                    {
                        tbl_detail.Quantity = Convert.ToInt32(tbl_detail.Quantity) + obj_OrderDetail.Quantity;
                        db.SubmitChanges();
                    }
                    else
                    {
                        tbl_OrderDetail tbl_orderdetail = new tbl_OrderDetail();
                        tbl_orderdetail.OrderID        = OrderID.ToString();
                        tbl_orderdetail.ProductID      = obj_OrderDetail.ProductID;
                        tbl_orderdetail.Quantity       = obj_OrderDetail.Quantity;
                        tbl_orderdetail.Price          = obj_OrderDetail.Price;
                        tbl_orderdetail.DiscountAmount = obj_OrderDetail.DiscountAmount;

                        db.tbl_OrderDetails.InsertOnSubmit(tbl_orderdetail);
                        db.SubmitChanges();
                    }
                }
            }
        }
Beispiel #4
0
        public static string Insert(int AgentID, int OrderID, string SKU, int ProductID, int ProductVariableID, string ProductVariableDescrition, double Quantity,
                                    double Price, int Status, double DiscountPrice, int ProductType, DateTime CreatedDate, string CreatedBy, bool IsCount)
        {
            using (var con = new inventorymanagementEntities())
            {
                #region Cập nhật thôn tin giá vốn
                Nullable <double> cogs = null;

                #region Sản phẩm đơn gian
                if (ProductType == 1)
                {
                    cogs = con.tbl_Product
                           .Where(x => x.ID == ProductID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion

                #region Sản phẩm biến thể
                if (ProductType == 2)
                {
                    cogs = con.tbl_ProductVariable
                           .Where(x => x.ID == ProductVariableID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion
                #endregion

                #region Khởi tạo chi tiết đơn hàng
                tbl_OrderDetail ui = new tbl_OrderDetail();
                ui.AgentID                   = AgentID;
                ui.OrderID                   = OrderID;
                ui.SKU                       = SKU;
                ui.ProductID                 = ProductID;
                ui.ProductVariableID         = ProductVariableID;
                ui.ProductVariableDescrition = ProductVariableDescrition;
                ui.Quantity                  = Quantity;
                ui.Price                     = Convert.ToDouble(Price);
                ui.Status                    = Status;
                ui.DiscountPrice             = DiscountPrice;
                ui.ProductType               = ProductType;
                ui.CreatedDate               = CreatedDate;
                ui.CreatedBy                 = CreatedBy;
                ui.ModifiedDate              = CreatedDate;
                ui.ModifiedBy                = CreatedBy;
                ui.IsCount                   = IsCount;
                ui.CostOfGood                = cogs.HasValue ? Convert.ToDecimal(cogs.Value) : 0;
                con.tbl_OrderDetail.Add(ui);
                int kq = con.SaveChanges();
                #endregion

                return(kq.ToString());
            }
        }
Beispiel #5
0
        public static void Insert(tbl_OrderDetail orderDetail)
        {
            using (var con = new inventorymanagementEntities())
            {
                #region Cập nhật thôn tin giá vốn
                Nullable <double> cogs = null;

                #region Sản phẩm đơn gian
                if (orderDetail.ProductType == 1)
                {
                    cogs = con.tbl_Product
                           .Where(x => x.ID == orderDetail.ProductID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion

                #region Sản phẩm biến thể
                if (orderDetail.ProductType == 2)
                {
                    cogs = con.tbl_ProductVariable
                           .Where(x => x.ID == orderDetail.ProductVariableID)
                           .Select(x => x.CostOfGood.HasValue ? x.CostOfGood.Value : 0)
                           .SingleOrDefault();
                }
                #endregion
                #endregion

                #region Khởi tạo chi tiết đơn hàng
                tbl_OrderDetail ui = new tbl_OrderDetail();
                ui.AgentID                   = orderDetail.AgentID;
                ui.OrderID                   = orderDetail.OrderID;
                ui.SKU                       = orderDetail.SKU;
                ui.ProductID                 = orderDetail.ProductID;
                ui.ProductVariableID         = orderDetail.ProductVariableID;
                ui.ProductVariableDescrition = orderDetail.ProductVariableDescrition;
                ui.Quantity                  = orderDetail.Quantity;
                ui.Price                     = orderDetail.Price;
                ui.Status                    = orderDetail.Status;
                ui.DiscountPrice             = orderDetail.DiscountPrice;
                ui.ProductType               = orderDetail.ProductType;
                ui.CreatedDate               = orderDetail.CreatedDate;
                ui.CreatedBy                 = orderDetail.CreatedBy;
                ui.ModifiedDate              = orderDetail.ModifiedDate;
                ui.ModifiedBy                = orderDetail.ModifiedBy;
                ui.IsCount                   = orderDetail.IsCount;
                ui.CostOfGood                = cogs.HasValue ? Convert.ToDecimal(cogs.Value) : 0;
                con.tbl_OrderDetail.Add(ui);
                con.SaveChanges();
                #endregion
            }
        }
 private bool InsertOrderDetail(tbl_OrderDetail orderdetail)
 {
     try
     {
         db.tbl_OrderDetail.Add(orderdetail);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #7
0
 public static tbl_OrderDetail GetByID(int ID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_OrderDetail ai = dbe.tbl_OrderDetail.Where(a => a.ID == ID).SingleOrDefault();
         if (ai != null)
         {
             return(ai);
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #8
0
 public static void Insert(tbl_OrderDetail orderDetail)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         tbl_OrderDetail ui = new tbl_OrderDetail();
         ui.AgentID                   = orderDetail.AgentID;
         ui.OrderID                   = orderDetail.OrderID;
         ui.SKU                       = orderDetail.SKU;
         ui.ProductID                 = orderDetail.ProductID;
         ui.ProductVariableID         = orderDetail.ProductVariableID;
         ui.ProductVariableDescrition = orderDetail.ProductVariableDescrition;
         ui.Quantity                  = orderDetail.Quantity;
         ui.Price                     = orderDetail.Price;
         ui.Status                    = orderDetail.Status;
         ui.DiscountPrice             = orderDetail.DiscountPrice;
         ui.ProductType               = orderDetail.ProductType;
         ui.CreatedDate               = orderDetail.CreatedDate;
         ui.CreatedBy                 = orderDetail.CreatedBy;
         ui.IsCount                   = orderDetail.IsCount;
         dbe.tbl_OrderDetail.Add(ui);
         dbe.SaveChanges();
     }
 }
Beispiel #9
0
        public ActionResult AddressAndPayment(OrderViewModel ovm)
        {
            var cart = ShoppingCart.GetCart(this.HttpContext);

            tbl_Order tb = new tbl_Order();

            tb.username      = Session["username"].ToString();
            tb.firstname     = ovm.firstname;
            tb.lastname      = ovm.lastname;
            tb.address       = ovm.address;
            tb.phone         = ovm.phone;
            tb.total         = cart.GetTotal();
            tb.orderDate     = Convert.ToDateTime(DateTime.Today.ToShortDateString());
            tb.delivayStatus = "Pending";

            storeDB.tbl_Order.Add(tb);
            storeDB.SaveChanges();


            List <tbl_Cart> lst = cart.GetCartItems();

            foreach (var item in lst)
            {
                tbl_OrderDetail tbord = new tbl_OrderDetail();
                tbord.orderID   = tb.orderID;
                tbord.productID = item.productID;
                tbord.quantity  = item.count;
                tbord.unitPrice = item.tbl_Product.sellingPrice;
                storeDB.tbl_OrderDetail.Add(tbord);
                storeDB.SaveChanges();
            }


            ViewBag.Message = "Your Ordered Done Successfully, It Takes 2/3 Hours In Our working Days";
            return(View());
        }
        public ActionResult OrderTour(string tenKH, string diaChi, string soDT, string email, string datetimepickerOrder, string ghiChu)
        {
            var cart  = (List <CardItemModel>)Session[CommonConstants.CardSession];
            var admin = db.tbl_Account.FirstOrDefault();

            if (!string.IsNullOrEmpty(tenKH) && !string.IsNullOrEmpty(diaChi) && !string.IsNullOrEmpty(soDT))
            {
                var order = new tbl_Orders();
                order.TenKH     = tenKH;
                order.DiaChi    = diaChi;
                order.SoDT      = soDT;
                order.Email     = email;
                order.NgayDat   = DateTime.Now;
                order.NgayCanDi = datetimepickerOrder == null ? DateTime.Now : DateTime.ParseExact(datetimepickerOrder, "yyyy-MM-dd",
                                                                                                   new CultureInfo("en-US"),
                                                                                                   DateTimeStyles.None);
                order.GhiChu = ghiChu;

                try
                {
                    var id = Insert(order);

                    string tentour = null;
                    int    songuoi = 0;
                    foreach (var item in cart)
                    {
                        var orderDetail = new tbl_OrderDetail();
                        orderDetail.TourID  = item.Tour.Id;
                        orderDetail.OrderID = id;
                        orderDetail.DonGia  = item.Tour.DonGia;
                        orderDetail.SoNguoi = item.SoNguoi;
                        tentour            += item.Tour.TenTourTL;
                        songuoi            += item.SoNguoi;
                        InsertOrderDetail(orderDetail);
                    }

                    string content = System.IO.File.ReadAllText(Server.MapPath("~/Views/OrderMail/NewOrderTourSendAdmin.cshtml"));
                    content = content.Replace("{{TenKH}}", tenKH);
                    content = content.Replace("{{SoDT}}", soDT);
                    content = content.Replace("{{Email}}", email);
                    content = content.Replace("{{DiaChi}}", diaChi);
                    content = content.Replace("{{TenTour}}", tentour);
                    content = content.Replace("{{SoNguoi}}", songuoi.ToString("N0"));

                    if (admin.Email != null)
                    {
                        string contentCusstom = null;
                        if (CommonConstants.CurrentCulture == null)
                        {
                            contentCusstom = System.IO.File.ReadAllText(Server.MapPath("~/Views/OrderMail/NewOrderTourSendCustom.cshtml"));
                            contentCusstom = contentCusstom.Replace("{{TenTour}}", tentour);
                            new MailHelper().SendMail(order.Email, Resource.lblConfigOderTour, null, contentCusstom, false, false);
                        }
                        else if (CommonConstants.CurrentCulture.Equals("vi"))
                        {
                            contentCusstom = System.IO.File.ReadAllText(Server.MapPath("~/Views/OrderMail/NewOrderTourSendCustom_vi.cshtml"));
                            contentCusstom = contentCusstom.Replace("{{TenTour}}", tentour);
                            new MailHelper().SendMail(order.Email, Resource.lblConfigOderTour, null, contentCusstom, false, false);
                        }
                        else
                        {
                            contentCusstom = System.IO.File.ReadAllText(Server.MapPath("~/Views/OrderMail/NewOrderTourSendCustom_en.cshtml"));
                            contentCusstom = contentCusstom.Replace("{{TenTour}}", tentour);
                            new MailHelper().SendMail(order.Email, Resource.lblConfigOderTour, null, contentCusstom, false, false);
                        }
                        var toEmail = admin.Email;

                        new MailHelper().SendMail(toEmail, "Khách hàng đặt tour mới", tenKH, content, false, true);
                        Session[CommonConstants.CardSession] = null;
                        return(RedirectToAction("Success"));
                    }
                }
                catch (Exception ex)
                {
                    return(RedirectToAction("OrderTourError"));
                }
                return(RedirectToAction("OrderTourError"));
            }
            else
            {
                ViewBag.ValidateOrder = Resource.vbErrorOderTour;
                return(View("Index", cart));
            }
        }