public IActionResult ThemKhachHangData(KhachHangView KhachHangView) { if (ModelState.IsValid) { _khachHangServices.ThemKhachHang(KhachHangView.KhachHangDTO); Index(); return(View(nameof(Index))); } ViewBag.Error = "Thêm khách hàng thất bại"; return(View(nameof(Index))); }
public IActionResult SuaKhachHangData(KhachHangView KhachHangView) { ViewBag.Error = "Cập nhật thành công"; if (ModelState.IsValid) { _khachHangServices.SuaKhachHang(KhachHangView.KhachHangDTO); Index(); return(View(nameof(Index))); } ViewBag.Error = "Cập nhật thất bại"; return(View()); }
public IActionResult Resgiter(KhachHangView model) { if (ModelState.IsValid) { //map tu KhachHang sang model KhachHang khachHang = _mapper.Map <KhachHang>(model); //viet xu ly tren mytool //Ham GenerateRandomKey, ToMD5. viet ben my tool khachHang.RandomKey = MyTool.GenerateRandomKey(); khachHang.MatKhau = (model.MatKhau + khachHang.RandomKey).ToMD5(); _content.Add(khachHang); _content.SaveChanges(); return(RedirectToAction("Login")); } return(View()); }
public IActionResult Checkout(KhachHangView model) { using (var transaction = ctx.Database.BeginTransaction()) { try { //chưa đăng nhập --> tạo mới khách hàng KhachHang kh = new KhachHang { MaKh = $"KH{DateTime.Now.Ticks}", HoTen = model.NguoiNhan, Email = model.Email, DiaChi = model.DiaChiGiaoHang }; ctx.Add(kh); ctx.SaveChanges(); //tạo đơn hàng DonHang hd = new DonHang { MaKh = kh.MaKh, DiaChiGiaoHang = model.DiaChiGiaoHang, NguoiNhan = model.NguoiNhan, NgayDatHang = DateTime.Now, TongTien = Cart.Sum(p => p.ThanhTien), TrangThaiDonHang = TrangThaiDonHang.MoiDangHang }; ctx.Add(hd); ctx.SaveChanges(); //tạo chi tiết đơn hàng ChiTietDonHang cthd = null; foreach (var item in Cart) { cthd = new ChiTietDonHang { MaDh = hd.Id, MaHh = item.HangMua.MaHh, SoLuong = item.SoLuong, DonGia = item.HangMua.DonGia }; ctx.Add(cthd); } ctx.SaveChanges(); transaction.Commit(); //xóa session HttpContext.Session.Remove("GioHang"); //gửi mail thông tin đơn hàng cho khách hàng string noiDung = $"Chào {model.NguoiNhan},<br>Bạn đặt hàng thành công đơn hàng <b>{hd.Id}</b>, tổng tiền thanh toán là: {hd.TongTien}."; GoogleMailer.Send(model.Email, "Xac nhan Dat hang", noiDung); } catch (SmtpException mailEx) { } catch (Exception ex) { transaction.Rollback(); } } return(RedirectToAction("Index", "HangHoa")); }
public IActionResult XoaKhachHangData(KhachHangView KhachHangView) { _khachHangServices.XoaKhachHang(KhachHangView.KhachHangDTO); Index(); return(View(nameof(Index))); }
/// <summary> /// Initializes a new instance of the <see cref="KhachHangController"/> class. /// </summary> /// <param name="currentService">The chat lieu service.</param> public KhachHangController(IKhachHangService currentService) { this.currentService = currentService; view = new KhachHangView(this); }