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)); } }
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)); } }