Ejemplo n.º 1
0
        public IActionResult Post([FromBody] AccountTransaction transaction)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel.Notification = ApUtility.CreateNotification("Invalid information", Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }

            try
            {
                transaction.Id        = Guid.NewGuid();
                transaction.CreatedOn = DateTime.UtcNow;

                transactionService.Create(transaction);
                transactionService.SaveChanges();

                transaction = transactionService.Get(transaction.Id);

                ResponseModel.Notification = ApUtility.CreateNotification("Account Transaction created successfully", Enums.NotificationType.Success);
                ResponseModel.Data         = transaction;

                return(Created(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
        public IActionResult SoftDelete(Guid id)
        {
            try
            {
                accountService.Update(
                    new CustomerAccount()
                {
                    Id           = id,
                    ModifiedOn   = DateTime.UtcNow,
                    RecordStatus = false
                },
                    p => p.RecordStatus, p => p.ModifiedOn
                    );

                accountService.SaveChanges();

                ResponseModel.Notification = ApUtility.CreateNotification("Manufacturar delete successfully", Enums.NotificationType.Success);
                return(Accepted(ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Ejemplo n.º 3
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));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Login([FromBody] LoginModel login)
        {
            ResponseModel rm    = new ResponseModel();
            var           users = authService.GetUsers(login);

            if (users != null && users.Any())
            {
                users = users.Where(s => s.Password.ToString().Equals(login.Password.Encrypt()));
                var customerAccount = customerAccountService.GetAccountByCustomer(users.FirstOrDefault().Id);
                var accountBalance  = transactionService.GetAccountBalance(users.FirstOrDefault().Id, customerAccount.Id);

                if (users.Any())
                {
                    if (users.Count() == 1)
                    {
                        var tokenString = GenerateJSONWebToken(users.FirstOrDefault(), customerAccount);

                        rm.Notification = ApUtility.CreateNotification("Loggedin Successfully.", Enums.NotificationType.Success);
                        rm.Data         = new
                        {
                            Token          = tokenString,
                            IsLogin        = true,
                            User           = users.Select(o => new { o.Email, UserName = o.FirstName, o.LastName }).FirstOrDefault(),
                            AccountBalance = accountBalance
                        };

                        return(Ok(rm));
                    }
                    else
                    {
                        rm.Notification = ApUtility.CreateNotification("Loggedin Successfully.", Enums.NotificationType.Success);
                        rm.Data         = new { IsLogin = true, Options = users.Select(o => new { Id = o.Id, Email = o.Email, Name = o.PersonalCode }) };

                        return(Ok(rm));
                    }
                }
                else
                {
                    rm.Notification = ApUtility.CreateNotification("Invalid username or password or your account is inactive", Enums.NotificationType.Error);
                    return(BadRequest(rm));
                }
            }
            else
            {
                rm.Notification = ApUtility.CreateNotification("User Information Not Available.", Enums.NotificationType.Error);
                return(BadRequest(rm));
            }
        }
Ejemplo n.º 5
0
        public IActionResult Delete(Guid id)
        {
            try
            {
                transactionService.Delete(id);
                transactionService.SaveChanges();

                ResponseModel.Notification = ApUtility.CreateNotification("Account Transaction delete successfully", Enums.NotificationType.Success);
                return(Accepted(ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Ejemplo n.º 6
0
        public IActionResult Put(AccountTransaction transaction)
        {
            try
            {
                transactionService.Update(transaction);
                transactionService.SaveChanges();

                transaction = transactionService.Get(transaction.Id);

                ResponseModel.Notification = ApUtility.CreateNotification("Account Transaction updated successfully", Enums.NotificationType.Success);
                ResponseModel.Data         = transaction;

                return(Accepted(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Ejemplo n.º 7
0
        public IActionResult Put(Customer customer)
        {
            try
            {
                customer.ModifiedOn = DateTime.UtcNow;
                customerService.Update(customer);
                customerService.SaveChanges();

                customer = customerService.Get(customer.Id);

                ResponseModel.Notification = ApUtility.CreateNotification("Customer Info is updated successfully", Enums.NotificationType.Success);
                ResponseModel.Data         = customer;

                return(Accepted(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
        public IActionResult Put(CustomerAccount account)
        {
            try
            {
                account.ModifiedOn = DateTime.UtcNow;

                accountService.Update(account);
                accountService.SaveChanges();

                account = accountService.Get(account.Id);

                ResponseModel.Notification = ApUtility.CreateNotification("Account information updated successfully", Enums.NotificationType.Success);
                ResponseModel.Data         = account;

                return(Accepted(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Ejemplo n.º 9
0
        public IActionResult Post([FromBody] Customer customer)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel.Notification = ApUtility.CreateNotification("Invalid information", Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }

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

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

                customerService.Create(customer);
                customerService.SaveChanges();

                customer = customerService.Get(customer.Id);

                ResponseModel.Notification = ApUtility.CreateNotification("Customer Registration is succeed.", Enums.NotificationType.Success);
                ResponseModel.Data         = customer;

                return(Created(string.Empty, ResponseModel));
            }
            catch (Exception ex)
            {
                ResponseModel.Notification = ApUtility.CreateNotification(ex.Message, Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }
        }
Ejemplo n.º 10
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));
            }
        }
Ejemplo n.º 11
0
        public IActionResult PostForTransfer([FromBody] AccountTransfer transfer)
        {
            if (!ModelState.IsValid)
            {
                ResponseModel.Notification = ApUtility.CreateNotification("Invalid information", Enums.NotificationType.Error);
                return(StatusCode(500, ResponseModel));
            }

            try
            {
                var customerAccount = customerAccountService.GetAccountByCustomer(transfer.ToCustomerId);

                transfer.Id             = Guid.NewGuid();
                transfer.TransferType   = 1;
                transfer.TransferDate   = DateTime.UtcNow;
                transfer.FromCustomerId = Guid.Parse(AppClaim.CustomerId);
                transfer.FromAccountId  = Guid.Parse(AppClaim.AccountId);
                transfer.ToAccountId    = customerAccount.Id;

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

                AccountTransaction transactionDr = new AccountTransaction()
                {
                    Id              = new Guid(),
                    CustomerId      = transfer.ToCustomerId,
                    AccountId       = transfer.ToAccountId,
                    TransactionDate = DateTime.UtcNow,
                    TransferType    = (int)Enums.TransactionType.Deposit,
                    DrAmount        = transfer.Amount,
                    CrAmount        = 0
                };

                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        transferService.Create(transfer);
                        transferService.SaveChanges();

                        transactionService.Create(transactionCr);
                        transactionService.Create(transactionDr);
                        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 Transfer 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));
            }
        }