public ActionResult Payment() { var order = new Model.EF.ORDER(); order.DATEBEGIN = DateTime.Now; try { var id = new OrderDAO().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDAO = new Model.DAO.OrderDetailDAO(); decimal total = 0; foreach (var item in cart) { var orderDetail = new Model.EF.ORDER_DETAIL(); orderDetail.ID_PRO = item.Product.ID_PRO; orderDetail.ID_CART = id; orderDetail.PRICE = item.Product.PRICE; orderDetail.SOLD_NUM = item.Quantity; detailDAO.Insert(orderDetail); total += (item.Product.PRICE.GetValueOrDefault(0) * item.Quantity); } } catch (Exception ex) { //ghi log throw ex; //return Redirect("/loi-thanh-toan"); } return(Redirect("/hoan-thanh")); }
public int ChangeStatus(long id) { var model = db.Orders.Find(id); if (model.Status == 2) { model.Status = 0; } else { if (model.Status == 0) { IList <OrderDetailViewModel> listDetail = new OrderDetailDAO().GetList(id); foreach (var item in listDetail) { new ProductDAO().SubtractQuanlity(item.orderDetail.ProductID, item.orderDetail.Quanlity); } } else if (model.Status == 1) { IList <OrderDetailViewModel> listDetail = new OrderDetailDAO().GetList(id); foreach (var item in listDetail) { new ProductDAO().AddQuanlity(item.orderDetail.ProductID, item.orderDetail.Quanlity); } } model.Status += 1; } db.SaveChanges(); return(model.Status); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new Order(); order.CreateDate = DateTime.Now; order.ShipAddress = address; order.ShipMobile = mobile; order.ShipName = shipName; order.ShipEmail = email; try { var id = new OrderDAO().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDao = new Model.DAO.OrderDetailDAO(); decimal total = 0; foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; detailDao.Insert(orderDetail); total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); } string content = System.IO.File.ReadAllText(Server.MapPath("/Asset/Client/template/neworder.html")); content = content.Replace("{{CustomerName}}", shipName); content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content); new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content); } catch (Exception) { //ghi log return(Redirect("/loi-thanh-toan")); } return(Redirect("/hoan-thanh")); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var cart = (List <CartItem>)Session[CartSession]; var order = new Order(); order.CreateDate = DateTime.Now; order.ShipAddress = address; order.ShipMobile = mobile; order.ShipName = shipName; order.ShipEmail = email; // lấy id user order.Status = true; var listSession = new List <CartItem>(); listSession = (List <CartItem>)Session[Common.CommonConstants.CartSession]; foreach (var item in listSession) { order.GiaShip = item.GiaShip; break; } order.TongTien = cart.Sum(x => Convert.ToInt64(x.Product.PromotionPrice) * x.Quantity) + order.GiaShip; SanPham sanPham = new SanPham(); SanPhamDAO sanPhamDAO = new SanPhamDAO(); try { var id = new OrderDAO().Insert(order); var detailDao = new Model.DAO.OrderDetailDAO(); decimal?total = order.TongTien; foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.SanPhamID = item.Product.SanPhamID; orderDetail.OrderID = id; orderDetail.DonGia = item.Product.PromotionPrice; orderDetail.Quantity = item.Quantity; orderDetail.ThanhTien = (Convert.ToInt64(orderDetail.DonGia) * item.Quantity).ToString(); detailDao.Insert(orderDetail); var soLuong = sanPhamDAO.ListAll().Where(x => x.SanPhamID == orderDetail.SanPhamID).ToList(); foreach (var soluong in soLuong) { sanPham.SanPhamID = soluong.SanPhamID; sanPham.Image = soluong.Image; sanPham.TenSanPham = soluong.TenSanPham; sanPham.DonGia = soluong.DonGia; sanPham.PromotionPrice = soluong.PromotionPrice; sanPham.TomTat = soluong.TomTat; sanPham.Description = soluong.Description; sanPham.MetaKeyword = soluong.MetaKeyword; sanPham.Quantity = soluong.Quantity - item.Quantity; sanPham.DanhMucSanPhamID = soluong.DanhMucSanPhamID; sanPham.Status = soluong.Status; sanPhamDAO.Update(sanPham); } } } catch (Exception ex) { //ghi log return(Redirect("/Cart/Error")); } Session[CartSession] = null; return(Redirect("/Cart/Success")); }