public static void ValidateCookie(this CabDataContext db, int index = 0)
        {
            var request = HttpContext.Current.Request;

            if (!request.Browser.Cookies || request.Cookies.Count <= 0 || request.Cookies[CookieName] == null)
            {
                LoginHelper.InvalidLoginRequest();
                return;
            }

            string cookieValue = request.Cookies[CookieName].Value;

            if (request.Cookies[CookieName] != null && cookieValue != null)
            {
                var loginToken = cookieValue;
                loginToken = loginToken.ToNumbers();

                if (db.Clients.Any(c => c.Token == loginToken))
                {
                    db.ValidateClientRequest(loginToken);
                }
                else
                {
                    LoginHelper.InvalidLoginRequest();
                }
            }
            else
            {
                LoginHelper.InvalidLoginRequest();
            }
        }
Пример #2
0
 public static void JobSentConfirmationCode(this Job job, CabDataContext db)
 {
     new Notification
     {
         Sender   = "Automatic",
         Receiver = job.Token,
         Type     = JobType.SentCodeForJob,
         Message  = "Dear <span class=\"roshan\">" + job.Name + "</span>,<br /><br />We've sent you a confirmation code at your email: <span class=\"roshan\"><a href=\"mailto:" + job.Email + "\">" + job.Email + "</a></span>. Please confirm your job as soon as possible and enjoy our bonus services!"
     }.AddNewNotification(db);
 }
Пример #3
0
 public static void ClientConfirmationNotification(this Client client, CabDataContext db)
 {
     new Notification
     {
         Sender   = "Automatic",
         Receiver = client.Token,
         Type     = JobType.AccountConfirmed,
         Message  = "Congratulation Sir,<br /><br />You've successfully confirmed your account."
     }.AddNewNotification(db);
 }
Пример #4
0
 public static void ClientResentConfirmationCode(this Client client, CabDataContext db)
 {
     new Notification
     {
         Sender   = "Admin",
         Receiver = client.Token,
         Type     = JobType.ResentCode,
         Message  = "Dear <span class=\"roshan\">" + client.Name + "</span>,<br /><br />We've sent you a confirmation code again at your email: <span class=\"roshan\"><a href=\"mailto:" + client.Email + "\">" + client.Email + "</a></span>. Please confirm your account as soon as possible and enjoy our bonus services!"
     }.AddNewNotification(db);
 }
Пример #5
0
        public static string GetDiscountToken(this CabDataContext db, string percent)
        {
            var discount = db.Discounts.FirstOrDefault(d => !d.IsExpired && d.ValidTill > UKTime.Now && d.ClientToken == LoginHelper.Client.Token);

            if (discount == null)
            {
                return(db.GenerateDiscount(percent));
            }

            return(discount.Token);
        }
Пример #6
0
 public static void NotifyClient(this Client client, CabDataContext db, string type, string message, string jobToken = null)
 {
     new Notification
     {
         JobToken = jobToken,
         Sender   = "Automatic",
         Receiver = client.Token,
         Type     = type,
         Message  = message
     }.AddNewNotification(db);
 }
Пример #7
0
 public static void JobConfirmationNotification(this Job job, CabDataContext db)
 {
     new Notification
     {
         JobToken = job.Token,
         Sender   = "Automatic",
         Receiver = job.ClientToken ?? job.Email,       //-------------- for anonymouse clients!
         Type     = JobType.JobConfirmed,
         Message  = "Congratulation Sir,<br /><br />You've successfully confirmed your job."
     }.AddNewNotification(db);
 }
Пример #8
0
 public static void NotifyOperator(this CabDataContext db, string type, string message, string jobToken = null)
 {
     new Notification
     {
         JobToken = jobToken,
         Sender   = "Automatic",
         Receiver = "Operator",
         Type     = type,
         Message  = message
     }.AddNewNotification(db);
 }
Пример #9
0
        public static string GetOptions(this CabDataContext db, string target, string token)
        {
            var result  = "";
            var vehicle = db.Vehicles.FirstOrDefault(v => v.Token == token);

            if (vehicle == null)
            {
                return(result);
            }

            int max = 0, i = 0;

            if (target == "number-of-passengers")
            {
                max = vehicle.MaxPassengers;
            }
            if (target == "luggages")
            {
                max = vehicle.MaxLuggages - 1; i = -1;
            }
            if (target == "hand-lag")
            {
                max = vehicle.MaxHandLag - 1; i = -1;
            }

            if (target == "baby-seats")
            {
                max = vehicle.MaxBabySeats - 1; i = -1;
            }
            if (target == "child-seats")
            {
                max = vehicle.MaxChildSeats - 1; i = -1;
            }

            if (target != "baby-seats" && target != "child-seats")
            {
                result = "<option>---</option>";
            }

            for (i += 1; i <= max; i++)
            {
                result += string.Format("<option>{0}</option>", i);
            }

            if (result.IsEmpty() || result == "<option>---</option>")
            {
                result += "<option>0</option>";
            }

            return(result);
        }
Пример #10
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();
        }
Пример #11
0
        public static Vehicle GetVehicle(this string token, CabDataContext db = null)
        {
            if (db == null)
            {
                db = new CabDataContext();
            }
            var vehicle = db.Vehicles.FirstOrDefault(v => v.Token == token);

            if (vehicle != null)
            {
                return(vehicle);
            }

            return(new Vehicle
            {
                Name = "Vehicle not found!",
                Token = "-------"
            });
        }
Пример #12
0
        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));
        }
Пример #13
0
        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));
        }
Пример #14
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);
        }
Пример #15
0
 public static Job GetLatestJob(this Client client, CabDataContext db)
 {
     return(db.Jobs.OrderByDescending(o => o.ID).FirstOrDefault(j => j.ClientToken == client.Token));
 }
 public static void Send(this Notification notification, CabDataContext db)
 {
     db.Notifications.InsertOnSubmit(notification);
     db.SubmitChanges();
 }
Пример #17
0
 public static void ValidateClientRequest(this CabDataContext db, string token)
 {
     Client = db.Clients.FirstOrDefault(c => c.Token == token);
 }
Пример #18
0
        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));
        }
Пример #19
0
        public static string GetDiscountValidTill(this CabDataContext db)
        {
            var discount = db.Discounts.FirstOrDefault(d => !d.IsExpired && d.ValidTill > UKTime.Now && d.ClientToken == LoginHelper.Client.Token);

            return(discount != null?discount.ValidTill.ToLongDateString() : "...");
        }
Пример #20
0
        public static void SendEmailToAdmin(this CabDataContext db, string subject, string body, string email = null)
        {
            var site = db.Site();

            new Live(email ?? "*****@*****.**", site).SendEmail(subject, body, email ?? "*****@*****.**");
        }
Пример #21
0
 public static Site Site(this CabDataContext db)
 {
     return(db.Sites.FirstOrDefault(s => s.Token == "airportsminicabs247"));
 }