Exemplo n.º 1
0
        public ActionResult Confirm(string confirmationToken, string password)
        {
            var client = db.Clients.FirstOrDefault(c => c.ConfirmationToken == confirmationToken);

            if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
            {
                return(Json(false));
            }

            client.IsConfirmed      = true;
            client.RegistrationDate = UKTime.Now; // confirmation date!

            db.SubmitChanges();

            client.ClientConfirmationNotification(db);

            // ---- adding cookies

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

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

            var discountToken = db.GetDiscountToken("5");

            return(Json(new
            {
                name = client.Name,
                cell = client.MobilePhone,
                email = client.Email,
                landline = client.HomePhone,
                discount = discountToken
            }));
        }
Exemplo n.º 2
0
        public JsonResult ContactUs(string message, string email = null, string name = null, string phone = null)
        {
            var site = db.Site();

            var body = "";

            if (!name.IsEmpty())
            {
                body += "<strong>Name:</strong> " + name + "<br /><br />";
            }
            if (!name.IsEmpty())
            {
                body += "<strong>Email:</strong> " + email + "<br /><br />";
            }
            if (!name.IsEmpty())
            {
                body += "<strong>Phone:</strong> " + phone + "<br /><br />";
            }

            body += "<strong>Message:</strong><br /><br /><blockquote>" + message + "</blockquote><br /><br />";
            body += "<strong>Sent from:</strong> " + site.Name + " ( " + site.URL + " )";

            var subject = "Contact message from " + site.URL;

            try
            {
                db.NotifyAdmin("Contact", body);
                db.SendEmailToAdmin(subject, body);
                return(Json(true));
            }
            catch
            {
                return(Json(false));
            }
        }
        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));
        }
        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.º 6
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));
            }
        }