Skip to content

Commit

Permalink
Merge pull request #163 from xdorro/v2
Browse files Browse the repository at this point in the history
Merge V2.0.2
  • Loading branch information
anhnmt authored Aug 27, 2021
2 parents d3a0fa7 + 95ff24e commit 5afba4f
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 170 deletions.
151 changes: 114 additions & 37 deletions Backend/Areas/Admin/Controllers/AccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AccountsController()
users = new Repository<Accounts>();
roles = new Repository<Roles>();
}

public ActionResult Index()
{
return View();
Expand Down Expand Up @@ -55,9 +55,56 @@ public ActionResult GetRole()
{
return Json(roles.Get(), JsonRequestBehavior.AllowGet);
}
[HttpPost]
public ActionResult ChangePassword(AdminChangePasswordViewModels changePasswordViewModel)
{
var errors = new Dictionary<string, string>();
var userUpdate = users.Get(changePasswordViewModel.AccountId);
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);
}

if (!ModelState.IsValid)
return Json(new
{
data = errors,
statusCode = 400,
message = "Error",
}, JsonRequestBehavior.AllowGet);

if (!changePasswordViewModel.Password.Equals(changePasswordViewModel.RePassword))
{
errors.Add("ConfirmPassword", "Your confirm is not the same as your new password!");
return Json(new
{
data = errors,
statusCode = 400,
message = "Error",
}, JsonRequestBehavior.AllowGet);
}
userUpdate.Password = Utils.HashPassword(changePasswordViewModel.Password);
if (!users.Edit(userUpdate))
{
return Json(new
{
data = errors,
statusCode = 400,
message = "Error",
}, JsonRequestBehavior.AllowGet);
}
return Json(new
{
statusCode = 200,
message = "Change Password Successfully",
}, JsonRequestBehavior.AllowGet);
}

[HttpPost]
public ActionResult Create(Accounts accounts)
public ActionResult Create(AccountViewModel accounts)
{
var errors = new Dictionary<string, string>();
var check = true;
Expand Down Expand Up @@ -99,13 +146,6 @@ public ActionResult Create(Accounts accounts)
check = false;
errors.Add("Phone", "Your Phone has been used!");
}


// if ()
// {
// check = false;
// errors.Add("Phone", "Your Phone has been used!");
// }
if (users.CheckDuplicate(x => x.NumberId == accounts.NumberId))
{
check = false;
Expand All @@ -120,7 +160,20 @@ public ActionResult Create(Accounts accounts)

if (ModelState.IsValid && check)
{
users.Add(accounts);
var account = new Accounts
{
Name = accounts.Name,
Email = accounts.Email,
Password = Utils.HashPassword("123456"),
NumberId = accounts.NumberId,
Phone = accounts.Phone,
AttemptLogin = 0,
RoleId = accounts.RoleId,
Address = accounts.Address,
Birthday = DateTime.Parse(accounts.Birthday),
Status = ((int)AccountStatus.Actived)
};
users.Add(account);
return Json(new
{
statusCode = 200,
Expand All @@ -129,12 +182,12 @@ public ActionResult Create(Accounts accounts)
}

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);
}
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
{
Expand All @@ -145,8 +198,9 @@ public ActionResult Create(Accounts accounts)
}

[HttpPost]
public ActionResult Edit(Accounts accounts)
public ActionResult Edit(AccountViewModel accounts)
{

var acc1 = users.Get(accounts.AccountId);
var errors = new Dictionary<string, string>();
var check = true;
Expand Down Expand Up @@ -177,7 +231,7 @@ public ActionResult Edit(Accounts accounts)
}
}

