public Task <DebitPlayerResponse> DebitPlayer([FromBody] DebitPlayerRequest request) { DebitPlayerResponse response = null; var result = GetPlayer <DebitPlayerResponse>(request); if (result.Item2 != null) { response = result.Item2; } else if (result.Item1.Id != request.PlayerId) { response = new DebitPlayerResponse() { Code = BrandApiErrorCode.InvalidPlayerId, Status = BrandErrorCodes[BrandApiErrorCode.InvalidPlayerId][GetLanguage(result.Item1)] } } ; else if (result.Item1.CurrencyCode != request.CurrencyCode) { response = new DebitPlayerResponse() { Code = BrandApiErrorCode.InvalidCurrencyCodeForPlayer, Status = BrandErrorCodes[BrandApiErrorCode.InvalidCurrencyCodeForPlayer][GetLanguage(result.Item1)] } } ; else if (result.Item1.Amount < request.Amount) { response = new DebitPlayerResponse() { Code = BrandApiErrorCode.InsufficientFunds, Status = BrandErrorCodes[BrandApiErrorCode.InsufficientFunds][GetLanguage(result.Item1)] } } ; else if (result.Item1.PlayerLimit < request.Amount) { response = new DebitPlayerResponse() { Code = BrandApiErrorCode.BetExceedsPlayerLimit, Status = BrandErrorCodes[BrandApiErrorCode.BetExceedsPlayerLimit][GetLanguage(result.Item1)] } } ; else { result.Item1.Amount -= request.Amount; _context.SaveChanges(); response = new DebitPlayerResponse() { Code = BrandApiErrorCode.Ok, TransactionId = Guid.NewGuid().ToString() }; } return(Task.FromResult(response)); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { var user = _context.Users.FirstOrDefault(x => x.Email == model.Email); if (user != null) { user.Token = CalculateMD5Hash(user.Email); _context.SaveChanges(); } _logger.LogInformation("User logged in."); return(Json("OK")); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToAction(nameof(Lockout))); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); } } var errors = ModelState.Values.Where(x => x.ValidationState == ModelValidationState.Invalid); return(Json(errors)); }
public IActionResult ChangeLanguage(BaseViewModel vm) { var user = _context.Users.FirstOrDefault(x => x.UserName == User.Identity.Name); if (user != null) { user.LanguageCode = vm.LanguageCode; _context.SaveChanges(); } else { Response.Cookies.Append("lang", vm.LanguageCode); } return(Redirect("/")); }