public JsonResult CreateTransaction(int userId, TransactSave transaction) { LoggedUserInfo userInfo = _userCache.Get(userId); string error401 = transaction.RecipientID == 0 ? ConstStrings.ReplenishmentError401 : ConstStrings.TransferError401; if (userInfo != null) { Result <TransactPresentation> transactionData = _dataService.CreateTransaction(userInfo.Token, transaction); if (transactionData.Data != null) { userInfo.Balance += transaction.Amount; _userCache.Update(userInfo); return(Json(transactionData.Data, JsonRequestBehavior.AllowGet)); } else { if (transactionData.Error.IndexOf("401") != -1 || transactionData.Error.IndexOf("403") != -1) { _userCache.Delete(userId); return(Json(error401, JsonRequestBehavior.AllowGet)); } return(Json(transactionData.Error, JsonRequestBehavior.AllowGet)); } } return(Json(error401, JsonRequestBehavior.AllowGet)); }
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack) { return; } if (string.IsNullOrEmpty(Context.User?.Identity?.Name)) { // Not logged in. return; } AddLogin.Visible = true; SearchText.Visible = true; var userId = Context.User.Identity.GetUserId(); var user = _userCache.Get(userId); SetPermissions(user); RoleName.Text = user?.RoleId?.Length > 0 ? $"{user.CompanyName ?? "Logged In As"}: {Roles.GetName(user.RoleId)}" : string.Empty; InitializeDropdowns(); RefreshGrid(); }
protected void Page_Load(object sender, EventArgs e) { var userId = Context.User.Identity.GetUserId(); var user = _userCache.Get(userId); if (!Permissions.CanManageUsers(user?.RoleId)) { Response.Redirect("~/Default.aspx"); } if (!Page.IsPostBack) { RefreshGrid(); } }
public UserAccount GetAccount() { var key = BuildCacheKey(); var userAccount = _cache.Get <UserAccount>(key); if (userAccount == null) { userAccount = new UserAccount(); // Try to set default first and last names by parsing the principal's identity name. var userName = _principal?.Identity?.Name; if (string.IsNullOrEmpty(userName)) { userName = "******"; } var nameTokens = userName.Split(' '); if (nameTokens.Length > 1) { userAccount.LastName = nameTokens.Last(); userAccount.FirstName = string.Join(" ", nameTokens, 0, nameTokens.Length - 1); } else { userAccount.FirstName = userName; } _cache.Set(key, userAccount); } return(userAccount); }
public ShoppingCart GetShoppingCart() { var userName = _principal.Identity?.Name ?? "guest"; var key = $"{nameof(ShoppingCart)}_{userName}"; var shoppingCart = _cache.Get <ShoppingCart>(key); if (shoppingCart == null) { shoppingCart = new ShoppingCart(); _cache.Set(key, shoppingCart); } return(shoppingCart); }
/// <summary> /// Получение информации пользователя /// для блока пользователя. /// </summary> /// <param name="userId">Идентификатор пользователя.</param> /// <returns>Идентификатор пользователя.</returns> public int GetModelInfo(int userId) { if (userId != 0) { LoggedUserInfo info = _userCache.Get(userId); if (info != null) { ViewBag.Name = info.Name; ViewBag.Balance = info.Balance; return(userId); } } ViewBag.Name = string.Empty; ViewBag.Balance = 0; return(0); }
public JsonResult GetUserData(int userId) { return(new JsonResult(_userCache.Get(userId))); }