public HttpResponseMessage CreateZeroAmountOrder(JObject orderBundle)
        {
            int place = 0;

            try
            {
                //deserial obj
                var order = BuildOrder(orderBundle);
                //validate  //capacity and such
                //calculate fees
                place = 1;

                Owner owner = db.Owners.Where(o => o.Id == 1).SingleOrDefault();
                if (owner == null)
                {
                    throw new Exception("Owner Setup is Not Configured Correctly");
                }

                var part = db.Participants.Where(p => p.Id == order.HouseId).FirstOrDefault();
                if (part != null)
                {
                    //custDesc = part.FirstName + " " + part.LastName + "_ord" + order.Id;
                    //partEmail = part.Email;
                    //partName = part.FirstName + " " + part.LastName;
                }
                else
                {
                    throw new Exception("couldn't find that houseId");
                }

                place = 2;

                ////orderService.CompleteOrder(stripeCharge)
                //order.AuthorizationCode = stripeCharge.Id;
                ////stripeCharge.
                //order.CardNumber = stripeCharge.StripeCard.Last4;
                //order.CardCvcCheck = stripeCharge.StripeCard.CvcCheck;
                //order.CardExpires = stripeCharge.StripeCard.ExpirationMonth + "/" + stripeCharge.StripeCard.ExpirationYear;
                //order.CardFingerprint = stripeCharge.StripeCard.Fingerprint;
                ////order.CardId = stripeCharge.StripeCard.;
                //order.CardName = stripeCharge.StripeCard.Name;
                //order.CardOrigin = stripeCharge.StripeCard.Country;
                //mjb fixorder.CardType = stripeCharge.StripeCard.Type;
                order.Voided = false;
                order.Status = "Complete";
                //mjb fix order.PaymentType = "credit";
                //db.Orders.Add(order);
                //db.SaveChanges();

                place = 7;

                //not good return reason
                OrderService _orderService = new OrderService();
                var          x             = _orderService.CreateOrder(order);

                place = 8;

                HttpResponseMessage result;

                //if (ConfigurationManager.AppSettings["CustomName"] == "bourbonchase")
                //    result = new MailController().SendBourbonLotteryConfirm(order.Id);
                //else
                result = new MailController().SendConfirmMail(order.Id);
                //HttpResponseMessage result = new MailController().SendTestEmail();

                var resp = Request.CreateResponse(HttpStatusCode.OK);
                //resp.Content = new StringContent();
                resp.Content = new StringContent(order.Id.ToString(), Encoding.UTF8, "text/plain");
                return(resp);
            }
            catch (Exception ex)
            {
                var logE = new EventureLog();
                logE.Message     = "Order exception: " + ex.Message + " -- place: " + place + " -- bundle: " + orderBundle;
                logE.Caller      = "OrderZERo_ERROR";
                logE.Status      = "ERROR";
                logE.LogDate     = System.DateTime.Now.ToLocalTime();
                logE.DateCreated = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(logE);
                db.SaveChanges();

                var badResp = Request.CreateResponse(HttpStatusCode.BadRequest);
                //resp.Content = new StringContent();
                badResp.Content = new StringContent("There was a problem with your order.  Please try again", Encoding.UTF8, "text/plain");
                return(badResp);
            }
        }
        public HttpResponseMessage CreateOrder(JObject orderBundle)
        {
            //TransactionStatus transactionStatus;
            // var results = new StudentValidation().Validate(studentViewModel);

            //if (!results.IsValid)
            //{
            //    studentViewModel.Errors = GenerateErrorMessage.Built(results.Errors);
            //    studentViewModel.ErrorType = ErrorTypeEnum.Error.ToString().ToLower();
            //    studentViewModel.Status = false;
            //    var badResponse = Request.CreateResponse(HttpStatusCode.BadRequest, studentViewModel);
            //    return badResponse;
            //}

            //var stundentBo = BuiltStudentBo(studentViewModel);
            //stundentBo.PaymentMethods = string.Join(",", studentViewModel.SelectedPaymentMethods);
            //stundentBo.Gender = studentViewModel.SelectedGender;

            //transactionStatus = _studentService.CreateStudent(stundentBo);

            int place = 0;

            try
            {
                //quick val  check required?

                //deserial obj
                var order = BuildOrder(orderBundle);

                //validate  //capacity and such

                //calculate fees

                place = 1;


                Owner owner = db.Owners.Where(o => o.Id == 1).SingleOrDefault();
                if (owner == null)
                {
                    throw new Exception("Owner Setup is Not Configured Correctly");
                }


                //var custDesc = string.Empty;
                //var partEmail = string.Empty;
                //var partName = string.Empty;
                var part = db.Participants.Where(p => p.Id == order.HouseId).FirstOrDefault();
                if (part != null)
                {
                    //custDesc = part.FirstName + " " + part.LastName + "_ord" + order.Id;
                    //partEmail = part.Email;
                    //partName = part.FirstName + " " + part.LastName;
                }
                else
                {
                    throw new Exception("couldn't find that houseId");
                }



                place = 2;

                //calulate
                order.CardProcessorFeeInCents = Convert.ToInt32(Math.Round(Convert.ToInt32(order.Amount * 100) * owner.CardProcessorFeePercentPerCharge / 100, 0) + owner.CardProcessorFeeFlatPerChargeInCents);
                order.LocalFeeInCents         = Convert.ToInt32(Math.Round(Convert.ToInt32(order.Amount * 100) * owner.LocalFeePercentOfCharge / 100, 0) + owner.LocalFeeFlatPerChargeInCents);
                order.LocalApplicationFee     = order.LocalFeeInCents - order.CardProcessorFeeInCents;

                if (order.LocalApplicationFee < 0)
                {
                    order.LocalApplicationFee = 0;
                }
                //}

                //create stripe service,customer, charge
                //charge card
                //var stripeService = new Stripe.

                //if good
                //record charege
                //create order
                //StripeService stripeService = new StripeService();

                //tring customerEmail,string customerDescription, string customerToken, string accessToken, string chargeDescription, decimal chargeAmount, Int32 applicationFee
                //var stripeCharge = stripeService.CreateCharge(part.Email, part.FirstName + " " + part.LastName, order.Token, owner.AccessToken, owner.Name, order.Amount, order.LocalApplicationFee);
                //         public StripeCharge CreateCharge(string customerEmail,string customerDescription, string customerToken, string accessToken, string chargeDescription, decimal chargeAmount, Int32 applicationFee )
                //{

                place = 3;

                var customerOptions = new StripeCustomerCreateOptions
                {
                    Email       = part.Email, //Email,
                    Description = part.FirstName + " " + part.LastName,
                    TokenId     = order.Token,
                };

                var stripeCustomerService = new StripeCustomerService(owner.AccessToken);   //owner.AccessToken
                var customer = stripeCustomerService.Create(customerOptions);

                place = 4;

                //int err = place / (place - place);

                var stripeChargeService = new StripeChargeService(owner.AccessToken); //The token returned from the above method
                var stripeChargeOption  = new StripeChargeCreateOptions()
                {
                    Amount         = Convert.ToInt32(order.Amount * 100),
                    Currency       = "usd",
                    CustomerId     = customer.Id,
                    Description    = owner.Name,
                    ApplicationFee = order.LocalApplicationFee
                };

                place = 5;

                var stripeCharge = stripeChargeService.Create(stripeChargeOption);

                place = 6;


                if (string.IsNullOrEmpty(stripeCharge.FailureCode))
                {
                    //orderService.CompleteOrder(stripeCharge)
                    order.AuthorizationCode = stripeCharge.Id;
                    //stripeCharge.
                    order.CardNumber      = stripeCharge.StripeCard.Last4;
                    order.CardCvcCheck    = stripeCharge.StripeCard.CvcCheck;
                    order.CardExpires     = stripeCharge.StripeCard.ExpirationMonth + "/" + stripeCharge.StripeCard.ExpirationYear;
                    order.CardFingerprint = stripeCharge.StripeCard.Fingerprint;
                    //order.CardId = stripeCharge.StripeCard.;
                    order.CardName   = stripeCharge.StripeCard.Name;
                    order.CardOrigin = stripeCharge.StripeCard.Country;
                    //mjb fixorder.CardType = stripeCharge.StripeCard.Type;
                    order.Voided      = false;
                    order.Status      = "Complete";
                    order.OrderStatus = OrderStatus.Completed;
                    //mjb fix order.PaymentType = "credit";
                    //db.Orders.Add(order);
                    //db.SaveChanges();

                    place = 7;

                    //not good return reason
                    OrderService _orderService = new OrderService();
                    var          x             = _orderService.CreateOrder(order);

                    place = 8;

                    HttpResponseMessage result;

                    if (ConfigurationManager.AppSettings["CustomName"] == "bourbonchase")
                    {
                        //result = new MailController().SendBourbonLotteryConfirm(order.Id);
                        result = new MailController().SendConfirmMail(order.Id);   //change back to bourbon chase??
                    }
                    else
                    {
                        result = new MailController().SendConfirmMail(order.Id);
                    }
                    //HttpResponseMessage result = new MailController().SendTestEmail();

                    var resp = Request.CreateResponse(HttpStatusCode.OK);
                    //resp.Content = new StringContent();
                    resp.Content = new StringContent(order.Id.ToString(), Encoding.UTF8, "text/plain");
                    return(resp);
                }
                else
                {
                    //order.Status = stripeCharge.FailureMessage;
                    //db.SaveChanges();
                    //return
                    //var badResponse = Request.CreateResponse(HttpStatusCode.ExpectationFailed, stripeCharge);  //stripeCharge.FailureCode
                    //return badResponse;

                    var logE = new EventureLog();
                    logE.Message     = "Stripe Exception: " + stripeCharge.FailureMessage + " -- place: " + place + " -- bundle: " + orderBundle;
                    logE.Caller      = "Order_ERROR_stripe";
                    logE.Status      = "Warning";
                    logE.LogDate     = System.DateTime.Now.ToLocalTime();
                    logE.DateCreated = System.DateTime.Now.ToLocalTime();
                    db.EventureLogs.Add(logE);
                    db.SaveChanges();

                    var badResp = Request.CreateResponse(HttpStatusCode.BadRequest);
                    badResp.Content = new StringContent(stripeCharge.FailureMessage, Encoding.UTF8, "text/plain");
                    return(badResp);
                }
            }
            catch (Exception ex)
            {
                var logE = new EventureLog();
                logE.Message     = "Order exception: " + ex.Message + " -- place: " + place + " -- bundle: " + orderBundle;
                logE.Caller      = "Order_ERROR";
                logE.Status      = "ERROR";
                logE.LogDate     = System.DateTime.Now.ToLocalTime();
                logE.DateCreated = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(logE);
                db.SaveChanges();

                //var x = "there was an issue";
                //var badResponse = Request.CreateResponse(HttpStatusCode.BadRequest, x.ToString());
                //return badResponse;

                string message       = ex.Message;
                string returnMessage = string.Empty;

                if (message.Substring(0, 4) == "Your")
                {
                    returnMessage = ex.Message;
                }
                else
                {
                    returnMessage = "There was problem processing your order.  Please Try again.";
                }

                var badResp = Request.CreateResponse(HttpStatusCode.BadRequest);
                //resp.Content = new StringContent();
                badResp.Content = new StringContent(returnMessage, Encoding.UTF8, "text/plain");
                return(badResp);
            }


            //if (transactionStatus.Status == false)
            //{
            //    var badResponse = Request.CreateResponse(HttpStatusCode.BadRequest, JsonConvert.SerializeObject(studentViewModel));
            //    return badResponse;
            //}
            //else
            //{
            //    transactionStatus.ErrorType = ErrorTypeEnum.Success.ToString();
            //    transactionStatus.ReturnMessage.Add("Record successfully inserted to database");

            //    var badResponse = Request.CreateResponse(HttpStatusCode.Created, transactionStatus);

            //    return badResponse;
            //}
        }
        public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordViewModel model)    //(ForgotPasswordViewModel model)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            try
            {
                IdentityUser user = await _repo.FindAsync(model.Email);

                if (user == null)   // || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // User not found.  Don't reveal that the user does not exist or is not confirmed?
                    return(Ok());
                }

                var code = await _repo.GeneratePasswordResetTokenAsync(user.Id);

                code = System.Web.HttpUtility.UrlEncode(code);

                //var code = System.Web.HttpUtility.urlEncode

                //var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                //string callbackUrl = this.Url.Link("ResetPassword", new { userId = user.Id, code = code });   //, protocol: Request.Url.Scheme
                //var callbackUrl = "http://localhost:65468/#/resetpassword?userId=" + code;
                //var callbackUrl = ConfigurationManager.AppSettings["resetPasswordLink"] + "/#/resetpassword?userId=" + code;

                //ConfigurationManager.AppSettings["resetPasswordLink"];

                //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>")
                //await _repo.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");
                //mjb _mailService.SendResetPassword(user.UserName, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>");

                HttpResponseMessage result = new MailController().SendResetPassword(user.UserName, code);



                //ViewBag.Link = callbackUrl;
                //return View("ForgotPasswordConfirmation");
                //IHttpActionResult errorResult = GetErrorResult(result);

                //if (errorResult != null)
                //{
                //    return errorResult;
                //}

                //return Ok();
                //}

                // If we got this far, something failed, redisplay form
                //return View(model);
                //return Ok(accessTokenResponse);
                return(Ok());
            }
            catch (Exception ex)
            {
                evsContext db   = new evsContext();
                var        logE = new EventureLog();
                logE.Message     = "Order exception: " + ex.Message + " -- bundle: ";
                logE.Caller      = "Order_ERROR";
                logE.Status      = "ERROR";
                logE.LogDate     = System.DateTime.Now.ToLocalTime();
                logE.DateCreated = System.DateTime.Now.ToLocalTime();
                db.EventureLogs.Add(logE);
                db.SaveChanges();


                //var badResp = Request.CreateResponse(HttpStatusCode.BadRequest);
                //badResp.Content = new StringContent(ex.Message, Encoding.UTF8, "text/plain");
                //return badResp;

                return(BadRequest(ex.Message));
            }
        }