//?orderId=80guid=22288&token=EC-7FY2945157687815B
        public ActionResult FailureView(int orderId = 0, int guid = 0, string token = "")
        {
            try
            {
                Models.FunOrder order = dbmeals.FunOrders.FirstOrDefault(x => x.OrderID == orderId);
                if (order != null)
                {
                    order.Status = 0;
                }
                foreach (TempOrderList tempData in dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId))
                {
                    dbmeals.TempOrderLists.Remove(tempData);
                }

                dbmeals.SaveChanges();

            }
            catch
            {
            }
            try
            {
                EmailModel emailmodel = new EmailModel();
                emailmodel.Subject = "Your Order Cancelled Successfully";
                emailmodel.To = "*****@*****.**"; //"*****@*****.**";
                emailmodel.EmailBody = "<div>Your order has been cancelled successfully<div>";
                Common.sendeMail(emailmodel, true);
            }
            catch
            {
            }
            return View();
        }
        public ActionResult ResetPassword(ResetPasswordModel objResetPasswordModel)
        {
            if (ModelState.IsValid)
            {
                if (EmailExist(objResetPasswordModel.UserNameOrEmailId))
                {
                    EmailModel emailmodel = new EmailModel();
                    emailmodel.To = objResetPasswordModel.UserNameOrEmailId;
                    emailmodel.Subject = "Reset Password";

                    StringBuilder sb = new StringBuilder();
                    sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">");
                    sb.Append("Click the link below for resetting your password.<br />");
                    sb.Append("<a href=" + ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/Reset?emailId=" + emailmodel.To + " style=\"color:#0066CC\"> here</a>.<br />");
                    sb.Append("regards,<br /> Funfooding Team");
                    emailmodel.EmailBody = sb.ToString();
                    Common.sendeMail(emailmodel, true);

                    ViewBag.Message = "Email sent to your emailaddress. Please check your mail and reset your password.";
                }
                else
                {
                    ModelState.AddModelError("UserNameOrEmailId", new Exception("This emailadress does not exist in our system. please try with valid emailaddress."));
                }
            }
            return View(objResetPasswordModel);
        }
        public ActionResult Reset(ResetModel resetModel)
        {
            if (ModelState.IsValid)
            {
                WebSecurity.ResetPassword(WebSecurity.GeneratePasswordResetToken(resetModel.UserName), resetModel.Password);
                EmailModel emailmodel = new EmailModel();
                emailmodel.To = resetModel.UserName;
                emailmodel.Subject = "Reset Password";

                StringBuilder sb = new StringBuilder();
                sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">");
                sb.Append("Hi User,<br />");
                sb.Append("Your password has been changed.<br />");
                sb.Append("regards,<br /> Funfooding Team");
                emailmodel.EmailBody = sb.ToString();
                Common.sendeMail(emailmodel, true);
                //return RedirectToAction("Login", "Account");
                if (WebSecurity.Login(resetModel.UserName, resetModel.Password, persistCookie: true))
                {

                    var user = db.UserProfiles.Where(x => x.UserName.Equals(resetModel.UserName)).First();
                    int UserID = user.UserId;
                    Session["FirstName"] = user.FirstName;

                    return RedirectPage(UserID);
                }
            }
            return View(resetModel);
        }
        public ActionResult Register(LoginRegisterViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                LoginModel model = new LoginModel();
                model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel);

                bool userexists = db.UserProfiles.Any(x => x.UserName.Equals(model.UserName));

                if (userexists)
                {
                    ModelState.AddModelError("", "There is already an account with that UserName. Please use a different username");
                    return View("Login");
                    // return View(viewmodel);
                }
                // Attempt to register the user

                try
                {
                    string confirmationToken =
                        WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new
                        {
                            FirstName = model.FirstName
                        }, requireConfirmationToken: true); //new {Email=model.Email}

                    //var email = new StandardEmail();
                    //email.To = model.UserName;
                    //email.Name = model.FirstName;
                    //// email.ConfirmationToken = confirmationToken;
                    //email.ConfirmationToken = ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken;

                    //email.Send();

                    EmailModel emailmodel = new EmailModel();
                    emailmodel.To = model.UserName;
                    emailmodel.Subject = "Welcome to Fun Fooding";

                    StringBuilder sb = new StringBuilder();
                    sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                    sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                    sb.Append("<head>");
                    sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
                    sb.Append("</head>");
                    sb.Append("<body>");
                    sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">");
                    sb.Append("Hi " + model.FirstName + ",<br />");
                    sb.Append("Thank you for signing up!<br />");
                    sb.Append("<br />");
                    sb.Append("To complete the sign up process click ");
                    sb.Append("<a href=" + ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken + " style=\"color:#0066CC\"> here</a>.<br />");
                    sb.Append("<br />");
                    sb.Append("If you have any problem completing the process, please contact <a href=\"#\" style=\"color:#0066CC\">[email protected]</a>.<br />");
                    sb.Append("<br /> ");
                    sb.Append("Best regards,<br />");
                    sb.Append("Support Team<br />");
                    sb.Append("<a href=\"http://funfooding.com/\" style=\"color:#0066CC\">www.funfooding.com</a></div>");
                    sb.Append("</body>");
                    sb.Append("</html>");
                    emailmodel.EmailBody = sb.ToString();
                    Common.sendeMail(emailmodel, true);

                    return RedirectToAction("ConfirmEmail", "Account", new { Name = model.FirstName });
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View("Login", viewmodel);
        }
        public JsonResult Register(LoginRegisterViewModel viewmodel)
        {
            bool res = true;
            //return Json(viewmodel, JsonRequestBehavior.AllowGet);
            try
            {
            LoginModel model = new LoginModel();
            model = Mapper.Map<LoginRegisterViewModel, LoginModel>(viewmodel);
            //return Json(viewmodel, JsonRequestBehavior.AllowGet);

                // Attempt to register the user

                    string confirmationToken =
                        WebSecurity.CreateUserAndAccount(viewmodel.UserName, viewmodel.Password,propertyValues: new
                        {
                            FirstName = viewmodel.FirstName
                        }, requireConfirmationToken: true); //new {Email=model.Email}

                    EmailModel emailmodel = new EmailModel();
                    emailmodel.To = viewmodel.UserName;
                    emailmodel.Subject = "Welcome to Fun Fooding";

                    StringBuilder sb = new StringBuilder();
                    sb.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                    sb.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                    sb.Append("<head>");
                    sb.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
                    sb.Append("</head>");
                    sb.Append("<body>");
                    sb.Append("<div style=\"padding:20px; font:normal 14px Arial, Helvetica, sans-serif; color:#333333;\">");
                    sb.Append("Hi " + viewmodel.FirstName + ",<br />");
                    sb.Append("Thank you for signing up!<br />");
                    sb.Append("<br />");
                    sb.Append("To complete the sign up process click ");
                    sb.Append("<a href=" + ConfigurationManager.AppSettings["funfoodingUrl"] + "/Account/EmailConfirmation/" + confirmationToken + " style=\"color:#0066CC\"> here</a>.<br />");
                    sb.Append("<br />");
                    sb.Append("If you have any problem completing the process, please contact <a href=\"#\" style=\"color:#0066CC\">[email protected]</a>.<br />");
                    sb.Append("<br /> ");
                    sb.Append("Best regards,<br />");
                    sb.Append("Support Team<br />");
                    sb.Append("<a href=\"http://funfooding.com/\" style=\"color:#0066CC\">www.funfooding.com</a></div>");
                    sb.Append("</body>");
                    sb.Append("</html>");
                    emailmodel.EmailBody = sb.ToString();
                    Common.sendeMail(emailmodel, true);
                    return Json(new { success = res}, JsonRequestBehavior.AllowGet);
                }
                catch (Exception e)
                {
                    res = false;
                    //ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                    return Json(new { success=res, msg = e }, JsonRequestBehavior.AllowGet);
                }

            // If we got this far, something failed, redisplay form
            return Json(res, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Invite(EmailaddressesViewModel invitedemails)
        {
            if (ModelState.IsValid)
            {
                int userid = invitedemails.UserID;
                string invalidemails = "";

                char[] delimiters = (",: ").ToCharArray();

                List<string> emails = invitedemails.Emailaddresses.Split(delimiters).ToList();
                IUserMailer mailer = new UserMailer();

                EmailModel emailmodel = new EmailModel();
                emailmodel.From = db.UserProfiles.Where(x => x.UserId == userid).First().UserName;

                foreach (var emailaddress in emails)
                {

                    if (IsValidEmail(emailaddress))
                    {

                        emailmodel.To = emailaddress;

                        Common.sendMail(emailmodel, EmailExist(emailaddress));
                        InsertRequestInfo(userid, emailmodel.From, emailmodel.To);
                    }
                    else
                    {
                        invalidemails = invalidemails + "," + emailaddress;

                    }

                }
                if (invalidemails == "")
                {

                    //AccountController acc = new AccountController();
                    return RedirectPage(userid);

                }

                else
                    invitedemails.Emailaddresses = invalidemails;

                invitedemails.ErrorMessage = "Please correct these emailaddresses";
                return View(invitedemails);
            }
            else { return View(); }
        }
        private void UpdateOrderDeteailsAfterPayment(int orderId)
        {
            try
            {
                Models.FunOrder order = dbmeals.FunOrders.FirstOrDefault(x => x.OrderID == orderId);
                if (order != null)
                {
                    order.Status = 1;
                }
                foreach (TempOrderList tempData in dbmeals.TempOrderLists.Where(x => x.sessionId == Session.SessionID && x.userid == WebSecurity.CurrentUserId))
                {
                    dbmeals.TempOrderLists.Remove(tempData);
                }

                dbmeals.SaveChanges();

            }
            catch
            {
            }
            try
            {
                EmailModel emailmodel = new EmailModel();
                emailmodel.Subject = "Your Order Created Successfully";
                emailmodel.To = "*****@*****.**"; //"*****@*****.**";
                emailmodel.EmailBody = "<div>Your order has been created successfully and your order number is " + orderId + "<div>";
                Common.sendeMail(emailmodel, true);
            }
            catch
            {
            }
        }