예제 #1
0
        public async Task <IActionResult> OnPostMakina(Guid id, string userId, string userEmail)
        {
            Makina = _makinaServices.AvailabilityId(vm, id);
            if (vm.Makina.Count == 1)
            {
                if (userId == null)
                {
                    var claimsIdentity = (ClaimsIdentity)User.Identity;
                    var claimId        = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                    var claimEmail     = claimsIdentity.FindFirst(ClaimTypes.Email);
                    userId    = claimId.Value;
                    userEmail = claimEmail.Value;
                }
                if (ModelState.IsValid)
                {
                    Booking.DateFrom       = vm.DateFrom;
                    Booking.DateTo         = vm.DateTo;
                    Booking.PickUpLocation = vm.PickUpLocation;
                    Booking.ReturnLocation = vm.ReturnLocation;
                    Booking.UserId         = userId;
                    Booking.MakinaId       = id;
                    Booking.UserEmail      = userEmail;
                    Booking = await _services.AddBooking(Booking);
                }


                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("Name", "Email"));
                message.To.Add(new MailboxAddress("Client ", userEmail));
                message.Subject = "Thank you for the order ";
                message.Body    = new TextPart("plain")
                {
                    Text = "Thank you for renting " + Booking.Makina.ModeliId + " between dates :"
                           + Booking.DateFrom + " to :" + Booking.DateTo + " Please Get the Car on "
                           + Booking.PickUpLocation + "And Drop the car In " + Booking.ReturnLocation
                };
                using (var client = new SmtpClient())
                {
                    client.Connect("smtp.gmail.com", 587, false);
                    client.Authenticate("YourEmail", "YourPass");
                    client.Send(message);
                    client.Disconnect(true);
                }

                return(RedirectToPage("index"));
            }
            return(NotFound());
            //}
            //return RedirectToPage("Error");
        }
예제 #2
0
        public ActionResult Index(Booking booking, string name, string phone, int time)
        {
            long idBooking = 0;

            if (ModelState.IsValid && booking.IdBed != 0 && booking.IdServices != 0 && time > DateTime.Now.Hour && booking.ArrivalTime.Date >= DateTime.Now.Date)
            {
                var customer = new Customer()
                {
                    Name = name, phone = phone
                };
                var idCustomer = _bookingServices.AddCustomer(customer);
                booking.IdCustomer = idCustomer;
                var bookingDate = new DateTime(booking.ArrivalTime.Year, booking.ArrivalTime.Month, booking.ArrivalTime.Day, time, 0, 0);
                booking.ArrivalTime = bookingDate;
                idBooking           = _bookingServices.AddBooking(booking);
                if (idBooking > 0)
                {
                    return(RedirectToAction("Success", new { idBooking }));
                }
            }
            if (booking.ArrivalTime < DateTime.Now || time < DateTime.Now.Hour)
            {
                ModelState.AddModelError("", "The Arrival Time you choose must be after the current time  !");
            }
            else if (idBooking == 0)
            {
                ModelState.AddModelError("", "The bed in arrival Time you choose isn't empty ! Please select other bed or time. ");
            }
            else
            {
                ModelState.AddModelError("", "Please fill full information for booking !");
            }
            ViewBag.servicesList = _bookingServices.ServicesList();
            ViewBag.bedsList     = _bookingServices.BedsList();
            ViewBag.roomsList    = _bookingServices.RoomsList();
            ViewBag.name         = name;
            ViewBag.phone        = phone;

            if (booking.IdServices != 0)
            {
                var services = _bookingServices.GetServices(booking.IdServices);
                ViewBag.services = services;
            }
            return(View(booking));
        }
예제 #3
0
        public IActionResult PostBooking(BookingViewModel booking)
        {
            bool IsBookingAdded;

            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }
            else
            {
                IsBookingAdded = bookingRequest.AddBooking(booking);
            }
            if (IsBookingAdded)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest("Unable to add Booking"));
            }
        }