public async Task <JsonResult> BulkRegisterAccount(BulkAccountUploadModel model) { string filepath = saveUploadedFile(model.AccountFile); try { //Read the contents of CSV file. string csvData = System.IO.File.ReadAllText(filepath); //Execute a loop over the rows. foreach (string row in csvData.Split('\n')) { if (!string.IsNullOrEmpty(row)) { var split = row.Split(','); var account = new IdentityAccountNumber(split[0], split[1], split[2]); var result = await AccountNumberManager.CreateAsync(account); } } return(Json(new { code = "00", message = "Sucessfull" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { //TODO: implement log throw new Exception("Inavlid File Uploaded"); } }
public async Task <JsonResult> RegisterNewAccount(AccountNumberModel model) { if (ModelState.IsValid) { var account = new IdentityAccountNumber(model.AccountNumber, model.AccountName, model.AccountBranch); var result = await AccountNumberManager.CreateAsync(account); if (result) { return(Json(new { code = "00", message = "Sucessfull" }, JsonRequestBehavior.AllowGet)); } else { throw new Exception("New Account creation failed"); } } throw new Exception("Invalid Data Submitted"); }