public ActionResult Preview(string token, string type)
        {
            var db      = new CabDataContext();
            var booking = db.Jobs.FirstOrDefault(j => j.ConfirmationToken == token);

            if (booking == null)
            {
                return(Json("<h2>Booking not found.</h2>", JsonRequestBehavior.AllowGet));
            }

            if (type == "confirm")
            {
                booking.IsConfirmed = true;
                db.SubmitChanges();

                booking.JobConfirmationNotification(db);
                db.SendEmailToAdmin("Booking Confirmed", "Booking confirmed by " + booking.Name + " ( " + booking.Email + " ).");

                booking.SendBookingConfirmedEmail(db.Site());

                var notifications = db.Notifications.Where(n => n.Receiver == booking.ClientToken && n.Type == JobType.SentCodeForJob);
                foreach (var notification in notifications)
                {
                    notification.Status = "Read";
                    db.SubmitChanges();
                }
            }

            if (type == "cancel")
            {
                booking.IsConfirmed = false;
                db.SubmitChanges();

                var body = "A customer ( " + booking.Name + " : " + booking.CellNumber + " ) want to cancel his booking number #" + booking.JobNumber + " <a href=\"http://" + (db.Site().URL + "/confirm-booking.html#details=" + booking.ConfirmationToken) + "\">View Booking Details</a>";
                db.SendEmailToAdmin("Customer want to cancel his booking", body);
            }

            return(View(booking));
        }
        public ActionResult Index(string job = null, string client = null, string forgot = null)
        {
            if (client != null)
            {
                return(RedirectToAction("Confirm", "Client", new { token = client }));
            }
            if (forgot != null)
            {
                return(RedirectToAction("ChangePassword", "Client", new { forgot }));
            }

            var db       = new CabDataContext();
            var bookinng = db.Jobs.FirstOrDefault(j => j.ConfirmationToken == job);

            if (bookinng == null || bookinng.IsConfirmed)
            {
                return(Redirect("/"));
            }

            bookinng.IsConfirmed = true;
            db.SubmitChanges();

            bookinng.JobConfirmationNotification(db);

            db.SendEmailToAdmin("Booking Confirmed", "Booking confirmed by " + bookinng.Name + " ( " + bookinng.Email + " ).", StaticHelper.JobURI);


            var notifications = db.Notifications.Where(n => n.Receiver == bookinng.ClientToken && n.Type == JobType.SentCodeForJob);

            foreach (var notification in notifications)
            {
                notification.Status = "Read";

                db.SubmitChanges();
            }

            return(View(bookinng));
        }
Exemplo n.º 3
0
        static void AddNewNotification(this Notification notification, CabDataContext db)
        {
BackAgain:
            var token = RandomNumbers.GetRandomNumbers(10);

            if (db.Notifications.Any(j => j.Token == token))
            {
                goto BackAgain;
            }

            notification.Token  = token;
            notification.SentAt = UKTime.Now;
            notification.Status = "New";

            db.Notifications.InsertOnSubmit(notification);
            db.SubmitChanges();
        }
        public JsonResult Add(
            string name, string email,
            string dateOfBooking,
            bool isFirstBooking,
            string scoreForUs,
            string scoreForCustomerService,

            string scoreForService,
            string scoreForJourney,
            string scoreForOnlineBooking,
            string defineService,
            string bookUsAgain
            )
        {
            var feedback = new Feedback
            {
                Name                    = name,
                Email                   = email,
                DateOfBooking           = dateOfBooking,
                FeedbackDate            = UKTime.Now,
                IsFirstBooking          = isFirstBooking,
                ScoreForUs              = scoreForUs,
                ScoreForCustomerService = scoreForCustomerService,
                ScoreForJourney         = scoreForJourney,
                ScoreForOnlineBooking   = scoreForOnlineBooking,

                DefineOurService = defineService.GetValidatedString(),
                BookUsAgain      = bookUsAgain
            };

            _db.Feedbacks.InsertOnSubmit(feedback);

            _db.SubmitChanges();

            return(Json(true));
        }
