public ActionResult RoomBooking(CustomerRoomBookingModel model)
 {
     if (ModelState.IsValid)
     {
         var _customer = (Customer)Session[Constants.CUSTOMER_SESSION];
         model.IdCustomer = _customer.IdCustomer;
         model.IsApproved = false;
         RoomBooking result = new BookingRoomClient().addBooking(model);
         if (result != null)
         {
             ViewBag.RoomBooking = result.IdBooking;
             return(RedirectToAction("BookingResult", "CustomerHome", new {
                 IdBooking = result.IdBooking,
                 DateCheckin = result.DateCheckin,
                 RoomType = result.RoomType,
                 IsApproved = result.IsApproved
             }));
         }
         else
         {
             ModelState.AddModelError("", "Không đặt phòng được!");
             return(View("RoomBooking"));
         }
     }
     return(View());
 }
Exemple #2
0
        public RoomBooking addBooking(CustomerRoomBookingModel model)
        {
            RoomBooking booking = new RoomBooking();

            booking.DateCheckin = model.DateCheckin;
            booking.RoomType    = model.RoomType;
            booking.IdCustomer  = model.IdCustomer;
            booking.IsApproved  = model.IsApproved;

            //

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(tools.Constants.Base_URL);
                client.DefaultRequestHeaders.Add("API_KEY", "12354678");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
                HttpResponseMessage response = client.PostAsJsonAsync("RoomBooking/PostBooking", booking).Result;

                return(response.Content.ReadAsAsync <RoomBooking>().Result);
            }
            catch
            {
                return(null);
            }
        }