public IViewComponentResult Invoke() { var tenantInfoIdentifier = _httpContextAccessor.HttpContext.GetMultiTenantContext().TenantInfo.Identifier; var shop = _rustShopService.GetShopById( Guid.Parse(_httpContextAccessor.HttpContext.GetMultiTenantContext().TenantInfo.Id)); var shopTitle = shop.ShopTitle; return(View("TenantNavBar", (tenantInfoIdentifier, shopTitle))); }
public async Task <IActionResult> Store() { string tenantId; try { tenantId = HttpContext.GetMultiTenantContext().TenantInfo.Id; } catch { return(RedirectToAction("Error404", "Error")); } var shopProducts = await _rustShopService.GetAllAssignedVisibleProductsToAShopByShopIdAsync(Guid.Parse(tenantId)); var shopCategories = _rustShopService.GetAllAssignedCategoriesToShopByShopId(Guid.Parse(tenantId)); var shop = _rustShopService.GetShopById(Guid.Parse(tenantId)); var model = new RustStoreViewModel { ShopName = shop.ShopName, Products = shopProducts.Select(x => new RustStoreProductViewModel { Id = x.Id.ToString(), Name = x.Name, Price = x.Price, Discount = x.Discount, BlockedTill = x.BlockedTill, ImgUrl = x.RustItem.ImgUrl, ItemsPerStack = x.ItemsPerStack, Description = x.Description, CategoryId = x.RustCategory.Id, CategoryName = x.RustCategory.Name, Type = x.RustItem.RustItemType.TypeName, PriceAfterDiscount = x.Price - (x.Price / 100) * x.Discount }), ProductCategories = shopCategories.ToDictionary( x => x.Id.ToString(), x => x.Name, StringComparer.OrdinalIgnoreCase) }; return(View(model)); }
public async Task InvokeAsync(HttpContext httpContext, EasyShopContext easyShopContext, IRustShopService rustShopService) { _easyShopContext = easyShopContext; _rustShopService = rustShopService; EasyShop.Domain.Entries.Shop.Shop shop = null; try { var tenantContext = httpContext.GetMultiTenantContext(); shop = _rustShopService.GetShopById(Guid.Parse(tenantContext.TenantInfo.Id)); } catch { await _next(httpContext); } if (httpContext.User.Identity.IsAuthenticated) { var steamUser = _easyShopContext.SteamUsers.FirstOrDefault(x => x.Uid == GetSteamUserUid(httpContext)); if (steamUser is null) { Guid newSteamUserGuid; do { newSteamUserGuid = Guid.NewGuid(); } while (_easyShopContext.SteamUsers.FirstOrDefault(x => x.Id == newSteamUserGuid) != null); var newSteamUser = new SteamUser { Id = newSteamUserGuid, Uid = GetSteamUserUid(httpContext), TotalSpent = 0m }; if (shop != null) { var newSteamUserShop = new SteamUserShop { Shop = shop, SteamUser = newSteamUser, Balance = shop.StartBalance, TotalSpent = 0m }; _easyShopContext.SteamUsersShops.Add(newSteamUserShop); } _easyShopContext.SteamUsers.Add(newSteamUser); await _easyShopContext.SaveChangesAsync(); } else { var steamUserShop = _easyShopContext.SteamUsersShops.FirstOrDefault(x => x.SteamUser.Id == steamUser.Id && x.Shop.Id == shop.Id); if (steamUserShop is null) { var newSteamUserShop = new SteamUserShop { Shop = shop, SteamUser = steamUser, Balance = shop.StartBalance, TotalSpent = 0m, StartBalance = shop.StartBalance }; _easyShopContext.SteamUsersShops.Add(newSteamUserShop); await _easyShopContext.SaveChangesAsync(); } } } await _next(httpContext); }