public async Task <IActionResult> Edit(int id, [Bind("KhachHangId,KhachHangTen,KhachHangSoDienThoai,KhachHangEmail,KhachHangNgaySinh,KhachHangChungMinhNhanDan,NgayTao")] TourKhachHang tourKhachHang) { if (id != tourKhachHang.KhachHangId) { return(NotFound()); } if (ModelState.IsValid) { try { context.Update(tourKhachHang); await context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TourKhachHangExists(tourKhachHang.KhachHangId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(tourKhachHang)); }
public async Task <IActionResult> Create([Bind("KhachHangId,KhachHangTen,KhachHangSoDienThoai,KhachHangEmail,KhachHangNgaySinh,KhachHangChungMinhNhanDan,NgayTao")] TourKhachHang tourKhachHang) { if (ModelState.IsValid) { context.Add(tourKhachHang); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(tourKhachHang)); }
public ActionResult Index(TourKhachHang tour) { long giaTour = 0; if (TempData.ContainsKey("tour")) { tour.bookTour.TourDetailId = Guid.Parse(TempData["tour"].ToString()); } if (TempData.ContainsKey("tourname")) { ViewBag.TenTour = TempData["tourname"].ToString(); } if (TempData.ContainsKey("GiaTour")) { long a = long.Parse(TempData["GiaTour"].ToString()); long sale = long.Parse(TempData["saleTour"].ToString()); giaTour = a - a * sale / 100; } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Base_URL_KhachHang); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("insert", tour.khachHang).Result; if (response.IsSuccessStatusCode) { HttpClient client1 = new HttpClient(); client1.BaseAddress = new Uri(Base_URL_KhachHang); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response1 = client.GetAsync("searchkh?keyword=" + tour.khachHang.FullName).Result; if (response1.IsSuccessStatusCode) { var strResult = response1.Content.ReadAsStringAsync().Result; var jsonData = JObject.Parse(strResult); var obj = jsonData["data"]; var tourDetail = obj.ToObject <TourDetail>(); tour.bookTour.KhachHangId = tourDetail.Id; tour.bookTour.TongTien = giaTour * tour.bookTour.NguoiLon; // HttpClient client2 = new HttpClient(); client2.BaseAddress = new Uri(Base_URL_BookTour); client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response2 = client2.PostAsJsonAsync("insert", tour.bookTour).Result; if (response2.IsSuccessStatusCode) { //send mail TempData["To"] = tour.khachHang.Email; string body = "<h1> Xin chào " + tour.khachHang.FullName + "</h1></br>" + "Qúy khách đã đăng kí tour " + TempData["tourname"] + " " + "với " + tour.bookTour.NguoiLon + " người lớn và " + tour.bookTour.TreEm + " trẻ em </br>" + "Giá Tour là : " + string.Format("{0:#,##0}", giaTour) + " đ/người </br>" + "Tổng số tiền quý khách phải thanh toán là: " + string.Format("{0:#,##0}", (giaTour * tour.bookTour.NguoiLon)) + " đ"; TempData["Body"] = body; return(RedirectToAction("SetBook")); } } // } return(View()); }