Exemplo n.º 5
0
        static string GenerateDiscount(this CabDataContext db, string percent)
        {
back:
            string token = RandomNumbers.GenerateCoupen();

            if (db.Discounts.Any(d => d.Token == token))
            {
                goto back;
            }
            var discount = new Discount
            {
                ClientToken = LoginHelper.Client.Token,
                GeneratedAt = UKTime.Now,
                ValidTill   = UKTime.Now.AddDays(10),
                Percent     = percent,
                Token       = token,
                IsExpired   = false
            };

            db.Discounts.InsertOnSubmit(discount);
            db.SubmitChanges();

            return(token);
        }
Exemplo n.º 6
0
        public JsonResult New()
        {
            var form = Request.Form;

            string
                name       = form["name"],
                password   = form["password"],
                email      = form["email"],
                address    = form["address"],
                postalCode = form["postalCode"],
                state      = form["state"],
                city       = form["city"],
                country    = form["country"],
                cellPhone  = form["cellPhone"],
                subscribe  = form["subscribe"];

            if (db.Clients.Any(a => a.Email == email))
            {
                return(Json(new { error = "This email address is being used by someone else. Please pick a unique email address." }));
            }

GoBack:
            var token = RandomNumbers.GetRandomNumbers();

            if (db.Clients.Any(c => c.Token == token))
            {
                goto GoBack;
            }

BackAgain:
            var confirmationToken = RandomNumbers.GenerateCoupen();

            if (db.Clients.Any(c => c.ConfirmationToken == confirmationToken))
            {
                goto BackAgain;
            }

            var client = new Client
            {
                Name                = name,
                Password            = BCrypt.HashPassword(password, BCrypt.GenerateSalt(8)),
                Email               = email.ToLower(),
                Address             = address,
                PostalCode          = postalCode,
                State               = state,
                MobilePhone         = cellPhone,
                HomePhone           = "",
                Token               = token,
                City                = city,
                Country             = country,
                SubscribeNewsletter = subscribe == "1",
                IsConfirmed         = false,
                ConfirmationToken   = confirmationToken,
                RegistrationDate    = UKTime.Now
            };

            try
            {
                db.Clients.InsertOnSubmit(client);
                db.SubmitChanges();

                client.SendEmail(db.Site());

                return(Json(new
                {
                    name = client.Name,
                    cell = client.MobilePhone,
                    email = client.Email,
                    landline = client.HomePhone
                }));
            }
            catch
            {
                return(Json(new
                {
                    error = "Currently we're unable to send you a confirmation code via email. We apologize for this inconvenience.\n\n"
                            + "Our admin is being alerted about this situation. He'll contact you soon.\n\n"
                            + "Please check your email 10 minutes later.",
                    isEmailError = true
                }));
            }
        }
 public static void Send(this Notification notification, CabDataContext db)
 {
     db.Notifications.InsertOnSubmit(notification);
     db.SubmitChanges();
 }
        public JsonResult Confirm(string token, string type, string password, bool isEmail = false)
        {
            var db = new CabDataContext();

            switch (type)
            {
            case "job":
            {
                var booking = db.Jobs.FirstOrDefault(j => j.ConfirmationToken == token);

                if (booking == null || booking.IsConfirmed)
                {
                    db.NotifyOperator("Unknown Error", "A customer tried to confirm booking that not exists or deleted. Booking token provided is: " + token);
                    return(Json("No such booking found!"));
                }

                if (isEmail && booking.Email != password)
                {
                    return(Json("Invalid email or you've not one who booked the job!"));
                }

                if (!isEmail)
                {
                    var client = LoginHelper.Client;
                    if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
                    {
                        return(Json("Invalid password."));
                    }
                }

                booking.IsConfirmed = true;
                db.SubmitChanges();

                booking.JobConfirmationNotification(db);
                db.SendEmailToAdmin("Booking Confirmed", "Booking confirmed by " + booking.Name + " ( " + booking.Email + " ).");

                var site    = db.Site();
                var subject = booking.Name + ": Your booking confirmed successfully!";
                var body    = "Dear " + booking.Name + "!<br /><br />You booking number #" + booking.JobNumber + " confirmed successfully.";
                new Live(site.BookingEmail, site).SendEmail(subject, body, booking.Email);

                var notifications = db.Notifications.Where(n => n.Receiver == booking.ClientToken && n.Type == JobType.SentCodeForJob);
                foreach (var notification in notifications)
                {
                    notification.Status = "Read";
                    db.SubmitChanges();
                }

                return(Json(true));
            }

            case "change-password":
            {
                var client = db.Clients.FirstOrDefault(c => c.ForgotPasswordToken == token);
                if (client == null)
                {
                    return(Json(false));
                }

                client.Password            = BCrypt.HashPassword(password, BCrypt.GenerateSalt(8));
                client.ForgotPasswordToken = null;

                db.SubmitChanges();

                return(Json(true));
            }

            case "account":
            {
                var client = db.Clients.FirstOrDefault(c => c.ConfirmationToken == token);
                if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
                {
                    return(Json(false));
                }

                client.IsConfirmed      = true;
                client.RegistrationDate = UKTime.Now;

                db.SubmitChanges();

                client.ClientConfirmationNotification(db);

                client.Token.AddCookie();
                db.ValidateCookie();

                db.SendEmailToAdmin("Confirmed Account", client.Name + " ( " + client.Email + " ) confirmed his account.");

                db.GetDiscountToken("5");

                return(Json(true));
            }
            }

            return(Json(false));
        }
