public ActionResult AddCart(long ID = 0) { var obj = sc.findObjectByID(ID); gModels.Cart cart; if (Session["Cart"] == null) { cart = new Cart(); } else { cart = (gModels.Cart)Session["Cart"]; } var cartitem = cart.find(obj.ID); if (cartitem == null) { cart.AddUpdateCart(new gModels.CartItem() { Quantity = 1, Object = obj, ID = obj.ID }); Session["Cart"] = cart; return Json(new { success = true, count = cart.Count }, JsonRequestBehavior.AllowGet); } else { Session["Cart"] = cart; return Json(new { success = false, msg = "Đã thêm trong giỏ hàng!", count = cart.Count }, JsonRequestBehavior.AllowGet); } }
public ActionResult AddCart(gObject obj, string Size, string Color, int Quantity) { gModels.Cart cart; if (Session["Cart"] == null) { cart = new Cart(); } else { cart = (gModels.Cart)Session["Cart"]; } var cartitem = cart.find(obj.ID); if (cartitem == null) { cart.AddUpdateCart(new gModels.CartItem() { Color = Color, Size = Size, Price = (obj.Attrs[1].AttrValue == null ? int.Parse(obj.Attrs[0].AttrValue) : int.Parse(obj.Attrs[1].AttrValue)), Quantity = Quantity, Pricing = Quantity * (obj.Attrs[1].AttrValue == null ? int.Parse(obj.Attrs[0].AttrValue) : int.Parse(obj.Attrs[1].AttrValue)), Object = obj, ID = obj.ID },cart); Session["Cart"] = cart; return Json(new { success = true, count = cart.Count }, JsonRequestBehavior.AllowGet); } else { Session["Cart"] = cart; return Json(new { success = false, msg = "Đã thêm trong giỏ hàng!", count = cart.Count }, JsonRequestBehavior.AllowGet); } }
public ActionResult GetCart() { gModels.Cart cart = null; if (Session["Cart"] != null) { cart = (gModels.Cart)Session["Cart"]; } else { cart = new Cart(); } return Json(new { success = true, data = cart }, JsonRequestBehavior.AllowGet); }
public ActionResult getAppConfig() { gModels.Cart cart = null; if (Session["Cart"] != null) { cart = (gModels.Cart)Session["Cart"]; } else { cart = new Cart(); } return Json(new { success = true, ShoppingCart = cart, config = sc.getOneObject("config", Organize.ID), menus = sc.ListObjectWithChild("menu", Organize.ID, " order by o.gOrder asc ", " order by o.gOrder asc "), ProvinceList = sc.GetListProvince() }, JsonRequestBehavior.AllowGet); }
public ActionResult DoOrder(gModels.User people,string paymentmethod,long shipfee) { gModels.Cart cart = null; if (Session["Cart"] != null) { cart = (gModels.Cart)Session["Cart"]; } else { return Json(new { success = false }, JsonRequestBehavior.AllowGet); } long Idcustomer = 0; if (User.Identity.IsAuthenticated) { var u = _userService.GetUserByEmail(User.Identity.Name); if (u == null) return Json(new { success = false, msg = "Not login" }, JsonRequestBehavior.AllowGet); Idcustomer = u.ID; } else { var customer = sc.findCustomer(people.Email, people.Phone); if (customer == null) { Idcustomer = sc.NewCustomer(people, Organize.ID); } else { Idcustomer = customer.ID; } } string error = ""; int result = sc.AddOrder(cart, Idcustomer, people, paymentmethod, shipfee); if (result > 0) { var mailconfig = sc.getOneObject("mailconfig", Organize.ID); //send mail to mailconfig var config = mailconfig.Attrs.ToDictionary(m => m.AttrName, m => m.AttrValue); try { var template = sc.getOneObject("mailtemplate", Organize.ID); var SmtpServer = new SmtpClient(config["host"]); SmtpServer.Port = int.Parse(config["port"]); SmtpServer.Credentials = new System.Net.NetworkCredential(config["user"], config["password"]); SmtpServer.EnableSsl = true; //get email template var dnow = DateTime.Now; var templateconfig = template.Attrs.ToDictionary(m => m.AttrName, m => m.AttrValue); var emailcontent = templateconfig["mailcontent"]; emailcontent = emailcontent.Replace("_TOTALAMOUNT_", String.Format("{0:0,0 vnđ}", cart.TotalAmount)); emailcontent = emailcontent.Replace("_TIME_", dnow.ToString("hh:mm:ss dd/MM/yyyy")); emailcontent = emailcontent.Replace("_NAME_", people.FullName); int i = 1; string cartstr = "<table cellspacing='0' cellpadding='10' border='1' style='width:100%'><tr style='background:#038738;color:#fff'><td>#</td><td>Sản phẩm</td><td>Số lượng</td><td>Đơn giá</td><td>Thành tiền</td></tr>"; foreach (var citem in cart.List) { cartstr += "<tr>"; cartstr += "<td style='text-align:center'>"; cartstr += i.ToString(); cartstr += "</td>"; cartstr += "<td>"; if (!string.IsNullOrEmpty(citem.Object.gImage)) { string imglink = citem.Object.gImage; cartstr += "<img style='width:50px;height:50px;float:left;margin-right:10px' src='" + imglink + "' alt='" + citem.Object.Title + "'/>"; } cartstr += "<span style='float:left;padding-top:10px;font-weight:bold'>" + citem.Object.Title + "</span>"; cartstr += "</td>"; cartstr += "<td style='text-align:center'>"; cartstr += citem.Quantity; cartstr += "</td>"; cartstr += "<td>"; cartstr += String.Format("{0:0,0 }",1); cartstr += "</td>"; cartstr += "<td>"; cartstr += String.Format("{0:0,0 }", citem.Pricing); cartstr += "</td>"; cartstr += "</tr>"; i += 1; } cartstr += "<tr>"; cartstr += "<td colspan='4'></td><td>"; cartstr += "<span style='color:green;font-size:18px;font-weight:bold;'>" + String.Format("{0:0,0 }", cart.TotalAmount) + "</span> VND"; cartstr += "</td>"; cartstr += "</tr>"; cartstr += "</table>"; emailcontent = emailcontent.Replace("_CART_", cartstr); MatchCollection matchCollection = Regex.Matches(emailcontent, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase); foreach (Match match in matchCollection) { string value = match.Groups[1].Value; emailcontent = emailcontent.Replace(value, HttpUtility.UrlDecode(value)); } string customerstr = "<table cellspacing='0' cellpadding='10' border='1'><tr style='background:#038738;color:#fff'><td>Họ và tên</td><td>Số điện thoại</td><td>Email</td><td>Địa chỉ</td></tr><tr><td>" + people.FullName + "</td><td>" + people.Phone + "</td><td>" + people.Email + "</td><td>" + people.Address + "</td></tr><tr><td>Ghi chú</td><td colspan='3'></td></tr></table>"; emailcontent = emailcontent.Replace("_CUSTOMER_", customerstr); emailcontent = emailcontent.Replace("_LINKCHECKORDER_", "<a href='" + Request.Url.GetLeftPart(UriPartial.Authority) + "/kiem-tra-don-hang?email=" + HttpUtility.UrlEncode(people.Email) + "&phone=" + HttpUtility.UrlEncode(people.Phone) + "' target='_blank'>Kiểm tra đơn hàng</a>"); try { var email = new GuMail(); email.mSmtp = SmtpServer; email.From = config["user"]; email.Title = templateconfig["mailtitle"] + " - " + dnow.ToString("hh:mm:ss dd/MM/yyyy"); email.ContentText = templateconfig["shortdescription"]; email.ContentHtml = emailcontent; email.To = people.Email; email.Send(); } catch (Exception er) { error += "Không thể gửi mail tới email của bạn" + er.Message; } try { var email = new GuMail(); email.mSmtp = SmtpServer; email.From = config["user"]; email.Title = templateconfig["mailtitle"] + " - " + dnow.ToString("hh:mm:ss dd/MM/yyyy"); email.ContentText = templateconfig["shortdescription"]; email.ContentHtml = emailcontent; email.To = config["notifyemail"]; email.Send(); } catch (Exception err) { error += "\n Không thể gửi mail tới email của bạn" + err.Message; } } catch { } // cart = new Cart(); Session["Cart"] = cart; } return Json(new { success = true, data = result, error = error }, JsonRequestBehavior.AllowGet); }
public ActionResult RemoveCart(long ID) { gModels.Cart cart = null; if (Session["Cart"] != null) { cart = (gModels.Cart)Session["Cart"]; } else { cart = new Cart(); } if (cart.Remove(ID) > 0) { Session["Cart"] = cart; return Json(new { success = true, cart.Count, cart.TotalAmount }, JsonRequestBehavior.AllowGet); } else { return Json(new { success = false, msg = "Không thể xóa nội dung này khỏi giỏ hàng" }, JsonRequestBehavior.AllowGet); } }
public ActionResult getAppConfig() { gModels.Cart cart = null; if (Session["Cart"] != null) { cart = (gModels.Cart)Session["Cart"]; } else { cart = new Cart(); } gModels.User u = null; if (User.Identity.IsAuthenticated) { u = _userService.GetUserByEmail(User.Identity.Name); } return Json(new { success = true, ShoppingCart = cart, config = sc.getOneObject("config", Organize.ID), menus = sc.getListObject("Product",null,null,1,12, Organize.ID), User = u, ProvinceList = sc.GetListProvince() }, JsonRequestBehavior.AllowGet); }