コード例 #1
0
ファイル: AdminAccountService.cs プロジェクト: anhtrinhh/Ars
        public async Task <AdminAccount> InsertAdmin(AdminAccount admin)
        {
            string salt = AppUtils.CreateRandomSalt();

            admin.AdminPassword = AppUtils.HashString(admin.AdminPassword, salt);
            admin.AdminId       = AppUtils.CreateRandomString(null, 10);
            return(await _repository.InsertAdmin(admin));
        }
コード例 #2
0
        public async Task <bool> SignUp(CustomerAccount customer)
        {
            string emailRegex = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?!-)(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$";
            string phoneRegex = "^\\d{8,15}$";

            if (customer == null)
            {
                return(false);
            }
            if (customer.CustomerFirstName.Length <= 0 || customer.CustomerLastName.Length <= 0 || customer.CustomerEmail.Length <= 0 ||
                (customer.CustomerPhoneNumber.Length < 8 && customer.CustomerPhoneNumber.Length > 15) ||
                customer.CustomerIdentification.Length < 8 || customer.CustomerAddress.Length < 3)
            {
                return(false);
            }
            if (!Regex.IsMatch(customer.CustomerEmail, emailRegex))
            {
                return(false);
            }
            if (!Regex.IsMatch(customer.CustomerPhoneNumber, phoneRegex))
            {
                return(false);
            }
            bool sendMail = false;

            for (int i = 0; i < 5; i++)
            {
                customer.CustomerNo = AppUtils.CreateRandomString(null, 11);
                bool success = await _repository.InsertCustomer(customer);

                if (success)
                {
                    string mailContent = AppUtils.CreateEmailActiveAccount(customer.CustomerFirstName + " "
                                                                           + customer.CustomerLastName, customer.CustomerNo,
                                                                           Regex.Replace(AppUtils.HashString(customer.CustomerNo), "\\W+", ""));
                    sendMail = await _mailService.SendEmail(customer.CustomerEmail, "Welcome to ARS Airways", mailContent);

                    break;
                }
            }
            if (sendMail)
            {
                return(true);
            }
            else
            {
                await _repository.DeleteCustomer(customer.CustomerNo);
            }
            return(false);
        }
コード例 #3
0
ファイル: BookingService.cs プロジェクト: anhtrinhh/Ars
        public async Task <string> InsertBooking(Booking booking)
        {
            booking.BookingId = AppUtils.CreateRandomString("B", 9);
            bool success = false;

            for (var i = 0; i < 5; i++)
            {
                success = await _repository.InsertBooking(booking);

                if (success)
                {
                    break;
                }
            }
            if (success)
            {
                return(booking.BookingId);
            }
            return(null);
        }