public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                EmailService objEmailService = new EmailService();
                string ConfirmationToken = objEmailService.CreateConfirmationToken();
                var user = new ApplicationUser() {Email=model.Email,  UserName = model.Email,ConfirmationToken= ConfirmationToken   };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    objEmailService.SendEmailConfirmation(model.Email, model.Name, ConfirmationToken);
                    Customer objCustomer = new Customer { FirstName=model.Name,LastName=model.LastName
                        ,Address= model.Address,
                        Gender = model.Gender,
                        PhoneNumber = model.PhoneNumber,
                        City = model.City,
                       Country =model.Country
                       ,State = model.State

                        ,ApplicationUserID= user.Id
                        ,PostalCode=model.PostalCode
                    };
                   
                    db.Customer.Add(objCustomer);
                    db.SaveChanges();
                       var CustomerID =  db.Customer.Where(m=>m.ApplicationUserID==user.Id).FirstOrDefault().ID;
                       PaymentInfo objPaymentInfo = new PaymentInfo() { CustomerID = CustomerID };
                         db.PaymentInfo.Add(objPaymentInfo);
                         db.SaveChanges();
                         await this.UserManager.AddToRoleAsync(user.Id, "Customers");

                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("ConfirmAccount", "Account");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult EnterEmail(FormCollection FormCollection )
        {

            EmailService objEmailService = new EmailService();
            string confirmationtoken = objEmailService.CreateConfirmationToken();
            string Email = FormCollection["Email"].ToString();
            var checkExist = db.Users.Where(m => m.UserName == Email).FirstOrDefault();
            if (checkExist != null)
            {
                Retrievepassword objRetrievepassword = new Retrievepassword() { ConfirmationToken = confirmationtoken ,Email=Email };
                db.Retrievepassword.Add(objRetrievepassword);
                db.SaveChanges();


                objEmailService.SendEmailConfirmation(Email, confirmationtoken);
                return RedirectToAction("EnterEmail", new { message = "successfull" });
            }
            else 
            {
                return RedirectToAction("EnterEmail", new { message = "notexist" });
            }
        }
        public async Task<ActionResult> ResendEmail() 
        {
            EmailService objEmailService = new EmailService();
            string applicationUserId = User.Identity.GetUserId();
            var result = UserManager.FindById(applicationUserId);
            string confirmationToken = objEmailService.CreateConfirmationToken();
            ApplicationUser user = db.Users.SingleOrDefault(u => u.Id == applicationUserId);
            if (user != null)
            {
                user.ConfirmationToken=confirmationToken;
                DbSet<ApplicationUser> dbSet = db.Set<ApplicationUser>();
                dbSet.Attach(user);
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                objEmailService.SendEmailConfirmation(result.Email, "", confirmationToken);
            }


            return RedirectToAction("ConfirmAccount", new {emailsent ="successfull" });
            
        }
        public ActionResult Checkout(FormCollection formCollection)
        {
            // string name = formCollection["txtname"].ToString();
            String ApplicationUserID = User.Identity.GetUserId();

            var result = db.Customer.Where(m => m.ApplicationUserID == ApplicationUserID).FirstOrDefault();
            var result1 = db.PaymentInfo.Where(m => m.CustomerID == result.ID).FirstOrDefault();
            if (result.FirstName == "" || result.LastName == "" || result.Address == "" || result.PhoneNumber == "" || result.City == "" || result.State == "" || result.Country == ""
               || result1.CartNumber == "" || result1.SecurityCode == "")
            {
                return RedirectToAction("CheckOut", new { message = "Please fill all fields before submitting the form" });
            }
            else
            {
                EmailService oEmailService = new EmailService();
                string CartID = Session["CartID"].ToString();

                int CustomerID = db.Customer.Where(m => m.ApplicationUserID == ApplicationUserID).FirstOrDefault().ID;

                Orders oOrders = new Orders() { CustomerID = CustomerID, CartID = CartID, Date = DateTime.Now };

                db.Orders.Add(oOrders);
                db.SaveChanges();
                var items = db.Cart.Include("Products").Where(m => m.cartID == CartID).ToList();
                oEmailService.SendEmailConfirmation(User.Identity.GetUserName());
                return RedirectToAction("ThankYou");
            }
        }