Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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" });
            }
        }
Exemplo n.º 3
0
        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 InsertCart(int ProductID)
        //{
        //}
        public ActionResult ShowCart(int? ProductID)
        {
            if (User.IsInRole("Admin"))
            {
                RedirectToAction("Index", "Home");
            }
                if (ProductID != null || Session["CartID"] != null)
                {
                    CartViewModel objCarViewModel = new CartViewModel();
                    if (Session["CartID"] == null)
                    {
                        Session.Timeout = 60;
                        EmailService objEmailService = new EmailService();
                        Session["CartID"] = objEmailService.CreateConfirmationToken();
                        int ProdID = Convert.ToInt16(ProductID);
                        int Price = db.Products.Find(ProductID).Price;

                        Cart objCart = new Cart { ProductID = ProdID, Quantity = 1, cartID = Session["CartID"].ToString(), Price = Price };

                        db.Cart.Add(objCart);
                        db.SaveChanges();

                    }
                    else
                    {
                        if (ProductID != null)
                        {
                            if (ProductExist(Convert.ToInt32(ProductID)))
                            {

                            }
                            else
                            {
                                int ProdID = Convert.ToInt16(ProductID);
                                int Price = db.Products.Find(ProductID).Price;
                                Cart objCart = new Cart { ProductID = ProdID, Quantity = 1, cartID = Session["CartID"].ToString(), Price = Price };

                                db.Cart.Add(objCart);
                                db.SaveChanges();
                            }
                        }
                        else
                        {

                        }

                    }
                    if (Session["CartID"] != null)
                    {

                        string CartID = Session["CartID"].ToString();
                        objCarViewModel.Carts = db.Cart.Include("Products").Where(m => m.cartID == CartID).ToList();
                        objCarViewModel.Subtotal = db.Cart.Where(m => m.cartID == CartID).Select(g => g.Price).Sum();

                        foreach (var item in objCarViewModel.Carts)
                        {

                        }

                    }
                    return View(objCarViewModel);
                }
                else
                {
                    ViewBag.Empty = true;
                    return View();

                }
        }