public ActionResult ThanhToanThanhCong(ShopMyPham.Models.MailModel model) { if (ModelState.IsValid) { string to = model.To; string subject = model.Subject; string body = model.Body; MailMessage mail = new MailMessage(); mail.To.Add(to); mail.Subject = subject; mail.Body = body; mail.From = new MailAddress("*****@*****.**"); mail.IsBodyHtml = false; SmtpClient smtp = new SmtpClient("smtp.gmail.com"); smtp.Port = 587; smtp.UseDefaultCredentials = true; smtp.EnableSsl = true; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Thinh@@01636142697"); smtp.Send(mail); ViewBag.message = "giui r"; Session["GioHang"] = null; return RedirectToAction("ViewTrangChu", "TrangChu"); } else { return View(); } }
public ActionResult GioHang(FormCollection frm, DonHang donhang, ShopMyPham.Models.MailModel model) { Session["NgayGiaoHang"] = DateTime.Parse(DateTime.Now.ToString("dd-MM-yyyy")); if (Session["MaKH"] == null) { return RedirectToAction("DangNhap", "DKDN"); } else { if (ModelState.IsValid) { donhang.MaKH = int.Parse(Session["MaKH"].ToString()); donhang.NgayDat = DateTime.Parse(DateTime.Now.ToString()); donhang.NgayGiao = DateTime.Parse(DateTime.Now.AddDays(+5).ToString("dd-MM-yyyy")); donhang.TriGia = decimal.Parse(Session["TongTien1"].ToString()); bool a = false; donhang.DaThanhToan = a; donhang.TinhTrangGiaoHang = a; donhang.TenNguoiNhan = frm["tennguoinhan"]; donhang.DienThoaiNhan = frm["dienthoainhanhang"]; donhang.DiaChiGH = frm["diachinhanhang"]; //donhang.Email = frm["email"]; db.DonHangs.Add(donhang); db.SaveChanges(); Session["Madh"] = donhang.MaDonHang; List<SanPhamGH> listSP = LayGioHang(); foreach (var item in listSP) { ChiTietDonHang ctdh = new ChiTietDonHang(); ctdh.MaDonHang = donhang.MaDonHang; ctdh.MaNuocHoa = Convert.ToInt32(item.MaSP); ctdh.SoLuong = item.SoLuong; ctdh.DonGia = (decimal)item.GiaSP; db.ChiTietDonHangs.Add(ctdh); db.SaveChanges(); } Session["GioHang"] = null; return RedirectToAction("ThanhToanThanhCong", "GioHang"); } else { return RedirectToAction("DangkY", "DKDN"); } } }