Exemplo n.º 9
0
        public ActionResult New()
        {
            var form = Request.Form;

            string passengerName    = form["passengerName"],
                   cellNumber       = form["cellNumber"],
                   pickFrom         = form["pickFrom"],
                   dropTo           = form["dropTo"],
                   vehicleType      = form["vehicleType"],
                   email            = form["email"],
                   payAs            = form["payAs"],
                   additionalInfo   = form["additionalInfo"],
                   fare             = form["fare"],
                   landLine         = form["landLine"],
                   handLag          = form["handLag"],
                   journeyType      = form["journeyType"],
                   stops            = form["stops"],
                   returnTimeString = form["returnTime"];

            var clientToken = "None";

            if (LoginHelper.Client != null)
            {
                var client = LoginHelper.Client;
                clientToken = client.Token;
            }

            int numberOfPassengers;

            int.TryParse(form["numberOfPassengers"], out numberOfPassengers);

            int childSeats;

            int.TryParse(form["childSeats"], out childSeats);

            int babySeats;

            int.TryParse(form["babySeats"], out babySeats);

            int luggage;

            int.TryParse(form["luggage"], out luggage);

            int handLagNumber;

            int.TryParse(handLag, out handLagNumber);

            DateTime pickupTime; DateTime.TryParse(form["pickupTime"], out pickupTime);
            DateTime returnTime = UKTime.Now;

            if (!string.IsNullOrWhiteSpace(returnTimeString))
            {
                DateTime.TryParse(returnTimeString, out returnTime);
            }

GoBack:
            var token = RandomNumbers.GetRandomNumbers();

            if (db.Jobs.Any(j => j.Token == token))
            {
                goto GoBack;
            }

            var job = new Job
            {
                Name               = passengerName,
                PickFrom           = pickFrom,
                DropTo             = dropTo,
                PickupTime         = pickupTime,
                Fare               = fare,
                NumberOfPassengers = numberOfPassengers,
                Luggage            = luggage,
                ClientToken        = clientToken,
                PaidAs             = payAs,
                Token              = token,
                VehicleToken       = vehicleType,
                ChildSeats         = childSeats,
                BabySeats          = babySeats,
                CellNumber         = cellNumber,
                Stops              = stops,
                DriverToken        = "None",
                Status             = "Active",
                Email              = email,
                AdditionalInfo     = additionalInfo,
                LandLine           = landLine,
                HandLag            = handLagNumber,
                JourneyType        = journeyType,
                ReturnTime         = returnTime
            };

            db.Jobs.InsertOnSubmit(job);
            db.SubmitChanges();

            return(Redirect("/Job/?token=" + token));
        }
