public CustomerAccountViewModel(Customer cus)
 {
     PagingInfo.GetPageInfo(cus.Orders.Count, 1, 5);
     var orders = cus.Orders.ToList().GetRange(PagingInfo.StartIndex, PagingInfo.Count);
     CustomerAccount = new CustomerModel(cus);
     CustomerAccount.Orders = orders.Select(i => new OrderModel(i)).ToList();
 }
Esempio n. 2
0
 public ActionResult CustomerRegister(string customerName, string customerPhone, string customerEmail,
                                      string shipAddress, string shipDistrict, string customerPassword, string confirmPassword)
 {
     var isInValid = false;
     var errMsg = "";
     if (!CacheHelper._CacheHelper.LoadShipmentFee().Exists(i => i.District == shipDistrict))
     {
         isInValid = true;
         errMsg += "Địa chỉ giao hàng [Quận] không tồn tại. ";
     }
     if (Context.GetCustomers(i => i.CustomerEmail == customerEmail).Count() > 0)
     {
         isInValid = true;
         errMsg += "Địa chỉ email:" + customerEmail +" đã được sử dụng. Nếu bạn quên mật khẩu hãy vào [Đăng nhập] và chọn [Quên mật khẩu] để đặt lại mật khẩu mới. ";
     }
     if ((customerPassword != confirmPassword) || customerPassword.Length < 6)
     {
         isInValid = true;
         errMsg += (customerPassword != confirmPassword) ? "Mật khẩu và xác nhận mật khẩu khác nhau. " :
             (customerPassword.Length < 6) ? "Mật khẩu ít nhất phải có 6 ký tự." : "";
     }
     if (isInValid)
     {
         var model = new CustomerAccountViewModel();
         model.CustomerAccount = new CustomerModel()
         {
             CustomerName = customerName,
             ShipAddress = shipAddress,
             ShipDistrict = shipDistrict
         };
         model.IsError = isInValid;
         model.Message = errMsg;
         model.Navigations.Add("Đăng ký tài khoản", "");
         return View(model);
     }
     try
     {
         var customer = new CustomerModel().SetPassword(customerPassword);
         customer.CustomerEmail = customerEmail;
         customer.CustomerName = customerName;
         customer.CustomerPhone = customerPhone;
         customer.ShipAddress = shipAddress;
         customer.ShipDistrict = shipDistrict;
         customer.RecieveInfo = true;
         var id = Context.CreateCustomer(customer.ToEntity());
         var mailHelper = new MailHelper();
         var subj = "Giải khát Ngọc Mai - Welcome " + customerName;
         var body = RenderRazorViewToString("~/Views/Shared/NewAccountEmail.cshtml", customer);
         mailHelper.SendMailNoAttachment(customerEmail, subj, body, null, true);
         return View("CustomerLogin", new LoginViewModel() { IsAccountCreated = true, Message = "Tài khoản đã tạo thành công, bạn có thể đăng nhập vào shop." });
     }
     catch(Exception ex)
     {
         var exType = ex.GetType();
         var model = new CustomerAccountViewModel();
         model.CustomerAccount = new CustomerModel()
         {CustomerName = customerName,
         ShipAddress = shipAddress,
         ShipDistrict = shipDistrict};
         model.IsError = true;
         model.Navigations.Add("Đăng ký tài khoản", "");
         if(exType == typeof(InvalidDataException))
         {
             model.Message = ex.Message;
             return View(model);
         }
         else if(exType == typeof(System.Net.Mail.SmtpFailedRecipientsException) ||
                 exType == typeof(System.Net.Mail.SmtpException))
         {
             model.Message = "Tài khoản của quý khách đã được tạo nhưng hệ thống không thể gửi mail cho quý khách theo địa chỉ mail quý khách cung cấp. " +
                             "Xin quý khách vui lòng liên hệ chúng tôi để xác nhận địa chỉ email. Thành thật xin lỗi quý khách.";
             return View(model);
         }
         else
         {
             model.Message = "Không thể tạo được tài khoản. Vui lòng kiểm tra lại các dữ liệu nhập.";
             return View(model);
         }
     }
 }
 public CustomerAccountViewModel()
 {
     CustomerAccount = new CustomerModel();
 }
Esempio n. 4
0
        /// <summary>
        /// Validate customer information
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="customerPhone"></param>
        /// <param name="customerEmail"></param>
        /// <param name="shipAddress"></param>
        /// <param name="shipDistrict"></param>
        /// <param name="customerPassword"></param>
        /// <exception cref="GiaiKhatNgocMai.Infrastructure.Exceptions.InvalidDataException"></exception>
        public static void ValidateCustomer(CustomerModel cus)
        {
            var isValid = (!string.IsNullOrWhiteSpace(cus.CustomerName) && cus.CustomerName.Length >= 2 && cus.CustomerName.Length <= 50) &&
                          (!string.IsNullOrWhiteSpace(cus.ShipAddress) && cus.ShipAddress.Length >= 10 && cus.ShipAddress.Length <= 50) &&
                          (AccountHelper.ValidatePhoneNumber(cus.CustomerPhone)) && (AccountHelper.ValidateEmail(cus.CustomerEmail));

            if (!isValid)
            {
                string[] message = new string[4];
                if (string.IsNullOrWhiteSpace(cus.CustomerName) || cus.CustomerName.Length < 2 || cus.CustomerName.Length > 50) message[0] = "Tên Khách Hàng";
                if (!AccountHelper.ValidatePhoneNumber(cus.CustomerPhone)) message[1] = "Số Điện Thoại";
                if (!AccountHelper.ValidateEmail(cus.CustomerEmail)) message[2] = "Email";
                if (string.IsNullOrWhiteSpace(cus.ShipAddress) || cus.ShipAddress.Length < 10 || cus.ShipAddress.Length > 50) message[3] = "Địa Chỉ";
                throw new InvalidDataException("Vui lòng kiểm tra lại các thông tin sau: " + string.Join(", ", message.Select(i => !string.IsNullOrWhiteSpace(i) ? i : "")));
            }
        }