Skip to content

Commit

Permalink
Merge pull request #178 from xdorro/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
thuyetbn authored Aug 27, 2021
2 parents 57da05d + be3dea6 commit 3e333ef
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 86 deletions.
39 changes: 11 additions & 28 deletions Backend/Areas/Admin/Controllers/BankAccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,46 +154,29 @@ public ActionResult Create(BankAccounts bank)
}

[HttpPost]
public ActionResult Edit(BankAccounts bank)
public ActionResult Edit(int id)
{
var errors = new Dictionary<string, string>();
var check = true;
var bank1 = bankAccounts.Get(bank.BankAccountId);
var bank1 = bankAccounts.Get(x =>x.BankAccountId == id).FirstOrDefault();

if (!long.TryParse(bank.Name, out long i))
{
check = false;
errors.Add("NameBank", "Your name must be number");
}

if (bankAccounts.CheckDuplicate(x => x.Name == bank.Name && x.BankAccountId != bank.BankAccountId))
if (ModelState.IsValid)
{
check = false;
errors.Add("NameBank", "Your Name has been used!");
}

if (check && ModelState.IsValid)
{
bank1.CurrencyId = bank.CurrencyId;
bank1.Name = bank.Name;
bank1.Balance = bank.Balance;
bank1.Status = bank.Status;
if (bank1.Status != (int)BankAccountStatus.Actived)
{
bank1.Status = (int)BankAccountStatus.Actived;
}
else
{
bank1.Status = (int)BankAccountStatus.Locked;
}
bankAccounts.Edit(bank1);
return Json(new
{
statusCode = 200,
message = "Success"
}, JsonRequestBehavior.AllowGet);
}

foreach (var k in ModelState.Keys)
foreach (var err in ModelState[k].Errors)
{
var key = Regex.Replace(k, @"(\w+)\.(\w+)", @"$2");
if (!errors.ContainsKey(key))
errors.Add(key, err.ErrorMessage);
}

return Json(new
{
statusCode = 400,
Expand Down
14 changes: 7 additions & 7 deletions Backend/Areas/Admin/Controllers/ChequesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ private static Transactions CreateTransactions(TransactionRequestModels tran, Ba
{
var transactionDetails = new List<TransactionDetails>()
{
new TransactionDetails
{
BankAccountId = fromBankAccount.BankAccountId,
Balance = fromBankAccount.Balance,
Type = (int) TransactionType.Minus,
Status = 1
},
// new TransactionDetails
// {
// BankAccountId = fromBankAccount.BankAccountId,
// Balance = fromBankAccount.Balance,
// Type = (int) TransactionType.Minus,
// Status = 1
// },
new TransactionDetails
{
BankAccountId = toBankAccount.BankAccountId,
Expand Down
8 changes: 7 additions & 1 deletion Backend/Areas/Admin/Views/Accounts/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,13 @@
$('#datatables').DataTable().ajax.reload();
}
else {
validator.showErrors(res.data);
if (typeof res.data == "string") {
notifyError("Error", res.data);
$("#modifyModal").modal("hide");
} else {
validator.showErrors(res.data);
}
}
}
Expand Down
43 changes: 33 additions & 10 deletions Backend/Areas/Admin/Views/Accounts/ProfileAccount.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
</div>

@section scripts{
<script>
<div><script>
const validator = $("#FormBank").validate({
rules: {
"NameBank": {
Expand Down Expand Up @@ -281,7 +281,7 @@
} else {
managerBank.receiveMoney(trans);
}
}
});
function loadStatus(status = null) {
Expand Down Expand Up @@ -350,7 +350,7 @@
url: "@Url.Action("FindId", "BankAccounts")",
data: {id : id},
success: function (res) {
$("#MoneyManagement").modal("show");
validator2.resetForm();
$("#Form2").trigger("reset");
Expand All @@ -371,8 +371,12 @@
$('#tbl_banks').DataTable().ajax.reload();
notifySuccess('Created Successfully',"Created BankAccounts Successfully")
} else {
validator.showErrors(res.data);
if (typeof res.data == "string") {
notifyError("Error", res.data);
$("#modifyModal").modal("hide");
} else {
validator.showErrors(res.data);
}
}
}
Expand All @@ -396,6 +400,24 @@
})
},
put2: function (id) {
$.ajax({
type: "POST",
url: "@Url.Action("Edit", "BankAccounts")",
data: {id:id},
success: function (res) {
if (res.statusCode === 200) {
$("#myModal").modal("hide");
$('#tbl_banks').DataTable().ajax.reload();
notifySuccess('Updated Successfully',"Updated BankAccounts Successfully");
} else {
notifyError('Created Error', res.data)
validator.showErrors(res.data);
}
}
})
},
delete: function (id) {
$.ajax({
type: "POST",
Expand Down Expand Up @@ -600,13 +622,14 @@
"orderable": false,
},
{
data: {BankAccountId:'BankAccountId'},
"render": function (data) {
data: { BankAccountId: 'BankAccountId', Status:"Status"},
render: function (data) {
let toggle = data.Status === 0 ? "Lock Account" : "Active Account";
let detail = "@Url.Action("ProfileAccountNumber", "Transactions")/"+data.BankAccountId;
return '<div class="dropdown custom-dropdown mb-0"><div class="btn sharp btn-primary tp-btn" data-toggle="dropdown" aria-expanded="false"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18px" height="18px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><circle fill="#000000" cx="12" cy="5" r="2"></circle><circle fill="#000000" cx="12" cy="12" r="2"></circle><circle fill="#000000" cx="12" cy="19" r="2"></circle></g></svg></div><div class="dropdown-menu dropdown-menu-right" x-placement="bottom-end" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(40px, 41px, 0px);">' +
'<a data-id="' + data.BankAccountId +'" class="dropdown-item btn-manager text-info" href="javascript:void(0);" >Money Managment</a>' +
'<a href="' + detail +'" class="dropdown-item btn-detail text-primary" >Details</a>' +
'<a data-id="' + data.BankAccountId +'" class="dropdown-item btn-edit text-warning" href="javascript:void(0);">Edit</a>' +
'<a data-id="' + data.BankAccountId + '" class="dropdown-item btn-edit text-warning" href="javascript:void(0);">' + toggle+'</a>' +
'<a data-id="' + data.BankAccountId +'" class="dropdown-item text-danger btn-delete btn-delete" href="javascript:void(0);">Delete</a></div></div>'
}
},
Expand Down Expand Up @@ -646,7 +669,7 @@
$(document).on("click", ".btn-edit", function () {
$("#type").val("EDIT");
let bankId = $(this).data("id");
let a = managerBank.get(bankId);
let a = managerBank.put2(bankId);
})
$(document).on("click", ".btn-manager", function () {
Expand All @@ -665,5 +688,5 @@
managerChequeBook.delete(bookId);
})
})
</script>
</script></div>
}
30 changes: 25 additions & 5 deletions Backend/Areas/Admin/Views/BankAccounts/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,24 @@
})
},
put2: function (id) {
$.ajax({
type: "POST",
url: "@Url.Action("Edit", "BankAccounts")",
data: {id:id},
success: function (res) {
if (res.statusCode === 200) {
$("#myModal").modal("hide");
$('#tbl_banks').DataTable().ajax.reload();
notifySuccess('Updated Successfully',"Updated BankAccounts Successfully");
} else {
notifyError('Created Error', res.data)
validator.showErrors(res.data);
}
}
})
},
delete: function (id) {
$.ajax({
type: "POST",
Expand Down Expand Up @@ -371,12 +389,14 @@
"orderable": false,
},
{
data: {BankAccountId:'BankAccountId'},
"render": function ( data) {
data: { BankAccountId: 'BankAccountId', Status: "Status"},
"render": function (data) {
let toggle = data.Status === 0 ? "Lock Account" : "Active Account";
let detail = "@Url.Action("ProfileAccountNumber", "Transactions")/"+data.BankAccountId;
return '<div class="dropdown custom-dropdown mb-0"><div class="btn sharp btn-primary tp-btn" data-toggle="dropdown" aria-expanded="false"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18px" height="18px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><circle fill="#000000" cx="12" cy="5" r="2"></circle><circle fill="#000000" cx="12" cy="12" r="2"></circle><circle fill="#000000" cx="12" cy="19" r="2"></circle></g></svg></div><div class="dropdown-menu dropdown-menu-right" x-placement="bottom-end" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(40px, 41px, 0px);">' +
'<a data-id="' + data.BankAccountId +'" class="dropdown-item btn-manager text-info" href="javascript:void(0);" >Money Managment</a>' +
'<a data-id="' + data.BankAccountId + '" class="dropdown-item btn-detail text-primary" href="javascript:void(0);">Details</a>' +
'<a data-id="' + data.BankAccountId +'" class="dropdown-item btn-edit text-warning" href="javascript:void(0);">Edit</a>' +
'<a href="' + detail + '" class="dropdown-item btn-detail text-primary" >Details</a>' +
'<a data-id="' + data.BankAccountId + '" class="dropdown-item btn-edit text-warning" href="javascript:void(0);">' + toggle+'</a>' +
'<a data-id="' + data.BankAccountId + '" class="dropdown-item text-danger btn-delete" href="javascript:void(0);">Delete</a></div></div>'
}
},
Expand All @@ -386,7 +406,7 @@
$(document).on("click", ".btn-edit", function () {
$("#type").val("EDIT");
let bankId = $(this).data("id");
let a = managerBank.get(bankId);
let a = managerBank.put2(bankId);
})
$(document).on("click", ".btn-detail", function () {
Expand Down
6 changes: 3 additions & 3 deletions Backend/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public HomeController()

public ActionResult Index()
{
if ((Accounts) Session["user"] == null) return RedirectToAction("Login");
ViewBag.Index = "active";
return View();
}

public ActionResult GetDataBankAccount(int account)
public ActionResult GetDataBankAccount()
{
var account = ((Accounts)Session["user"]).AccountId;
ViewBag.Accounts = "active";
var data = bankAccounts.Get().Where(a => a.AccountId == account).Select(x => new BankAccountsViewModels
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public ActionResult CreateBankAccount(BankAccounts bank)
number += random.Next(10).ToString();
}
} while (bankAccounts.CheckDuplicate(x => x.Name == number));

bank.AccountId = ((Accounts)Session["user"]).AccountId;
bank.Name = number;
bank.Status = 2;
bank.CreatedAt = DateTime.Now;
Expand Down
13 changes: 13 additions & 0 deletions Backend/Controllers/TransactionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public ActionResult Index()

public ActionResult GetData(int fromId, DateTime? startDate, DateTime? endDate)
{
var user = (Accounts)Session["user"];
var account = accounts.Get(user.AccountId);

if (!transactionDetails.CheckDuplicate(x => x.BankAccountId == fromId && x.BankAccount.AccountId == account.AccountId))
{
return Json(new
{
data = new List<TransactionsViewModels>(),
message = "Not found",
statusCode = 404
}, JsonRequestBehavior.AllowGet);
}

var data = transactionDetails.Get(x => x.BankAccountId == fromId);
if (!Utils.IsNullOrEmpty(startDate) && !Utils.IsNullOrEmpty(endDate))
{
Expand Down
Loading

0 comments on commit 3e333ef

Please sign in to comment.