if (users.CheckDuplicate(x => x.Email == accounts.Email && x.AccountId != acc1.AccountId) )
if (users.CheckDuplicate(x => x.Email == accounts.Email && x.AccountId != acc1.AccountId))
{
check = false;
errors.Add("Email", "Your email has been used!");
Expand All @@ -203,17 +257,24 @@ public ActionResult Edit(Accounts accounts)

if (ModelState.IsValid && check)
{

acc1.Name = accounts.Name;
acc1.Email = accounts.Email;
acc1.Password = accounts.Password;
acc1.Phone = accounts.Phone;
acc1.Birthday = accounts.Birthday;
acc1.Address = accounts.Address;
acc1.NumberId = accounts.NumberId;
acc1.RoleId = accounts.RoleId;
acc1.Status = accounts.Status;
users.Edit(acc1);
var acc3 = users.Get(accounts.AccountId);
acc3.Name = accounts.Name;
acc3.Email = accounts.Email;
acc3.Phone = accounts.Phone;
acc3.Birthday = DateTime.Parse(accounts.Birthday);
acc3.Address = accounts.Address;
acc3.NumberId = accounts.NumberId;
acc3.RoleId = accounts.RoleId;
acc3.Status = accounts.Status;
if (!users.Edit(acc3))
{
return Json(new
{
statusCode = 400,
message = "Error",
data = "Error"
}, JsonRequestBehavior.AllowGet);
}

return Json(new
{
Expand All @@ -223,12 +284,12 @@ public ActionResult Edit(Accounts accounts)
}

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);
}
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
{
Expand All @@ -237,9 +298,25 @@ public ActionResult Edit(Accounts accounts)
data = errors
}, JsonRequestBehavior.AllowGet);
}

[HttpPost]
public ActionResult Delete(int id)
{
using (var _context = new ApplicationDbContext())
{
var user = _context.Accounts.FirstOrDefault(x => x.AccountId == id);
var bankaccount = _context.BankAccounts.FirstOrDefault(x => x.AccountId == id);
if (bankaccount != null)
{
user.Status = 2;
_context.SaveChanges();
return Json(new
{
statusCode = 200,
message = "Success"
}, JsonRequestBehavior.AllowGet);
}
}

if (users.Delete(id))
{
return Json(new
Expand All @@ -258,7 +335,7 @@ public ActionResult Delete(int id)

public ActionResult ProfileAccount(int id)
{
if (((Accounts) Session["user"]) == null) return RedirectToAction("Login", "Home", new {area = ""});
if (((Accounts)Session["user"]) == null) return RedirectToAction("Login", "Home", new { area = "" });
var x = users.Get(id);
if (x == null)
{
Expand Down
26 changes: 25 additions & 1 deletion Backend/Areas/Admin/Controllers/BankAccountsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public ActionResult GetInfoBankAccount(string name)
Name = x.Account.Name,
Id = x.BankAccountId
});
if (data.FirstOrDefault() == null)
{
return Json(new
{
data,
message = "Error",
statusCode = 400
}, JsonRequestBehavior.AllowGet);
}
return Json(new
{
data,
Expand Down Expand Up @@ -106,7 +115,7 @@ public ActionResult Create(BankAccounts bank)
var errors = new Dictionary<string, string>();
var check = true;

if (!int.TryParse(bank.Name, out int i))
if (!long.TryParse(bank.Name, out long i))
{
check = false;
errors.Add("NameBank", "Your name must be number");
Expand Down Expand Up @@ -196,6 +205,21 @@ public ActionResult Edit(BankAccounts bank)
[HttpPost]
public ActionResult Delete(int id)
{
using (var _context1 = new ApplicationDbContext())
{
var bankAccount = _context1.BankAccounts.FirstOrDefault(x => x.BankAccountId == id);
var transaction = _context1.TransactionDetails.FirstOrDefault(x => x.BankAccountId == id);
if (transaction != null)
{
bankAccount.Status = 3;
_context1.SaveChanges();
return Json(new
{
statusCode = 200,
message = "Success"
}, JsonRequestBehavior.AllowGet);
}
}
if (bankAccounts.Delete(id))
{
return Json(new
Expand Down
7 changes: 2 additions & 5 deletions Backend/Areas/Admin/Controllers/ChequesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,8 @@ public ActionResult ChequeExec(ChequesExecViewModel chequeExec)
var newNotifications = CreateNotifications(newTransaction);

transaction.Commit();

// using (var chatHub = new ChatHub())
// {
// chatHub.SendNotifications(newNotifications);
// }

ChatHub.Instance().SendNotifications(newNotifications);

return Json(new
{
Expand Down
Loading

0 comments on commit 5afba4f

Please sign in to comment.