Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

1.4 KB
Raw Blame
@using Grand.Business.Core.Extensions
@using Grand.Business.Core.Interfaces.Common.Stores
@inject IStoreService StoreService
@inject IContextAccessor contextAccessor
@{
    var availableStores = (await StoreService.GetAllStores())
        .Select(x =>
        {
            //model
            var storeModel = new StoreModel
            {
                Id = x.Id,
                        Name = x.GetTranslation(y => y.Name, contextAccessor.WorkContext.WorkingLanguage.Id),
                Shortcut = x.Shortcut
            };
            return storeModel;
        }).ToList();

    if (availableStores.Count > 1)
    {
        var returnUrl = Context?.Request?.GetEncodedPathAndQuery();

        <div class="dropdown btn-group me-2">
        <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">@availableStores.FirstOrDefault(x => x.Id == contextAccessor.StoreContext.CurrentStore.Id)?.Name</button>
        <ul class="dropdown-menu">
            @foreach (var store in availableStores)
            {
                var className = store.Id == contextAccessor.StoreContext.CurrentStore.Id ? "active" : "";
                <li><a class="dropdown-item @className" href="@Url.RouteUrl("ChangeStore", new { shortcut = store.Shortcut, returnUrl })">
                    @store.Name
                </a></li>
            }
        </ul>
    </div>
    }
}