Beispiel #1
0
        public ActionResult StorePurchase(int passId, int userId)
        {
            Pass_Log pl = db.processPurchase(db.getClassPasse(passId), userId, "IN-STORE");

            Yoga_User u = db.getUserById(userId);

            EmailSender.sendPurchaseConfirmation(u, pl, "In-Store");

            return(RedirectToAction("SuccessView"));
        }
Beispiel #2
0
        public ActionResult Purchases(string Cancel = null)
        {
            int passId = Int32.Parse(Request.QueryString["passId"]);
            var pass   = db.getClassPasse(passId);

            // veryfy paypal successfull before
            //getting the apiContext
            APIContext apiContext = Paypal.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];

                var guid            = Request.Params["guid"];
                var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                if (executedPayment.state.ToLower() != "approved")
                {
                    return(View("FailureView"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(View("FailureView"));
            }

            int userId = Int32.Parse(Session["Uid"].ToString());

            //todo update all field correctly later on

            // create purchase log
            Pass_Log pl = db.processPurchase(pass, userId, "ONLINE");

            Yoga_User u = db.getUserById(userId);

            EmailSender.sendPurchaseConfirmation(u, pl, "Online");
            // todo success message with receipt etc.

            return(View("SuccessView"));
        }
Beispiel #3
0
        public static void sendPurchaseConfirmation(Yoga_User user, Pass_Log pl, string purchaseType)
        {
            DBMaster db = new DBMaster();

            Class_Passes pass = db.getClassPasse(pl.Pass_Id);

            Promotion p = db.getPromotionByPassId(pl.Pass_Id);

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

            client.EnableSsl = true;

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            client.UseDefaultCredentials = false;

            client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "xkcd1701");


            MailMessage msobj = new MailMessage();

            msobj.To.Add(user.U_Email);
            msobj.From       = new MailAddress("*****@*****.**");
            msobj.Subject    = "Confirmation of " + purchaseType + " Purchase from Samsara Yoga";
            msobj.IsBodyHtml = true;

            if (p == null || p.Promo_End < DateTime.Now.Date)
            {
                decimal tax = ((pass.Pass_Price) * (decimal).15);


                msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1><p>Thank you for your recent " + purchaseType.ToLower() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/><br/>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Tax: " + tax.ToString("F") + "<br>Total: " + (tax + pass.Pass_Price).ToString("F") + "$";



                client.Send(msobj);
            }
            else
            {
                if (p.Promo_End.Date > DateTime.Today && p.Num_Classes == 0)
                {
                    decimal discount = decimal.Round((pass.Pass_Price * (decimal)p.Discount * -1), 2);
                    decimal tax      = ((pass.Pass_Price + discount) * (decimal).15);

                    msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1>" +
                                 "<p>Thank you for your recent " + purchaseType.ToLowerInvariant() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/>Promotion: " + p.Promo_Desc + " " + (int)(p.Discount * 100) + "% Off<br/><br>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Discount: " + discount.ToString("F") + "<br/><br/>Subtotal: " + (discount + pass.Pass_Price).ToString("F") + "<br/>Total: " + (tax + pass.Pass_Price + discount).ToString("F") + "$";



                    client.Send(msobj);
                }
                else
                {
                    decimal tax = ((pass.Pass_Price) * (decimal).15);

                    msobj.Body = "<h1 style='color:#557ee6;'>Saṃsāra Yoga</h1><p>Thank you for your recent " + purchaseType.ToLowerInvariant() + " purchase from Samsara Yoga. Details of this transaction are below:</p><br/>Transaction ID: " + pl.Invoice_Number + "<br/>Transaction Date: " + pl.Date_Purchased + "<br/><br/>Purchased Item: " + pass.Pass_Name + "<br/>Promotion: " + p.Promo_Desc + " +" + p.Num_Classes + " Passes<br/><br/>‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑<br/><br/>Unit Price: " + pass.Pass_Price.ToString("F") + "<br/>Tax: " + tax.ToString("F") + "<br>Total: " + (tax + pass.Pass_Price).ToString("F") + "$";



                    client.Send(msobj);
                }
            }
        }
        public ActionResult LogInSignUp(FormCollection collection)
        {
            string email = collection["Email"];
            string pass  = collection["Password"];

            bool valid = db.LoginUser(email, pass);



            if (valid)
            {
                Yoga_User u = db.getUserByEmail(email).Single();


                int    id       = u.Roles_Id;
                string roleName = db.getRoleName(id);
                //#+Nta{--


                if (id == 1 && u.Active == false || id == 2 && u.Active == false || id == 3 && u.Active == false || id == 4 && u.Active == false && u.Email_Confirmation == null)
                {
                    Session["Uid"] = u.U_Id;
                    //redirect view to set new password. (replace temporary password)
                    return(RedirectToAction("NewPassword", "LoginSignUp"));
                }


                if (u.Active == true)
                {
                    if (id == 1 || id == 2 || id == 3 || id == 4)
                    {
                        Session["Auth"] = id;
                    }
                }
                else
                {
                    Session["Auth"]     = null;
                    ViewBag.message     = "Account is not Activated";
                    ViewBag.StickyEmail = email;
                    return(View());
                }

                ViewBag.message = "Valid, Login";

                Session["Uid"] = u.U_Id;

                return(RedirectToAction("Homepage", "Home"));
            }
            else
            {
                Yoga_User u = db.getUserByEmail(email).SingleOrDefault();
                if (u == null)
                {
                    ViewBag.message     = "Invalid Login Credentials";
                    ViewBag.StickyEmail = email;
                }
                else if (u.Active == true)
                {
                    ViewBag.message     = "Invalid Login Credentials";
                    ViewBag.StickyEmail = email;
                }
                else
                {
                    ViewBag.message     = "Account is not Activated";
                    ViewBag.StickyEmail = email;
                }
                return(View());
            }
        }
        public ActionResult SignUp(FormCollection collection)
        {
            string token = Guid.NewGuid().ToString();

            string email = collection["Email"];



            String password1 = collection["password1"].ToString();

            String password2 = collection["password2"].ToString();


            String firstName = collection["FirstName"].ToString();

            String lastName = collection["LastName"].ToString();

            Yoga_User newUser = new Yoga_User();

            newUser.U_Email            = email;
            newUser.U_First_Name       = firstName;
            newUser.U_Last_Name        = lastName;
            newUser.Roles_Id           = 4;
            newUser.Email_Confirmation = token;


            // check if user exist

            bool validUserExist = db.ValidateUserExist(email);

            if (validUserExist)
            {
                ViewBag.messageSignUp = "This user email is already register";

                ViewBag.StickyUser = newUser;

                //ViewBag.set

                return(View());
            }

            // Check if both password equals
            if (!string.Equals(password1, password2))
            {
                ViewBag.messageSignUp = "Please make sure the two passwords are the same";

                ViewBag.StickyUser = newUser;

                return(View());
            }



            // encode hash the password
            string test  = password2;
            string test2 = encoder.Encode(password2);

            newUser.U_Password = encoder.Encode(password2);
            //newUser.U_Password = password2;

            ViewBag.messageSignUp = "Account created successfully";


            // add user if not already existing
            try
            {
                //myDB.SaveChanges();
                db.CreateUser(newUser);
                Util.EmailSender.sendSignUpConfirmation(email, token);
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);

                        Console.WriteLine("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }



            return(View());
        }
        public ActionResult EditSchedule(FormCollection collection)
        {
            var classes  = db.getClassList();
            var teachers = db.getTeacherList();
            var rooms    = db.getRoomList();

            var scheduleViewModel = new ScheduleViewModel
            {
                Classes  = classes,
                Teachers = teachers,
                Rooms    = rooms
            };

            int id = (int)TempData["EditScheduleId"];

            var schedule = db.getScheduleById(id);

            ViewBag.EditSchedule = schedule;

            // getg

            var selectedTeacher = Convert.ToInt32(collection["SelectedTeacherId"]);
            //var selectedCLass = collection["SelectedClassId"];
            var selectedCLass = Convert.ToInt32(collection["SelectedClassId"]);
            var selectedRoom  = Convert.ToInt32(collection["SelectedRoomId"]);

            DateTime classDate  = Convert.ToDateTime(collection["classDate"]);
            TimeSpan timePicker = TimeSpan.Parse(collection["picker"]);

            var status = collection["status"];


            ViewBag.tid = selectedTeacher;
            ViewBag.cid = selectedCLass;
            ViewBag.rid = selectedRoom;

            XDocument xd           = db.getAvailability(selectedTeacher);
            string    dayOftheWeek = classDate.DayOfWeek.ToString();
            TimeSpan  sTime;
            TimeSpan  eTime;

            Yoga_User u = db.getUserById(selectedTeacher);

            if (DateTime.Now.Date > classDate)
            {
                ViewBag.message = "<p><span style=\"color:red\">Date Error: Can't Select Dates in the Past</span>";
                return(View(scheduleViewModel));
            }

            try
            {
                sTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("Start").Value);
                eTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("End").Value);
            }
            catch
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " is unavailable " + dayOftheWeek.ToLower() + "s.";
                return(View(scheduleViewModel));
            }

            Class    c        = db.getClass(selectedCLass);
            TimeSpan classEnd = timePicker.Add(c.Class_Length);

            ViewBag.time = timePicker.Hours + ":" + timePicker.Minutes;
            ViewBag.date = classDate.ToString("yyyy-MM-dd");

            // put db update method
            if (sTime > timePicker)
            {
                ViewBag.message = "Availability Error: " + u.U_First_Name + " " + u.U_Last_Name + " starts " + dayOftheWeek + " at " + sTime.Hours + ":" + sTime.Minutes.ToString("00");
                return(View(scheduleViewModel));
            }

            if (classEnd > eTime)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " ends " + dayOftheWeek + " at " + eTime.Hours + ":" + eTime.Minutes.ToString("00") + "<br/>" +
                                  "Class End: " + classEnd.Hours + ":" + classEnd.Minutes.ToString("00") + "</p><br/>";
                return(View(scheduleViewModel));
            }

            IEnumerable <Schedule> sList = db.getScheduleByRoomAndDay(selectedRoom, classDate);

            foreach (Schedule s in sList)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd && s.Schedule_Id != schedule.Schedule_Id || classEnd > s.Start_Time && classEnd <= sEnd && s.Schedule_Id != schedule.Schedule_Id)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Room Error: </span>" + s.Room.Room_Name + " is unavailable from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }


            IEnumerable <Schedule> sListbyTeacher = db.getScheduleByTeacherAndDay(selectedTeacher, classDate);

            foreach (Schedule s in sListbyTeacher)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd && s.Schedule_Id != schedule.Schedule_Id || classEnd > s.Start_Time && classEnd <= sEnd && s.Schedule_Id != schedule.Schedule_Id)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " is already scheduleed from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }

            if (schedule.Schedule_Status != status && status == "CANCELLED" && schedule.Class_Date.Date > DateTime.Now.Date)
            {
                List <Yoga_User> list = db.getScheduleSignUpList(schedule.Schedule_Id);
                db.CancelledScheduleRefund(id);
                EmailSender.ClassCancelledEmail(list, schedule);
            }

            if (schedule.Schedule_Status != status && status == "ACTIVE" && schedule.Class_Date.Date > DateTime.Now.Date)
            {
                List <Yoga_User> list = db.getScheduleSignUpList(schedule.Schedule_Id);
                db.RestoreScheduleRemoveUsers(id);
                EmailSender.ClassRestoreEmail(list, schedule);
            }

            schedule.Teacher_Id      = selectedTeacher;
            schedule.Class_Id        = selectedCLass;
            schedule.Room_Id         = selectedRoom;
            schedule.Class_Date      = classDate;
            schedule.Schedule_Status = status;

            db.UpdateSchedule(schedule);



            return(RedirectToAction("ScheduleList"));
        }
        public ActionResult CreateSchedule(FormCollection collection)
        {
            // how to get dropdown value
            var classes  = db.getClassActiveList();
            var teachers = db.getTeacherList();
            var rooms    = db.getRoomList();

            var scheduleViewModel = new ScheduleViewModel
            {
                Classes  = classes,
                Teachers = teachers,
                Rooms    = rooms
            };

            Schedule schedule = new Schedule();


            var selectedTeacher = Convert.ToInt32(collection["SelectedTeacherId"]);
            var selectedCLass   = Convert.ToInt32(collection["SelectedClassId"]);
            var selectedRoom    = Convert.ToInt32(collection["SelectedRoomId"]);

            ViewBag.tid = selectedTeacher;
            ViewBag.cid = selectedCLass;
            ViewBag.rid = selectedRoom;

            DateTime classDate = Convert.ToDateTime(collection["classDate"]);

            ViewBag.date = classDate.ToString("yyyy-MM-dd");
            TimeSpan timePicker = TimeSpan.Parse(collection["picker"]);

            ViewBag.time = timePicker.Hours + ":" + timePicker.Minutes;
            XDocument xd           = db.getAvailability(selectedTeacher);
            string    dayOftheWeek = classDate.DayOfWeek.ToString();
            TimeSpan  sTime;
            TimeSpan  eTime;

            Yoga_User u = db.getUserById(selectedTeacher);

            if (DateTime.Now.Date > classDate)
            {
                ViewBag.message = "<p><span style=\"color:red\">Date Error:</span> Can't Select Dates in the Past</p>";
                return(View(scheduleViewModel));
            }


            try
            {
                sTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("Start").Value);
                eTime = TimeSpan.Parse(xd.Root.Element(dayOftheWeek).Element("End").Value);
            }
            catch
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " is unavailable " + dayOftheWeek.ToLower() + ".";
                return(View(scheduleViewModel));
            }
            Class    c        = db.getClass(selectedCLass);
            TimeSpan classEnd = timePicker.Add(c.Class_Length);


            if (sTime > timePicker)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " starts " + dayOftheWeek + " at " + sTime.Hours + ":" + sTime.Minutes.ToString("00");
                return(View(scheduleViewModel));
            }

            if (timePicker > eTime)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " ends " + dayOftheWeek + " at " + eTime.Hours + ":" + eTime.Minutes.ToString("00");
                return(View(scheduleViewModel));
            }

            if (classEnd > eTime)
            {
                ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " ends " + dayOftheWeek + " at " + eTime.Hours + ":" + eTime.Minutes.ToString("00") + "<br/>" +
                                  "Class End: " + classEnd.Hours + ":" + classEnd.Minutes.ToString("00") + "</p>";
                return(View(scheduleViewModel));
            }

            IEnumerable <Schedule> sList = db.getScheduleByRoomAndDay(selectedRoom, classDate);

            foreach (Schedule s in sList)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd || classEnd > s.Start_Time && classEnd <= sEnd)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Room Error: </span>" + s.Room.Room_Name + " is unavailable from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }

            IEnumerable <Schedule> sListbyTeacher = db.getScheduleByTeacherAndDay(selectedTeacher, classDate);

            foreach (Schedule s in sListbyTeacher)
            {
                String   date = s.Class_Date.ToString("dd/MM/yyyy");
                TimeSpan sEnd = s.Start_Time.Add(s.Class.Class_Length);
                if (timePicker >= s.Start_Time && timePicker < sEnd || classEnd > s.Start_Time && classEnd <= sEnd)
                {
                    ViewBag.message = "<p><span style=\"color:red\">Availability Error: </span>" + u.U_First_Name + " " + u.U_Last_Name + " already scheduleed from " + s.Start_Time.Hours + ":" + s.Start_Time.Minutes.ToString("00") + " until " + sEnd.Hours + ":" + sEnd.Minutes.ToString("00") + " on " + date + "</p>";
                    return(View(scheduleViewModel));
                }
            }



            // Add course length to timeSpan? no sure working
            var classTime = db.getClass(selectedCLass).Class_Length;

            timePicker.Add(classTime);


            schedule.Teacher_Id      = selectedTeacher;
            schedule.Class_Id        = selectedCLass;
            schedule.Room_Id         = selectedRoom;
            schedule.Class_Date      = classDate;
            schedule.Schedule_Status = "ACTIVE";
            schedule.Start_Time      = timePicker;


            db.CreateSchedule(schedule);

            return(RedirectToAction("ScheduleList"));
        }
        public ActionResult CreateUser(FormCollection collection)
        {
            int    role  = Convert.ToInt32(collection["role"]);
            string email = collection["Email"];
            string fname = collection["FirstName"];
            string lname = collection["LastName"];
            string pass  = collection["Password"];

            //
            string   phone    = collection["Phone"];
            DateTime birthday = Convert.ToDateTime(collection["Birthday"]);



            Yoga_User y = new Yoga_User();

            //y.Roles_Id = db.getRoleId(role);
            y.Roles_Id = role;

            y.U_Email      = email;
            y.U_First_Name = fname;
            y.U_Last_Name  = lname;

            y.U_Phone    = phone;
            y.U_Birthday = birthday;


            // will do false so that the user need to update the temporary password
            y.Active = false;

            //  Generate temporary password and send confirmation email

            String tempPassword = Membership.GeneratePassword(8, 2);

            y.U_Password = encoder.Encode(pass);

            //string token = Guid.NewGuid().ToString();
            //Util.EmailSender.sendSignUpConfirmationTempPassword(email, token, tempPassword);



            // If teacher
            if (role == 2)
            {
                // "N/A" Me
                XDocument availabilities = new XDocument
                                           (
                    new XElement("Root",
                                 new XElement("Sunday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Monday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Tuesday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Wednesday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Thursday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Friday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A")),
                                 new XElement("Saturday",
                                              new XElement("Start", "N/A"),
                                              new XElement("End", "N/A"))
                                 ));

                y.Availability = availabilities.ToString();
            }
            if (db.ValidateUserExist(email))
            {
                return(View());
            }
            db.CreateUser(y);
            return(RedirectToAction("UserList"));
        }