コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,AdultNumber,ChildernNumberNumber,DateFrom,DateTo")] ReservationData reservationData)
        {
            if (ModelState.IsValid)
            {
                int row = int.Parse(Request.Form["Row"]);
                int col = int.Parse(Request.Form["Col"]);
                if (row <= 0)
                {
                    return(View(reservationData));
                }
                int id = Convert.ToInt32(TempData["PersonId"]);
                reservationData.PersonId = id;
                reservationData.DateFrom = reservationData.DateFrom.AddDays(col - 1);
                ViewBag.row = row;
                ViewBag.col = col;

                var email = db.PersonalDatas.SingleOrDefault(p => p.Id == id).Email;
                //Email.Send(email, "Booking Ticket Flight", "You Booked Ticket -_-");

                db.ReservationDatas.Add(reservationData);
                db.SaveChanges();


                return(View("Finish", reservationData));
            }

            return(View(reservationData));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,FirstName,MiddleName,GrandFatherName,LastName,Email,IdentityNumber,BirthDate,BithPlace,PhoneNumber,MobileNumber,Residence,Street")] PersonalData personalData)
        {
            if (ModelState.IsValid)
            {
                db.PersonalDatas.Add(personalData);
                db.SaveChanges();
                TempData["PersonId"] = personalData.Id;
                return(RedirectToAction("Create", "ReservationDatas"));
            }

            return(View(personalData));
        }
        public ActionResult Create([Bind(Include = "booking_id,booking_start_date,booking_end_date,user_id,hotel_id,booking_places")] BookingViewModel booking)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Booking bk = new Booking();
                    bk.hotel_id           = booking.hotel_id;
                    bk.booking_places     = (int)booking.booking_places;
                    bk.booking_start_date = (System.DateTime)booking.booking_start_date;
                    bk.booking_end_date   = (System.DateTime)booking.booking_end_date;
                    bk.user_id            = User.Identity.GetUserId(); //booking.user_id;

                    //Getting the hotel
                    Hotel_Data hotel = dm.Hotel_Data.Find(booking.hotel_id);

                    var newHotelCapacity = hotel.hotel_capacity - booking.booking_places;

                    if (newHotelCapacity >= 0)
                    {
                        hotel.hotel_capacity = (int)newHotelCapacity;
                        dm.SaveChanges();
                        db.Bookings.Add(bk);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        var model = new BookingViewModel
                        {
                            hotelList = dm.Hotel_Data.Select(p => new SelectListItem {
                                Text = p.hotel_name, Value = p.hotel_id.ToString()
                            }).ToList()
                        };
                        ViewBag.Failure = "Booking capacity reached for that hotel. please choose a different hotel.";
                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    var model = new BookingViewModel
                    {
                        hotelList = dm.Hotel_Data.Select(p => new SelectListItem {
                            Text = p.hotel_name, Value = p.hotel_id.ToString()
                        }).ToList()
                    };
                    ViewBag.Failure = "You already have a booking for that date. Please choose a different date.";
                    return(View(model));
                }
            }
            return(View());
        }
コード例 #4
0
        public IHttpActionResult PutBookings(int id, Bookings bookings)
        {
            if (!ModelState.IsValid)
            {
                log.Error("Fel parametrar inskickade, BadRequest");
                return(BadRequest(ModelState));
            }

            if (id != bookings.Booking_Id)
            {
                log.Error("Inskickade ID finns inte");
                return(BadRequest());
            }

            //Felhantering för dubbellagring

            var temp = db.Bookings.Where(s => s.Event_Id == bookings.Event_Id).Where(s => s.User_Id == bookings.User_Id)
                       .Where(s => s.Booking_Id != bookings.Booking_Id).Select(s => s.Booking_Id).ToArray();

            if (temp.Count() < 1)
            {
                try
                {
                    db.Entry(bookings).State = EntityState.Modified;
                    db.SaveChanges();
                    log.Info("Lyckades uppdatera");
                }
                catch (DbUpdateConcurrencyException e)
                {
                    log.Error(e);
                    if (!BookingsExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }



            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #5
0
        public ActionResult Paynow(FormCollection form)
        {
            int           roomId      = Convert.ToInt32(Session["roomId"].ToString());
            Double        roomPrice   = Convert.ToDouble(Session["roomPrice"].ToString());
            DateTime      fromDate    = Convert.ToDateTime(Session["fromDate"].ToString());
            DateTime      toDate      = Convert.ToDateTime(Session["toDate"].ToString());
            UserBankModel userBank    = new UserBankModel();
            DateTime      currentTime = DateTime.UtcNow;
            int           userID      = Convert.ToInt32(Session["userId"].ToString());
            //string query = "SELECT * FROM USERBANK WHERE FK_UID=@uid";
            //IEnumerable<USERBANK> results = userBank.Database.SqlQuery<USERBANK>(query, new SqlParameter("@uid",userID));
            double userAmount = 1000;

            //foreach (USERBANK userAcnt in results ){
            //  userAmount = Convert.ToDouble(userAcnt.amount);
            //}
            if (userAmount >= roomPrice)
            {
                BookingModel bookingModel   = new BookingModel();
                BOOKING      bookingDetails = new BOOKING();
                bookingDetails.FK_RID     = roomId;
                bookingDetails.FK_UID     = userID;
                bookingDetails.fromDate   = fromDate;
                bookingDetails.toDate     = toDate;
                bookingDetails.bookedTime = currentTime;
                bookingModel.BOOKINGs.Add(bookingDetails);
                bookingModel.SaveChanges();
                ViewBag.PaymentStatus = "Success";
                ViewBag.PaymentInfo   = "Thank you for using our services. Enjoy your stay.";
                ViewBag.userName      = Session["userName"].ToString();
                Session.Remove("toDate");
                Session.Remove("fromDate");
                Session.Remove("adults");
                Session.Remove("children");
                Session.Remove("roomId");
                Session.Remove("roomPrice");
            }
            else
            {
                ViewBag.PaymentStatus = "Failure";
                ViewBag.PaymentInfo   = "Insufficient Funds in your Account. PLease try later.";
                ViewBag.userName      = Session["userName"].ToString();
            }
            ViewBag.userName = Session["userName"].ToString();

            return(View());
        }