Exemplo n.º 10
0
        public JsonResult ConfirmBooking()
        {
            var form = Request.Form;

            string customerName     = form["customerName"],
                   cellNumber       = form["cellNumber"],
                   pickFrom         = form["pickFrom"],
                   dropTo           = form["dropTo"],
                   vehicleType      = form["vehicleType"],
                   email            = form["email"],
                   payAs            = form["payAs"],
                   additionalInfo   = form["additionalInfo"],
                   fare             = form["fare"],
                   landLine         = form["landLine"],
                   handLag          = form["handLag"],
                   journeyType      = form["journeyType"],
                   stops            = form["stops"],
                   returnTimeString = form["returnTime"],
                   passengerName    = form["passengerName"],
                   passengerCell    = form["passengerCell"],
                   bonusToken       = form["bonusToken"];

            var clientToken = "None";

            if (LoginHelper.Client != null)
            {
                var client = LoginHelper.Client;
                clientToken = client.Token;
            }

            int numberOfPassengers;

            int.TryParse(form["numberOfPassengers"], out numberOfPassengers);

            int childSeats;

            int.TryParse(form["childSeats"], out childSeats);

            int babySeats;

            int.TryParse(form["babySeats"], out babySeats);

            int luggage;

            int.TryParse(form["luggage"], out luggage);

            int handLagNumber;

            int.TryParse(handLag, out handLagNumber);

            DateTime pickupTime; DateTime.TryParse(form["pickupTime"], out pickupTime);
            DateTime returnTime = UKTime.Now;

            if (!returnTimeString.IsEmpty())
            {
                DateTime.TryParse(returnTimeString, out returnTime);
            }

GoBack:
            var token = RandomNumbers.GetRandomNumbers();

            if (_db.Jobs.Any(j => j.Token == token))
            {
                goto GoBack;
            }

BackAgain:
            var confirmationToken = RandomNumbers.GenerateCoupen();

            if (_db.Jobs.Any(j => j.ConfirmationToken == confirmationToken))
            {
                goto BackAgain;
            }

            const int bottleOfWater = 2;
            string    newspaper     = null;
            var       vehicle       = vehicleType.GetVehicle(_db);

            if (vehicle.Name == "Executive")
            {
                newspaper = form["newspaper"];
            }

            string drink = null;

            if (vehicle.Name == "Gold-Vip")
            {
                drink     = form["drink"];
                newspaper = form["newspaper"];
            }

            int jobNumber = 1;

            if (_db.Jobs.Any())
            {
                jobNumber = (_db.Jobs.OrderByDescending(j => j.JobNumber).FirstOrDefault() ?? new Job {
                    JobNumber = 0
                }).JobNumber + 1;
            }

            var site = _db.Site();

            var job = new Job
            {
                Name               = customerName,
                PickFrom           = pickFrom,
                DropTo             = dropTo,
                PickupTime         = pickupTime,
                Fare               = fare,
                NumberOfPassengers = numberOfPassengers,
                Luggage            = luggage,
                ClientToken        = clientToken,
                PaidAs             = payAs,
                Token              = token,
                VehicleToken       = vehicleType,
                ChildSeats         = childSeats,
                BabySeats          = babySeats,
                CellNumber         = cellNumber,
                Stops              = stops,
                DriverToken        = "None",
                Status             = "Active",
                Email              = email,
                AdditionalInfo     = additionalInfo,
                LandLine           = landLine,
                HandLag            = handLagNumber,
                JourneyType        = journeyType,
                ReturnTime         = returnTime,

                IsConfirmed       = false,
                ConfirmationToken = confirmationToken,

                BottleOfWater = bottleOfWater,
                Newspaper     = newspaper,
                Drink         = drink,

                JobNumber = jobNumber,

                SiteToken             = site.Token,
                BookingFrom           = site.Token,
                BookingTime           = UKTime.Now,
                MinicabOffice         = "",
                BusinessAccountHolder = "",
                CardTransactionCode   = ""
            };

            if (!passengerName.IsEmpty())
            {
                job.PassengerName = passengerName;
                job.PassengerCell = passengerCell;
            }

            try
            {
                _db.Jobs.InsertOnSubmit(job);
                _db.SubmitChanges();

                string message;

                if (!bonusToken.IsEmpty())
                {
                    var discount =
                        _db.Discounts.FirstOrDefault(
                            d =>
                            d.Token == bonusToken && d.ClientToken == LoginHelper.Client.Token && !d.IsExpired &&
                            d.ValidTill >= UKTime.Now);
                    if (discount != null)
                    {
                        discount.JobToken  = job.Token;
                        discount.IsExpired = true;
                        _db.SubmitChanges();
                    }
                    else
                    {
                        message = "Invalid bonus token ( " + bonusToken + " ) used for this job!";
                        _db.NotifyOperator(JobType.NewJob, message, job.Token);
                    }
                }

                message = "New job added by " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )";
                _db.NotifyOperator(JobType.NewJob, message, job.Token);

                if (job.Fare.IsEmpty() || job.Fare == "0" || job.Fare == "NaN")
                {
                    message = "Unable to count fare for job added by " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )";
                    _db.NotifyOperator(JobType.JobError, message, job.Token);

                    _db.SendEmailToAdmin("Unable to Count Fare for a booking!", message);
                }
            }
            catch (Exception ex)
            {
                string errorMessage = "Unable to add booking for: " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )";
                errorMessage += "<br />";
                errorMessage += "<br />Pick from: " + job.PickFrom;
                errorMessage += "<br />Drop to: " + job.DropTo;

                if (!job.Stops.IsEmpty())
                {
                    job.Stops = stops.Replace(",", "=====").Replace("-----", ",");
                    var splittedStops = stops.Split(',');
                    int index         = 0;
                    foreach (var stop in splittedStops)
                    {
                        index++;
                        errorMessage += "<br />" + index + ". " + stop;
                    }
                }
                errorMessage += "<br />Pickup time: " + job.PickupTime;
                errorMessage += "<br />Journey type: " + job.JourneyType;
                errorMessage += "<br />Vehicle: " + job.VehicleToken;
                errorMessage += "<br />Fare: " + job.Fare;
                errorMessage += "<br /><br />Error Message:<br /><br /> " + ex;

                _db.NotifyOperator(JobType.JobError, errorMessage);
                _db.SendEmailToAdmin("Unable to add booking", errorMessage);

                const string message = "We are really sorry to say that something went wrong on our servers.<br />However, an automatic message has been sent to the administrator.<br />We will contact you soon via email or call.";

                if (LoginHelper.Client != null)
                {
                    LoginHelper.Client.NotifyClient(_db, "Something went wrong", message);
                }

                return(Json(message));
            }

            //-------------------------------------------------------------------------------------
            //-------------------- Now sending email confirmation message
            //-------------------------------------------------------------------------------------

            try
            {
                //job.SendEmail(_db.Site(), airportCharges);
                //job.JobSentConfirmationCode(_db);

                return(Json(
                           new
                {
                    booked = true,
                    registered = LoginHelper.Client != null,
                    token = LoginHelper.Client != null ? job.ConfirmationToken : null
                }));
            }
            catch
            {
                string errorMessage = "Unable to send confirmation email to: " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )";
                _db.NotifyOperator(JobType.JobError, errorMessage, job.Token);
                _db.SendEmailToAdmin("New Booking: Unable to send confirmation code!", errorMessage);

                var message = "We are unable to drop a confirmation code at your email: <a href=\"mailto:" + job.Email + "\">" + job.Email + "</a><br />An automatic email has been sent to the administrator.<br />We will send you confirmation code in a few minutes at your email address: <a href=\"mailto:" + job.Email + "\">" + job.Email + "</a>";

                if (LoginHelper.Client != null)
                {
                    LoginHelper.Client.NotifyClient(_db, "Unable to send confirmation code", message, job.Token);
                }
                return(Json(message));
            }
        }