コード例 #1
0
        public async Task <UpdateWebHookResponse> UpdateWebHookAsync(UpdateWebHookViewModel model)
        {
            try
            {
                //get merchant
                var merchant = _context.MerchantAccounts.FirstOrDefault(x => x.ApiKey == model.HashCode);

                if (merchant != null)
                {
                    //update merchant webhook...
                    merchant.WebHook = model.WebHookURL;

                    _context.Entry(merchant).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }

                return(new UpdateWebHookResponse
                {
                    Message = "Merchant Webhook updated successfully",
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
コード例 #2
0
        public async Task <UserManagerResponse> RegisterUserAsync(RegisterViewModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new NullReferenceException("Register Model is Null");
                }

                if (model.Password != model.ConfirmPassword)
                {
                    return new UserManagerResponse
                           {
                               Message   = "Confirm password doesn't match password",
                               IsSuccess = false,
                           }
                }
                ;

                var IdentityUser = new IdentityUser
                {
                    Email    = model.Email,
                    UserName = model.Email,
                };

                var result = await _userManager.CreateAsync(IdentityUser, model.Password);

                if (result.Succeeded)
                {
                    //register to User and Merchant table
                    var user = new User();

                    var merchant = new MerchantAccount();
                    user.Email     = model.Email;
                    user.Role      = "Merchant";
                    user.Password  = "******"; //aspNetusers Management
                    user.CreatedOn = DateTime.Now;

                    await _context.Users.AddAsync(user);

                    await _context.SaveChangesAsync();

                    merchant.UserId          = user.UserId;
                    merchant.BusinessName    = model.BusinessName;
                    merchant.BusinessPhone   = model.BusinessPhone;
                    merchant.BusinessAddress = model.BusinessAddress;
                    merchant.ApiKey          = ApiUtil.GenerateKey(); //generate random key
                    merchant.SecretKey       = "secret";              //aspnet management
                    merchant.WebHook         = model.MerchantWebHook;
                    merchant.CreatedOn       = DateTime.Now;

                    await _context.MerchantAccounts.AddAsync(merchant);

                    await _context.SaveChangesAsync();


                    return(new UserManagerResponse
                    {
                        Message = "User created successfully",
                        IsSuccess = true,
                    });
                }

                //did not succeed
                return(new UserManagerResponse
                {
                    Message = "User did not create",
                    IsSuccess = false,
                    Errors = result.Errors.Select(e => e.Description),
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
コード例 #3
0
        public async Task <NewAccountResponse> NewAccountNumberAsync(NewAccountViewModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new NullReferenceException("New Account Model is Null");
                }

                // Email, Phone and ConsumerName

                //generate account number
                var AccountNumber = ApiUtil.RandomDigits();

                //check if account number already exists
                var result = _context.CustomerAccounts.FirstOrDefault(z => z.AccountNumber == AccountNumber);

                if (result == null) //if account does not exist
                {
                    //get merchant
                    var merchantId = _context.MerchantAccounts.FirstOrDefault(x => x.ApiKey == model.HashCode).MerchantAccountId;

                    if (merchantId != 0)
                    {
                        //create cust as user
                        var user = new User();
                        user.Email     = model.Email;
                        user.Role      = "Customer";
                        user.Password  = "******"; //not tied to aspnetUser
                        user.CreatedOn = DateTime.Now;

                        await _context.Users.AddAsync(user);

                        await _context.SaveChangesAsync();

                        //create customer with account
                        var cust = new CustomerAccount();
                        cust.MerchantAccountId = merchantId;
                        cust.AccountName       = model.CustomerName;
                        cust.AccountNumber     = AccountNumber;
                        cust.Phone             = model.Phone;
                        cust.CreatedOn         = DateTime.Now;
                        cust.Balance           = 0;
                        cust.UserId            = user.UserId;

                        await _context.CustomerAccounts.AddAsync(cust);

                        await _context.SaveChangesAsync();
                    }
                }
                else
                {
                    throw new NullReferenceException("New Account already exists");
                }

                return(new NewAccountResponse
                {
                    AccountNumber = AccountNumber.ToString(),
                    Message = "Customer Account created successfully",
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }