public ActionResult Edit(AgencyAccount model, string ReNewPassword) { model.IsDeleted = false; model.UpdatedAt = DateTime.Now; if (ModelState.IsValid) { try { if (model.Email == "" || model.Email == null) { model.Email = model.UserName; } if (ReNewPassword != null && ReNewPassword.Trim().Length > 0) { model.Password = SimpleEncrypt.Encrypt(ReNewPassword, true); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(Content(javasctipt_add("/AgencyAccount", "Cập nhật dữ liệu thành công"))); } catch (Exception) { return(Content(javasctipt_add("/AgencyAccount", "Cập nhật dữ liệu thất bại"))); } } ViewBag.AgencyId = new SelectList(db.Agencies, "Id", "Id", model.AgencyId); ViewBag.RoleId = new SelectList(db.Roles.Where(n => n.Name.Contains("Agency")), "Id", "Name", model.RoleId); var status = StatusUtils.GetSettingStatus(); ViewBag.IsActive = new SelectList(status, "Value", "Text", model.IsActive); ViewBag.Gender = new SelectList(StatusUtils.GetGender(), "Value", "Text", model.Gender); return(Content(javasctipt_add("/AgencyAccount", "Cập nhật dữ liệu thất bại"))); }
public ActionResult Add(AgencyAccount model) { model.IsDeleted = false; model.CreatedAt = model.UpdatedAt = DateTime.Now; if (ModelState.IsValid) { try { if (model.Email == "" || model.Email == null) { model.Email = model.UserName; } model.Password = SimpleEncrypt.Encrypt(model.Password, true); db.AgencyAccounts.Add(model); db.SaveChanges(); return(Content(javasctipt_add("/AgencyAccount", "Thêm dữ liệu thành công"))); } catch (Exception) { return(Content(javasctipt_add("/AgencyAccount", "Thêm dữ liệu thất bại"))); } } ViewBag.AgencyId = new SelectList(db.Agencies, "Id", "Id", model.AgencyId); ViewBag.RoleId = new SelectList(db.Roles.Where(n => n.Name.Contains("Agency")), "Id", "Name", model.RoleId); var status = StatusUtils.GetSettingStatus(); ViewBag.IsActive = new SelectList(status, "Value", "Text", model.IsActive); ViewBag.Gender = new SelectList(StatusUtils.GetGender(), "Value", "Text", model.Gender); return(Content(javasctipt_add("/AgencyAccount", "Thêm dữ liệu thất bại"))); }
public async Task <Result> CreateForAgency(Agency agency, Currencies currency) { return(await CheckAgencyVerified() .Map(CreateAccount) .Tap(LogSuccess) .OnFailure(LogFailure)); async Task <Result> CheckAgencyVerified() { var(_, isFailure, verificationState, error) = await _adminAgencyManagementService.GetVerificationState(agency.Id); if (isFailure) { return(Result.Failure(error)); } return(new[] { AgencyVerificationStates.ReadOnly, AgencyVerificationStates.FullAccess }.Contains(verificationState) ? Result.Success() : Result.Failure("Account creation is only available for verified agencies")); } async Task <AgencyAccount> CreateAccount() { var account = new AgencyAccount { Balance = 0, AgencyId = agency.Id, Currency = Currencies.USD, // Only USD currency is supported Created = _dateTimeProvider.UtcNow() }; _context.AgencyAccounts.Add(account); _context.AgencyMarkupBonusesAccounts.Add(new AgencyMarkupBonusesAccount { AgencyId = agency.Id, Currency = Currencies.USD, Balance = 0 }); await _context.SaveChangesAsync(); return(account); } void LogSuccess(AgencyAccount account) { _logger.LogAgencyAccountCreationSuccess(agency.Id, account.Id); } void LogFailure(string error) { _logger.LogAgencyAccountCreationFailed(agency.Id, error); } }
private async Task <AgencyAccount> WriteAuditLogWithReferenceCode(AgencyAccount account, ChargedMoneyData paymentData, AccountEventType eventType, UserInfo user) { var eventData = new AccountBalanceLogEventData(paymentData.Reason, account.Balance); await _auditService.Write(eventType, account.Id, paymentData.Amount, user, eventData, paymentData.ReferenceCode); return(account); }
public ActionResult UpdateInfo(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AgencyAccount agencyAccount = db.AgencyAccounts.Find(id.FromBase64()); if (agencyAccount == null) { return(HttpNotFound()); } ViewBag.RoleId = new SelectList(db.Roles.Where(n => n.Name.Contains("Agency")), "Id", "Name", agencyAccount.RoleId); return(View(agencyAccount)); }
public ActionResult UpdateInfo(AgencyAccount agencyAccount, string ReNewPassword) { agencyAccount.IsDeleted = false; agencyAccount.IsActive = true; agencyAccount.UpdatedAt = DateTime.Now; agencyAccount.AgencyId = user.Agency.Id; if (ModelState.IsValid) { try { var upImage = Request.Files["upImage"]; if (upImage.ContentLength > 0 && upImage != null) { string fileName = upImage.FileName.DoiTenHinh(); upImage.SaveAs(Server.MapPath("~/images/Staff/" + fileName)); agencyAccount.Avatar = fileName; } if (ReNewPassword != null && ReNewPassword.Trim().Length > 0) { agencyAccount.Password = SimpleEncrypt.Encrypt(ReNewPassword, true); } db.Entry(agencyAccount).State = EntityState.Modified; db.SaveChanges(); Session["AccBetterLife"] = agencyAccount; #region create cookies HttpCookie ckiUser = new HttpCookie("CkBetterLife"); ckiUser["Id"] = agencyAccount.UserName; ckiUser["Pw"] = SimpleEncrypt.Encrypt(agencyAccount.Password, true); ckiUser.Expires = DateTime.Now.AddHours(24); Response.Cookies.Add(ckiUser); #endregion TempData["Message"] = "Cập nhật thông tin thành công"; return(PartialView("~/views/Message/Add.cshtml")); } catch (Exception) { ModelState.AddModelError("error", "Có lỗi xảy ra, vui lòng kiểm tra lại dữ liệu"); TempData["Message"] = "Có lỗi xảy ra, vui lòng kiểm tra lại dữ liệu"; } } ViewBag.RoleId = new SelectList(db.Roles.Where(n => n.Name.Contains("Agency")), "Id", "Name", agencyAccount.RoleId); return(View(agencyAccount)); }
public async Task <Result> CreateForAgency(Agency agency, Currencies currency) { return(await Result.Success() .Ensure(IsCounterpartyVerified, "Account creation is only available for verified counterparties") .Map(CreateAccount) .Tap(LogSuccess) .OnFailure(LogFailure)); async Task <bool> IsCounterpartyVerified() { var counterparty = await _context.Counterparties.Where(c => c.Id == agency.CounterpartyId).SingleAsync(); return(new[] { CounterpartyStates.ReadOnly, CounterpartyStates.FullAccess }.Contains(counterparty.State)); } async Task <AgencyAccount> CreateAccount() { var account = new AgencyAccount { Balance = 0, AgencyId = agency.Id, Currency = Currencies.USD, // Only USD currency is supported Created = _dateTimeProvider.UtcNow() }; _context.AgencyAccounts.Add(account); await _context.SaveChangesAsync(); return(account); } void LogSuccess(AgencyAccount account) { _logger.LogAgencyAccountCreationSuccess( $"Successfully created account for agency: '{agency.Id}', account id: {account.Id}"); } void LogFailure(string error) { _logger.LogAgencyAccountCreationFailed($"Failed to create account for agency {agency.Id}, error {error}"); } }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AgencyAccount model = db.AgencyAccounts.Find(id.FromBase64()); if (model == null) { return(HttpNotFound()); } ViewBag.AgencyId = new SelectList(db.Agencies, "Id", "Id", model.AgencyId); ViewBag.RoleId = new SelectList(db.Roles.Where(n => n.Name.Contains("Agency")), "Id", "Name", model.RoleId); var status = StatusUtils.GetSettingStatus(); ViewBag.IsActive = new SelectList(status, "Value", "Text", model.IsActive); ViewBag.Gender = new SelectList(StatusUtils.GetGender(), "Value", "Text", model.Gender); return(View(model)); }
public async Task SendNotificationIfRequired(AgencyAccount account, MoneyAmount chargedAmount) { var resultingBalance = account.Balance - chargedAmount.Amount; var(_, isFailure, setting, _) = await _balanceNotificationsManagementService.Get(account.Id); if (isFailure || !setting.Thresholds.Any(t => account.Balance >= t && resultingBalance < t)) { return; } var(_, isAgencyFailure, agency, _) = await _adminAgencyManagementService.Get(account.AgencyId); if (isAgencyFailure) { return; } var lowestThreshold = setting.Thresholds .Where(t => account.Balance >= t && resultingBalance < t) .OrderBy(t => t) .First(); var messageData = new AccountBalanceManagementNotificationData { AgencyAccountId = account.Id, AgencyId = agency.Id ?? 0, AgencyName = agency.Name, Currency = EnumFormatters.FromDescription(account.Currency), Threshold = lowestThreshold, NewAmount = MoneyFormatter.ToCurrencyString(resultingBalance, account.Currency) }; await _notificationService.Send(messageData : messageData, notificationType : NotificationTypes.AccountBalanceManagementNotification, email : _options.AccountsEmail); }
private bool AreCurrenciesMatch(AgencyAccount account, ChargedMoneyData paymentData) => account.Currency == paymentData.Currency;
private bool IsBalanceSufficient(AgencyAccount account, decimal amount) => account.Balance.IsGreaterOrEqualThan(amount * (1 - MaxOverdraftProportion));