Example #1
0
        public ActionResult CreateAccount(Company model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int rowsAffected = 0;
                    db.Company.Add(model);
                    rowsAffected = db.SaveChanges();
                    int companyid = model.CompanyID;

                    EnrollSetting enrolsetting = new EnrollSetting();
                    enrolsetting.SchedulePageFormat      = 1;
                    enrolsetting.ClassIDGenerationMethod = 1;
                    enrolsetting.SiteName                  = model.SubDomain;
                    enrolsetting.MailForm                  = model.Email;
                    enrolsetting.CompanyID                 = model.CompanyID;
                    enrolsetting.TermsCondition            = "<p>Terms and Conditions</p>\r\n<ul>\r\n<li>At " + model.CompanyName + ", We do know that emergencies happen; students may reschedule registered courses for whatever reason, provided they give us 24 &ndash;hours&rsquo; prior notice before the scheduled class. We offer no refunds. Please notify us via email or phone if you&rsquo;re unable to attend. We encourage students to be early. Students who are more than 15 minutes late to scheduled class will be turned away and asked to reschedule.</li>\r\n<li>We charge $25 for the processing of any replacement card.&nbsp;</li>\r\n<li>Course books are mandatory, the American Heart Association requires that each student has a course textbook before, during, and after the course certification for reference use. Certification cards cannot be issued to students without a book present in class.</li>\r\n<li>Book prices are fixed and any promotional code applies to classroom instructions only.</li>\r\n</ul>";
                    enrolsetting.ContactUsEmail            = model.Email == null ? "" : model.Email;
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.EnrolSetting.Add(enrolsetting);
                    rowsAffected = db.SaveChanges();

                    model.User.CompanyID           = companyid;
                    model.User.IsActive            = true;
                    model.User.IsTrainingSiteAdmin = true;
                    model.User.IsWebManager        = true;
                    db.User.Add(model.User);
                    rowsAffected = db.SaveChanges();
                    AddHostHeader(model.SubDomain);
                    FlashMessage.Confirmation("Account Created Successfully. Please login to access the Enrolment Management System");
                    return(RedirectToAction("Login", "Access"));
                }
                catch (Exception ex)
                {
                    FlashMessage.Danger(ex.Message);
                }
            }

            return(View(model));
        }
        public ActionResult CompleteRegistration(Student model)
        {
            Context db = new Context();
            //JavaScriptSerializer jss = new JavaScriptSerializer();
            //Student model = jss.Deserialize<Student>(st);
            string        subdomain = Request.Url.Host.Split(new char[] { '.' })[0];
            EnrollSetting seting    = db.EnrolSetting.Where(x => x.SiteName == subdomain).FirstOrDefault();

            try
            {
                if (model.PaymentType == 2)
                {
                    var mycharge = new StripeChargeCreateOptions();
                    mycharge.Amount = (int)((model.TotalClassPrice - model.DiscountPrice) * 100);
                    int paymentAmount = (int)((model.TotalClassPrice - model.DiscountPrice) * 100);
                    mycharge.Currency = "USD";

                    mycharge.SourceCard = new SourceCard()
                    {
                        Number          = model.CardNo,
                        ExpirationYear  = Convert.ToInt32(model.ExpirationYear),
                        ExpirationMonth = Convert.ToInt32(model.ExpirationMonth),
                        AddressCountry  = "US",
                        AddressLine1    = model.MailingAddress1,
                        AddressLine2    = model.MailingAddress2,
                        AddressCity     = model.MailingCity,
                        AddressState    = model.MailingState,
                        AddressZip      = model.MailingZip,
                        Name            = model.LastName + " " + model.FirstName + " (" + model.Email + ")",
                        Cvc             = model.SecurityCode
                    };
                    mycharge.Description = "Payment received from student registration";
                    mycharge.Capture     = true;
                    //mycharge.CustomerId = current.Id;
                    string       key           = seting.StripeLiveSecretKey; //"sk_test_2LVKznWm1WA4kvWngmGaPdLx";
                    var          chargeservice = new StripeChargeService(key);
                    StripeCharge currentcharge = chargeservice.Create(mycharge);
                    //StripeCustomer current = GetCustomer();
                    if (currentcharge.Status == "succeeded" && currentcharge.Paid == true)
                    {
                        int StudentID = SaveRegistration(model);

                        StudentPayment payment = new StudentPayment();
                        payment.PaymentID     = 0;
                        payment.PaymentDate   = DateTime.Now;
                        payment.TransactionID = currentcharge.Id;
                        payment.type          = "Credit Card";
                        payment.StudentID     = StudentID;
                        payment.Detail        = "";
                        payment.Amount        = (model.TotalClassPrice - model.DiscountPrice);
                        db.StudentPayment.Add(payment);
                        db.SaveChanges();

                        Utilities.AssignKeycodesToCourseAddons(model.SelectedOptions, model.FirstName, model.LastName, model.Email, model.ClassID, StudentID);
                        Utilities.SendClassRegistrationConfirmationToStudent(model);

                        return(RedirectToAction("RegistrationConfirmed", new { id = StudentID }));
                    }
                    else
                    {
                        FlashMessage.Warning("Credit Card Transaction Fail");
                        return(RedirectToAction("RegistrationError"));
                    }
                }
                else
                {
                    int StudentID = SaveRegistration(model);
                    //SendRegistrationConfirmationToStudent(model);
                    return(RedirectToAction("RegistrationConfirmed", new { id = StudentID }));
                }
            }
            catch (Exception ex)
            {
                FlashMessage.Warning(ex.Message);
                return(RedirectToAction("RegistrationError"));
            }
        }