Beispiel #1
0
        static void Main(string[] args)
        {
            EmailTool emailTool = new EmailTool();
            Account   account   = new Account("username", "*****@*****.**", "fname", "lname", "password", "");

            emailTool.SendEmail(account, "test", "test1234").Wait();
        }
Beispiel #2
0
        public async Task <UserDataDto> AddAsync(UserDto user)
        {
            var isValidEmail = EmailTool.IsValidEmail(user.Email);

            if (!isValidEmail)
            {
                throw new Exception("Email is not valid");
            }

            var userAge = DateTool.GetAge(user.BirthDate);

            if (userAge < 18)
            {
                throw new Exception("You must be of legal age to register");
            }

            var emailExist = await this._unitOfWork.Repositories.Users
                             .QueryableBy(x =>
                                          x.Email == user.Email)
                             .AnyAsync();

            if (emailExist)
            {
                throw new Exception("You email already exists");
            }

            var phoneNumberExist = await this._unitOfWork.Repositories.Users
                                   .QueryableBy(x =>
                                                x.PhoneNumber == user.PhoneNumber)
                                   .AnyAsync();

            if (phoneNumberExist)
            {
                throw new Exception("You phone number already exists");
            }

            var password          = StringTool.GetRandomString(20);
            var encryptedPassword = EncryptedTool.EncryptToMD5(password);
            var entity            = new User
            {
                Name           = user.Name,
                LastName       = user.LastName,
                SecondLastName = user.SecondLastName,
                Email          = user.Email,
                BirthDate      = user.BirthDate,
                PhoneNumber    = user.PhoneNumber,
                Genre          = user.Genre,
                Password       = encryptedPassword
            };

            this._unitOfWork.Repositories.Users.Add(entity);
            await this._unitOfWork.SaveAsync();

            return(new UserDataDto
            {
                Id = entity.Id,
                Email = entity.Email,
                Password = password
            });
        }
Beispiel #3
0
        internal int ThemHopDong(HopDongNcc hopDong)
        {
            //hopDong.Id = TaoMa();
            hopDong.TinhTrang   = true;
            hopDong.TTThanhToan = true;
            db.HopDongNccs.Add(hopDong);
            db.SaveChanges();
            var sendmail = new EmailTool();

            sendmail.SendMail(GetParent(hopDong.Id));
            return(hopDong.Id);
        }
Beispiel #4
0
        public ActionResult PaypalPaymanet()
        {
            var s = PdtHolder.Success(Request.QueryString.Get("tx"));
            //khởi tạo biến order
            var order    = new Order();
            var username = Session["UsernameMember"];

            if (username != null)
            {
                var model = new UserDAO().findByUsername(username.ToString());
                order.UserID = model.ID;
            }
            order.ShipCreateDate = DateTime.Now;
            order.ShipName       = s.AddressName;
            order.ShipAddress    = s.AddressState + "-" + s.AddressCountry + "-" + s.AddressStreet;
            order.ShipEmail      = s.PayerEmail;
            order.Status         = 0;
            order.PaymentID      = 1;

            //insert order

            var id = new OrderDAO().Create(order);//trả về id của order

            try
            {
                var cart = (List <CartItem>)Session[CartSession];
                var db   = new OrderDetailDAO();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.ProductModel.ID;
                    orderDetail.OrderID   = id;
                    if (item.ProductModel.Sale != null)
                    {
                        orderDetail.Price = item.ProductModel.Sale;
                    }
                    else
                    {
                        orderDetail.Price = item.ProductModel.Price;
                    }
                    orderDetail.Quantity = item.Quantity;
                    db.Create(orderDetail);
                    Session[CartSession] = null;
                }
                EmailTool emailTool = new EmailTool();
                emailTool.SendMail(GetParent(id));
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("Success", "Cart"));//chuyển hướng đến hành động được chỉ định thay vì hiển thị HTML
        }
        public ActionResult PaymentUserLogin()
        {
            var username = Session["Member"];//lấy session gáng giá trị vào order
            var model    = new UserDAO().FindUserName(username.ToString());
            var order    = new Order();

            order.ShipCreateDate = DateTime.Now;
            order.ShipName       = model.Name;
            order.ShipAddress    = model.Address;
            order.ShipEmail      = model.Email;
            order.ShipPhone      = model.Phone;
            order.Status         = 0;
            order.UserID         = model.ID;
            //insert order

            var id = new OrderDAO().Create(order);//trả về id của order

            try
            {
                var     cart  = (List <CartItem>)Session[CartSession];
                var     db    = new OrderDetailDAO();
                decimal total = 0;
                foreach (var item in cart)
                {
                    decimal price       = (decimal)item.ProductModel.Price;
                    var     orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.ProductModel.ID;
                    orderDetail.OrderID   = id;
                    if (item.ProductModel.Sale.HasValue)
                    {
                        price = price - (decimal)(item.ProductModel.Sale * price / 100);
                    }
                    orderDetail.Price    = price;
                    orderDetail.Quantity = item.Quantity;
                    orderDetail.SubPrice = item.Quantity * price;
                    total += (decimal)orderDetail.SubPrice;

                    db.Create(orderDetail);
                    Session[CartSession] = null;
                }
                new OrderDAO().EditTotal(total, id);
                EmailTool emailTool = new EmailTool();
                emailTool.SendMail(GetParent(id));
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("Success", "Cart"));
        }
