Example #1
0
        public IActionResult PostForDeposit([FromBody] AccountDeposit deposit)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel.Notification = ApUtility.CreateNotification("Invalid information", Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }

            try
            {
                deposit.Id          = Guid.NewGuid();
                deposit.DepositDate = DateTime.UtcNow;
                deposit.CustomerId  = Guid.Parse(AppClaim.CustomerId);
                deposit.AccountId   = Guid.Parse(AppClaim.AccountId);

                AccountTransaction accountTransaction = new AccountTransaction()
                {
                    Id              = new Guid(),
                    CustomerId      = Guid.Parse(AppClaim.CustomerId),
                    AccountId       = Guid.Parse(AppClaim.AccountId),
                    TransactionDate = DateTime.UtcNow,
                    TransferType    = (int)Enums.TransactionType.Deposit,
                    DrAmount        = deposit.Amount,
                    CrAmount        = 0
                };

                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        depositService.Create(deposit);
                        depositService.SaveChanges();

                        transactionService.Create(accountTransaction);
                        transactionService.SaveChanges();

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        ts.Dispose();
                        ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                        return(StatusCode(500, ResponseModel));
                    }
                }

                ResponseModel.Notification = ApUtility.CreateNotification("Account Desposit is succeed", Enums.NotificationType.Success);
                ResponseModel.Data         = transactionService.GetAccountBalance(Guid.Parse(AppClaim.CustomerId), Guid.Parse(AppClaim.AccountId));

                return(Created(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Example #2
0
        public IActionResult CustomerRegistration([FromBody] CustomerDto customerdto)
        {
            ResponseModel rm = new ResponseModel();

            if (!ModelState.IsValid)
            {
                rm.Notification = ApUtility.CreateNotification("Invalid information", Enums.NotificationType.Error);
                return(StatusCode(500, rm));
            }

            try
            {
                var chekDuplicateEemail = customerService.GetByEmail(customerdto.Email);
                if (chekDuplicateEemail != null)
                {
                    rm.Notification = ApUtility.CreateNotification("Email Already Exists.", Enums.NotificationType.Error);
                    return(StatusCode(500, rm));
                }

                var customer        = ApUtility.ObjectMapToOther <CustomerDto, Customer>(customerdto);
                var customerAccount = ApUtility.ObjectMapToOther <CustomerDto, CustomerAccount>(customerdto);

                customer.Id        = Guid.NewGuid();
                customer.Password  = customer.Password.Encrypt();
                customer.CreatedOn = DateTime.UtcNow;

                customerAccount.Id            = Guid.NewGuid();
                customerAccount.CustomerId    = customer.Id;
                customerAccount.AccountNumber = customerAccountService.GetAccountNumberMax();
                customerAccount.RecordStatus  = true;
                customerAccount.CreatedOn     = DateTime.UtcNow;

                AccountDeposit deposit = new AccountDeposit()
                {
                    Id          = new Guid(),
                    CustomerId  = customer.Id,
                    AccountId   = customerAccount.Id,
                    DepositDate = DateTime.UtcNow,
                    Amount      = customerAccount.Amount
                };

                AccountTransaction accountTransaction = new AccountTransaction()
                {
                    Id              = new Guid(),
                    CustomerId      = customer.Id,
                    AccountId       = customerAccount.Id,
                    TransactionDate = DateTime.UtcNow,
                    TransferType    = (int)Enums.TransactionType.Deposit,
                    DrAmount        = customerAccount.Amount,
                    CrAmount        = 0
                };

                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        customerService.Create(customer);
                        customerService.SaveChanges();

                        customerAccountService.Create(customerAccount);
                        customerAccountService.SaveChanges();

                        depositService.Create(deposit);
                        depositService.SaveChanges();

                        transactionService.Create(accountTransaction);
                        transactionService.SaveChanges();

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        ts.Dispose();
                        rm.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                        return(StatusCode(500, rm));
                    }
                }

                rm.Notification = ApUtility.CreateNotification("Customer Registration is succeed.", Enums.NotificationType.Success);
                rm.Data         = customerService.Get(customer.Id);

                return(Created(string.Empty, rm));
            }
            catch (Exception ex)
            {
                rm.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, rm));
            }
        }