예제 #1
0
        public ActionResult Register(TbUser user)
        {
            var emailUser = db.TbUsers.Where(x => x.Email == user.Email).SingleOrDefault();

            if (emailUser != null)
            {
                ModelState.AddModelError("", "Email này đã tồn tại");
                return(View());
            }

            TbUser newUser = new TbUser()
            {
                FullName    = user.FullName,
                Email       = user.Email,
                Password    = MySecurity.EncryptPassword(user.Password),
                StatusId    = 1,
                CreatedDate = DateTime.Now
            };

            db.TbUsers.Add(newUser);
            db.SaveChanges();
            Authen(newUser.Id);


            //sendmail
            EmailManagement.SendMail(user.Email, "Chuc mung dang ky thanh cong", "<h1>Hello [Name], ban da dag ky</h1>".Replace("[Name]", newUser.FullName));
            return(RedirectToAction("Index", "Home"));
            ///return Redirect(Request.UrlReferrer.ToString());
        }
        public ActionResult Register(TbUser user)
        {
            var emailUser = db.TbUsers.Where(x => x.Email == user.Email).SingleOrDefault();

            if (emailUser != null)
            {
                return(Json("This email already exists"));
            }

            if (user.Password == null)
            {
                return(Json("Your email is valid!"));
            }

            TbUser newUser = new TbUser()
            {
                FullName    = user.FullName,
                Email       = user.Email,
                Password    = MySecurity.EncryptPassword(user.Password),
                StatusId    = 1,
                CreatedDate = DateTime.Now,
                CountLogin  = 0
            };

            db.TbUsers.Add(newUser);
            db.SaveChanges();
            Authen(newUser.Id);

            //sendmail
            EmailManagement.SendMail(user.Email, "Aptech Shose Shop",
                                     "<h1>Hello [Name]! You have successfully registered an account at Aptech Shose Shop</h1>".Replace("[Name]", newUser.FullName));
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult ForgotPW(string email)
        {
            var user = db.TbUsers.Where(x => x.Email == email).SingleOrDefault();

            if (user == null)
            {
                return(Json("The email you entered is not correct"));
            }


            Random rdom  = new Random();
            var    xPass = rdom.Next(100000, 1000000).ToString();

            ///string newPass = xPass.ToString("000000");

            user.Password   = MySecurity.EncryptPassword(xPass);
            user.StatusId   = 1;
            user.CountLogin = 0;
            user.TimeLock   = null;
            db.SaveChanges();

            EmailManagement.SendMail(user.Email, "Aptech Shose Shop",
                                     "<h1>Hello [Name]! Your new password is [newPass]</h1>"
                                     .Replace("[Name]", user.FullName)
                                     .Replace("[newPass]", xPass));

            return(Json("Please check your email for the password"));
        }
예제 #4
0
        public ActionResult Checkout(string data,
                                     string CustomerName, string CustomerEmail,
                                     string CustomerAddress,
                                     string CustomerPhone, string OrderNote
                                     )
        {
            if (CustomerName == "" || CustomerEmail == "" || CustomerPhone == "" || CustomerAddress == "")
            {
                return(Content("Kiểm tra lại thông tin"));
            }

            var cart_items = JsonConvert.DeserializeObject <List <CartItem> >(data);

            if (cart_items == null || cart_items.Count == 0)
            {
                return(Content("Ko có sp trong giỏ hàng"));
            }

            int?userName = null;

            if (User.Identity.IsAuthenticated)
            {
                userName = int.Parse(User.Identity.Name);
            }

            Order orders = new Order()
            {
                CustomerName    = CustomerName,
                CustomerEmail   = CustomerEmail,
                CustomerAddress = CustomerAddress,
                CustomerPhone   = CustomerPhone,
                OrderDate       = DateTime.Now,
                OrderNote       = OrderNote,
                UserId          = userName != null ? userName : userName,
                StatusId        = 1
            };

            db.Orders.Add(orders);

            string emailOrderDetail = string.Empty;
            double subTotal         = 0;

            foreach (var item in cart_items)
            {
                Product     p  = db.Products.Find(item.productid);
                OrderDetail od = new OrderDetail()
                {
                    OrderId       = orders.Id,
                    ProductId     = item.productid,
                    UnitPrice     = p.UnitPrice,
                    DiscountRatio = p.DiscountRatio,
                    Quantity      = item.quantity,
                    ColorName     = item.ColorName,
                    SizeName      = item.SizeName
                };
                db.OrderDetails.Add(od);

                string priceInEmail = (p.UnitPrice - ((p.UnitPrice * p.DiscountRatio) / 100)).ToString();
                string quanInEmail  = item.quantity.ToString();
                subTotal         += (p.UnitPrice - ((p.UnitPrice * p.DiscountRatio.Value) / 100)) * item.quantity;
                emailOrderDetail += "<tr>" +
                                    "<td width='80%' class='purchase_item'><span class='f-fallback'>{" + od.Product.ProductName + "}</span></td>" +
                                    "<td class='align-right' width='20%' class='purchase_item'><span class='f-fallback'>" + quanInEmail + " x $" + priceInEmail + "</span></td>" +
                                    "</tr>";
            }
            db.SaveChanges();
            subTotal *= 1.1;

            //Send mail
            string CreateBody()
            {
                string body = string.Empty;

                using (StreamReader reader = new StreamReader(Server.MapPath("~/Views/Checkout/Receipt.html")))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{ purchase_date }", DateTime.Now.ToString("yyyy-MM-dd"));
                body = body.Replace("{name}", CustomerName);
                body = body.Replace("{receipt_id}", orders.Id.ToString());
                body = body.Replace("{OrderDate}", DateTime.Now.ToString());
                body = body.Replace("{receipt_details}", emailOrderDetail);
                body = body.Replace("{total}", subTotal.ToString());

                return(body);
            }

            EmailManagement.SendMail(CustomerEmail, "Aptech Shose Shop", CreateBody());

            return(Content("OK"));
        }