Beispiel #6
0
        public ActionResult PaymentUserLogin()
        {
            var username = Session["UsernameMember"];//lấy session gáng giá trị vào order
            var model    = new UserDAO().findByUsername(username.ToString());
            var order    = new Order();

            order.ShipCreateDate = DateTime.Now;
            order.ShipName       = model.Name;
            order.ShipAddress    = model.Address;
            order.ShipEmail      = model.Email;
            order.ShipPhone      = model.Phone;
            order.Status         = 0;
            order.PaymentID      = 2;
            order.UserID         = model.ID;
            //insert order

            var id = new OrderDAO().Create(order);//trả về id của order

            try
            {
                var cart = (List <CartItem>)Session[CartSession];
                var db   = new OrderDetailDAO();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.ProductModel.ID;
                    orderDetail.OrderID   = id;
                    if (item.ProductModel.Sale != null)
                    {
                        orderDetail.Price = item.ProductModel.Sale;
                    }
                    else
                    {
                        orderDetail.Price = item.ProductModel.Price;
                    }
                    orderDetail.Quantity = item.Quantity;
                    db.Create(orderDetail);
                    Session[CartSession] = null;
                }
                EmailTool emailTool = new EmailTool();
                emailTool.SendMail(GetParent(id));
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("Success", "Cart"));
        }
Beispiel #7
0
        public ActionResult Payment(string shipName, string shipPhone, string shipAddress, string shipEmail)
        {
            var order = new Order();

            order.ShipCreateDate = DateTime.Now;
            order.ShipName       = shipName;
            order.ShipAddress    = shipAddress;
            order.ShipEmail      = shipEmail;
            order.ShipPhone      = shipPhone;
            order.Status         = 0;
            order.PaymentID      = 2;

            //insert order

            var id = new OrderDAO().Create(order);//trả về id của order

            try
            {
                var cart = (List <CartItem>)Session[CartSession];
                var db   = new OrderDetailDAO();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.ProductModel.ID;
                    orderDetail.OrderID   = id;
                    if (item.ProductModel.Sale != null)
                    {
                        orderDetail.Price = item.ProductModel.Sale;
                    }
                    else
                    {
                        orderDetail.Price = item.ProductModel.Price;
                    }
                    orderDetail.Quantity = item.Quantity;
                    db.Create(orderDetail);

                    Session[CartSession] = null;
                }
                EmailTool emailTool = new EmailTool();
                emailTool.SendMail(GetParent(id));
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("Success", "Cart"));
        }
 public ActionResult ForgotPassword(string email)
 {
     if (ModelState.IsValid)
     {
         var check = new UserDAO().find(email);
         if (check != null)
         {
             var newpass = new UserDAO().CreatePassword(8);
             var creat   = new UserDAO().UpdatePass(email, Encryptor.Encrypt(newpass));
             if (creat)
             {
                 EmailTool emailTool = new EmailTool();
                 emailTool.SendMail(GetParent(email, newpass));
                 ModelState.AddModelError("", "Đã gửi một email chứa mật khẩu tới tài khoản của bạn!");
                 return(View());
             }
         }
     }
     return(View());
 }
Beispiel #9
0
        public ActionResult ForgotPassword(string email)
        {
            if (ModelState.IsValid)
            {
                var check = new UserDAO().find(email);
                if (check != null)
                {
                    var newpass = new UserDAO().CreatePassword(10);
                    var creat   = new UserDAO().UpdatePass(email, Encryptor.Encrypt(newpass));
                    if (creat)
                    {
                        EmailTool emailTool = new EmailTool();
                        emailTool.SendMail(GetParent(email, newpass));
                        TempData["Success"] = "Đã lấy lại mật khẩu thành công ,chung tôi đã gửi một email chứa mật khẩu tới tài khoản của bạn!";
                        return(View());
                    }
                }
            }
            TempData["Error"] = "Lấy lại mật khẩu không thành công!";

            return(View());
        }