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));
        }
Пример #2
0
        public JsonResult EditJob(
            string jobToken,
            string customerName,
            string cellNumber,
            string landLine,
            string email,
            string pickFrom,
            string dropTo,
            string pickupTime,
            string returnTime,
            int numberOfPassengers,
            string vehicleType,
            int childSeats,
            int babySeats,
            int luggage,
            int handLag,
            string payAs,
            string additionalInfo,
            string journeyType,
            string stops,
            string passengerName,
            string passengerCell)
        {
            var job = db.Jobs.FirstOrDefault(j => j.Token == jobToken);

            if (job == null)
            {
                return(Json(false));
            }

            if (jobToken.IsEmpty() ||
                customerName.IsEmpty() ||
                cellNumber.IsEmpty() ||
                email.IsEmpty() ||
                pickFrom.IsEmpty() ||
                dropTo.IsEmpty() ||
                pickupTime.IsEmpty() ||
                vehicleType.IsEmpty() ||
                payAs.IsEmpty() ||
                journeyType.IsEmpty()
                )
            {
                return(Json(false));
            }

            job.Name       = customerName;
            job.CellNumber = cellNumber;
            job.LandLine   = landLine;

            job.Email = email;

            job.PickFrom = pickFrom;
            job.DropTo   = dropTo;

            DateTime pickupDateTime; DateTime.TryParse(pickupTime, out pickupDateTime);

            job.PickupTime = pickupDateTime;

            DateTime returnDateTime;

            if (returnTime.IsEmpty())
            {
                returnDateTime = UKTime.Now;
                job.ReturnTime = returnDateTime;
            }
            else
            {
                DateTime.TryParse(returnTime, out returnDateTime);
                job.ReturnTime = returnDateTime;
            }

            job.NumberOfPassengers = numberOfPassengers;
            job.VehicleToken       = vehicleType;

            job.ChildSeats = childSeats;
            job.BabySeats  = babySeats;
            job.Luggage    = luggage;
            job.HandLag    = handLag;

            job.PaidAs = payAs;

            job.AdditionalInfo = additionalInfo.GetValidatedString();

            job.JourneyType = journeyType;
            job.Stops       = stops;

            job.PassengerName = passengerName;
            job.PassengerCell = passengerCell;

            db.SubmitChanges();

            var message = job.Name + " edited his job. Please count fare and send him direct email containg fares info.";

            db.NotifyOperator(JobType.JobError, message, job.Token);
            db.SendEmailToAdmin("Booking Edited", message);

            return(Json(true));
        }
Пример #3
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));
            }
        }