Exemplo n.º 1
0
        public JsonResult InsertOrUpdate(ReserveVM reserveVM, int id_reserve)
        {
            try
            {
                var json        = JsonConvert.SerializeObject(reserveVM);
                var buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                if (reserveVM.id_reserve == 0)
                {
                    var result = client.PostAsync("reserves", byteContent).Result;
                    return(Json(result));
                }
                else if (reserveVM.id_reserve == id_reserve)
                {
                    var result = client.PutAsync("reserves/" + id_reserve, byteContent).Result;
                    return(Json(result));
                }

                return(Json(404));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public ActionResult Search()
        {
            ReserveVM ReserveVM = new ReserveVM();

            ReserveVM.Locations = HotelManager.GetAll().Select(x => x.Location).Distinct().ToList();
            ViewBag.Message     = "Choose your dates";

            return(View(ReserveVM));
        }
Exemplo n.º 3
0
        public IActionResult EditReserve(int id, ReserveVM carVM)
        {
            var edit = _iReserve.Update(carVM, id);

            if (edit > 0)
            {
                return(Ok(edit));
            }
            return(BadRequest("Not Successfully"));
        }
Exemplo n.º 4
0
        public IActionResult CreateReserve(ReserveVM carVM)
        {
            var create = _iReserve.Create(carVM);

            if (create > 0)
            {
                return(Ok(create));
            }
            return(BadRequest("Not Successfully"));
        }
        // Book the stay
        public ActionResult Book()
        {
            if (Session["ReserveVM"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ReserveVM ReserveVM = (ReserveVM)Session["ReserveVM"];

            return(View(ReserveVM));
        }
Exemplo n.º 6
0
 public int Create(ReserveVM reserveVM)
 {
     using (SqlConnection connection = new SqlConnection(_configuration.GetConnectionString("myConn")))
     {
         var procName = "SPInsertReserve";
         parameters.Add("start", reserveVM.start_date);
         parameters.Add("end", reserveVM.end_date);
         parameters.Add("status", reserveVM.status);
         parameters.Add("tot", reserveVM.total);
         parameters.Add("tgl_bayar", reserveVM.tgl_bayar);
         parameters.Add("carID", reserveVM.carID);
         parameters.Add("konsumenID", reserveVM.konsumenID);
         var insert = connection.Execute(procName, parameters, commandType: CommandType.StoredProcedure);
         return(insert);
     }
 }
Exemplo n.º 7
0
        public JsonResult GetById(int Id)
        {
            ReserveVM reserveVM = null;
            var       resTask   = client.GetAsync("reserves/" + Id);

            resTask.Wait();

            var result = resTask.Result;

            if (result.IsSuccessStatusCode)
            {
                var json = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result).ToString();
                reserveVM = JsonConvert.DeserializeObject <ReserveVM>(json);
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Server Error.");
            }
            return(Json(reserveVM));
        }
Exemplo n.º 8
0
        public ActionResult Search(ReserveVM ReserveVM = null)
        {
            if (ReserveVM.Checkin < DateTime.Now)
            {
                ModelState.AddModelError(string.Empty, "The check-in can not be before today");
                return(View());
            }

            if (ReserveVM.Checkin > ReserveVM.Checkout)
            {
                ModelState.AddModelError(string.Empty, "Check-in must be before check-out");
                return(View());
            }

            ReserveVM.Rooms = RoomManager.GetSearch(ReserveVM.Location, ReserveVM.Checkin, ReserveVM.Checkout, ReserveVM.HasHairDryer, ReserveVM.HasTV,
                                                    ReserveVM.HasParking, ReserveVM.HasWifi, ReserveVM.MinPrice, ReserveVM.MaxPrice, ReserveVM.MinCategory, ReserveVM.MaxCategory);



            ReserveVM.Hotels     = ReserveVM.Rooms.Select(x => x.Hotel).Distinct().ToList();
            Session["ReserveVM"] = ReserveVM;
            return(RedirectToAction("Index", "Book"));
        }
        public ActionResult Book(ReserveVM ReserveVM = null)
        {
            if (ReserveVM == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid && ReserveVM.Firstname != null && ReserveVM.Lastname != null)
            {
                ReserveVM reserveVMSession = (ReserveVM)Session["ReserveVM"];
                reserveVMSession.Firstname = ReserveVM.Firstname;
                reserveVMSession.Lastname  = ReserveVM.Lastname;

                Session["ReserveVM"] = reserveVMSession;
                Booking b = new Booking()
                {
                    CheckIn  = reserveVMSession.Checkin, CheckOut = reserveVMSession.Checkout,
                    Date     = System.DateTime.Now, Firstname = reserveVMSession.Firstname,
                    Lastname = reserveVMSession.Lastname
                };
                foreach (Room r in reserveVMSession.Rooms)
                {
                    b.Room  = r;
                    b.Price = r.Price;
                    BookingManager.PostNewBooking(b);
                }

                return(RedirectToAction("Confirmation", "Book"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "The firstname and/or lastname are empty !");
                ReserveVM reserveVMSession = (ReserveVM)Session["ReserveVM"];
                return(View(reserveVMSession));
            }
        }
        // Details of the hotel
        public ActionResult Details(int id = 0)
        {
            if (id == 0 || Session["ReserveVM"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }


            ReserveVM ReserveVMsession = (ReserveVM)Session["ReserveVM"];

            ReserveVMsession.days  = ReserveVMsession.Checkout.Date.Subtract(ReserveVMsession.Checkin).Days;
            ReserveVMsession.Hotel = HotelManager.Getid(id);
            List <Room> tempRooms = ReserveVMsession.Rooms.Where(r => r.IdHotel == id).ToList();

            ReserveVMsession.Rooms = new List <Room>();
            int nbPerson = ReserveVMsession.nbPerson;



            while (nbPerson > 0)
            {
                Room room = tempRooms.Where(r => r.Type == 2).FirstOrDefault();

                if (room == null)
                {
                    room = tempRooms.FirstOrDefault();
                }

                if (room == null)
                {
                    break;
                }

                ReserveVMsession.Rooms.Add(room);
                nbPerson -= room.Type;
                tempRooms.Remove(room);
            }

            if (nbPerson == -1)
            {
                Room roomTemp = ReserveVMsession.Rooms.Last();
                ReserveVMsession.Rooms.Remove(ReserveVMsession.Rooms.Last());

                if (tempRooms.FirstOrDefault(r => r.Type == 1) != null)
                {
                    Room room = tempRooms.FirstOrDefault(r => r.Type == 1);
                    ReserveVMsession.Rooms.Add(room);
                }
                else
                {
                    ReserveVMsession.Rooms.Add(roomTemp);
                }
            }



            decimal totalPrice = 0;

            foreach (var room in ReserveVMsession.Rooms)
            {
                room.Price = room.Price * ReserveVMsession.days;

                totalPrice += room.Price;
            }

            ReserveVMsession.TotalPrice = totalPrice;

            return(View(ReserveVMsession));
        }
        // List of hotels
        public ActionResult Index()
        {
            ReserveVM ReserveVM = (ReserveVM)Session["ReserveVM"];

            return(View(ReserveVM));
        }