EF Core - updated data retrieve problem

Cenk 956 Reputation points
2022-09-16T05:37:57.627+00:00

Hello,

I am trying to get updated data like this in my Blazor Server application:

async Task PassiveDetail(OrderDetail orderDetail)  
    {  
        if (orderDetail == _detailToInsert)  
        {  
            _detailToInsert = null;  
        }  
  
          
        await PassiveOrderDetailUseCase.ExecuteAsync(orderDetail);  //Updates a value  
          
        _orders = await ViewAllOrdersUseCase.ExecuteAsync(user); // Retrieves data but not updated!  
        StateHasChanged();  
  
    }  

Here is how I update a value:

public async Task PassiveOrderDetailAsync(OrderDetail orderDetail)  
        {  
             
            var detail = await this._db.OrdersDetail.FindAsync(orderDetail.Id);  
            if (detail != null)  
            {  
                  
                detail.IsActive = 0; // 0-Passive  
                  
                await _db.SaveChangesAsync();  
            }  
        }  

Here is how I retrieve:

public async Task<IEnumerable<Order?>> GetAllOrders(ClaimsPrincipal user)  
        {  
            if (user.IsInRole("Administrators"))  
            {  
                return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync(); ;  
            }  
              
            return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync();  
  
        }  

When I refresh the page the data is updated, what is the problem? Any ideas?

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
697 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,386 questions
{count} votes

9 answers

Sort by: Most helpful
  1. Cenk 956 Reputation points
    2022-09-16T10:00:34.2+00:00

    Here is the Blazor Page for the transaction I mention, retrieving correct on OnInitializedAsync method but it is not working on async Task PassiveDetail(OrderDetail orderDetail) why it is not ?

    @page "/orders"  
      
    @using IMS.CoreBusiness  
    @using IMS.Plugins.EFCore.Migrations  
    @using IMS.UseCases.Interfaces.Order  
    @using IMS.UseCases.Interfaces.OrderDetail  
    @using System.Globalization  
    @using System.Security.Claims  
    @using IMS.UseCases.Interfaces.Customer  
    @using IMS.UseCases.Interfaces.Vendor  
    @using Vendor = IMS.CoreBusiness.Vendor  
    @using OfficeOpenXml  
    @using OfficeOpenXml.Style  
      
      
    @inject NavigationManager NavigationManager  
    @inject IViewAllOrdersUseCase ViewAllOrdersUseCase  
    @inject IAddOrderUseCase AddOrderUseCase  
    @inject IEditOrderUseCase EditOrderUseCase  
    @inject IAddOrderDetailUseCase AddOrderDetailUseCase  
    @inject IEditOrderDetailUseCase EditOrderDetailUseCase  
    @inject IViewAllVendorsUseCase ViewAllVendorsUseCase  
    @inject IViewOrdersByStatusUseCase ViewOrdersByStatusUseCase  
    @inject ICancelOrderUseCase CancelOrderUseCase  
    @inject ICancelOrderDetailUseCase CancelOrderDetailUseCase  
    @inject IViewAllCustomersUseCase ViewAllCustomersUseCase  
    @inject IPassiveOrderDetailUseCase PassiveOrderDetailUseCase  
    @inject IJSRuntime JS  
    @inject AuthenticationStateProvider _authenticationStateProvider  
      
      
      
    <style>  
        #wrapper { overflow: auto; }  
      
        #c1 { float: right; }  
      
        #c2 { float: right; }  
      
        #c3 { float: right; }  
    </style>  
    @if (DisplayAlert) {  
        <div class="alert alert-success alert-dismissible d-flex align-items-center fade show">  
            <i class="bi-check-circle-fill"></i>  
            <strong class="mx-2">Success!</strong> Your message has been sent successfully.  
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>  
        </div>  
    }  
    <h1>Orders</h1>  
    <RadzenButton Icon="add_circle_outline" style="margin-bottom: 10px" Text="Add New Order" Click="@InsertRow" Disabled="@(_orderToInsert != null)"/><RadzenButton Text="Export XLS" Icon="grid_on" Click="@(args => ExportExcel())" Class="mb-4 mr-2" />  
    <RadzenDataGrid @ref="_grid" AllowFiltering="true" AllowPaging="true" PageSize="7" AllowSorting="true" RowClick="RowClick" ExpandMode="DataGridExpandMode.Single"  
                    Data="@_orders" TItem="Order" EditMode="DataGridEditMode.Single" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" @bind-Value="@SelectedOrders"  
                    ShowExpandColumn="false" ShowPagingSummary="true" AllowColumnResize="true" >  
        <Template Context="order">  
            <RadzenCard Style="margin-bottom: 20px">  
                Customer:  
                <b>@order?.Customer?.Name</b>  
            </RadzenCard>  
            <RadzenTabs>  
                <Tabs>  
                    <RadzenTabsItem Text="Order Details">  
                        <div id="wrapper">  
                            <RadzenButton Icon="add_circle_outline" style="margin-bottom: 10px" Text="Add Order Detail" Click="@(() => InsertDetailRow(order.Id))" Disabled="@(_detailToInsert != null)"/>  
                            <RadzenButton Text="Export XLS" Icon="grid_on" Click="@(args => ExportDetailExcel())" Class="mb-4 mr-2" />  
                            <RadzenButton Icon="close" id="c3" style="margin-bottom: 10px;" ButtonStyle="ButtonStyle.Light" Click="@(args => CancelEdits(SelectedOrders.FirstOrDefault()?.OrderDetails))" />  
                            <RadzenButton Icon="save" style="margin-bottom: 10px; margin-right: 10px" Text="Save Details" id="c2" Click="@(args => SaveRowDetails(SelectedOrders.FirstOrDefault()?.OrderDetails))"/>  
                            <RadzenButton Icon="border_color" style="margin-bottom: 10px; margin-right: 10px" Text="Edit Details" id="c1" Click="@(args => EditRowDetails(SelectedOrders.FirstOrDefault()?.OrderDetails))" @onclick:stopPropagation="true"/>  
                              
                              
                        </div>  
                        <RadzenDataGrid @ref="_gridDetail" AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true" Data="@order.OrderDetails"   
                        TItem="OrderDetail" EditMode="DataGridEditMode.Multiple" RowUpdate="@OnUpdateRowDetail" RowCreate="@OnCreateRowDetail" AllowColumnResize="true"  
                                        AllowColumnPicking="true" ShowPagingSummary="true" ColumnWidth="150px" >  
                            <Columns>  
      
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Id" Title="Product Number" Frozen="true" OrderIndex="1"/>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="ProductCode" Title="Code" Frozen="true" OrderIndex="2">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.ProductCode" Style="width: 100%; display: block" Name="ProductCode"/>  
                                        <RadzenRequiredValidator Text="Product Code is required" Component="ProductCode" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="ProductName" Title="Name" Frozen="true" OrderIndex="3">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.ProductName" Style="width: 100%; display: block" Name="ProductName"/>  
                                        <RadzenRequiredValidator Text="Product Name is required" Component="ProductName" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Vendor.Name" Title="Vendor" Width="200px" OrderIndex="4">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenDropDownDataGrid TValue="int"  AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains"  
                                                                Data=@_vendors Count="5" TextProperty="Name" ValueProperty="Id"  
                                                                Class="w-100" @bind-Value="orderDetail.VendorId"/>  
                                          
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Currency" Title="Currency" OrderIndex="5">  
                                    <EditTemplate Context="orderDetail">  
                                       <RadzenDropDown AllowClear="true" TValue="string" Class="w-100" Data=@currency @bind-Value="orderDetail.Currency" Name="Currency" />  
                                        <RadzenRequiredValidator Text="Currency is required" Component="Currency" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity" OrderIndex="6">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenNumeric TValue="int" Min="1" @bind-Value="orderDetail.Quantity" Style="width: 100%; display: block" Name="Quantity"/>  
                                        <RadzenRequiredValidator Text="Quantity is required" Component="Quantity" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                    <FooterTemplate>  
                                        <b>@string.Format(new CultureInfo("tr-TR"), "{0:G}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.Quantity))</b>  
                                    </FooterTemplate>  
                                </RadzenDataGridColumn>  
                                @*<AuthorizeView Roles="Administrators"> *@  
                                    <RadzenDataGridColumn TItem="OrderDetail" Property="BuyUnitPrice" Title="Buy Unit Price" OrderIndex="7">  
                                    <Template Context="detail">  
                                        @switch (detail.Currency)  
                                        {  
                                            case "Dolar":  
                                                @string.Format(new CultureInfo("en-US"), "{0:C2}", detail.BuyUnitPrice)  
                                                break;  
                                            case "Euro":  
                                                @string.Format(new CultureInfo("en-FR"), "{0:C2}", detail.BuyUnitPrice)  
                                                break;  
                                            default:  
                                                @string.Format(new CultureInfo("tr-TR"), "{0:C2}", detail.BuyUnitPrice)  
                                                break;  
                                        }  
                                    </Template>  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenNumeric TValue="double" Min="1" @bind-Value="orderDetail.BuyUnitPrice" Style="width: 100%; display: block" Name="BuyUnitPrice"/>  
                                        <RadzenRequiredValidator Text="BuyUnitPrice is required" Component="BuyUnitPrice" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                               @* </AuthorizeView>*@  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="TotalBuyPrice" Title="Total Buy" OrderIndex="8">  
                                   <Template Context="detail">  
                                        @switch (detail.Currency)  
                                        {  
                                            case "Dolar":  
                                                @string.Format(new CultureInfo("en-US"), "{0:C2}", detail.BuyUnitPrice * detail.Quantity)  
                                                break;  
                                            case "Euro":  
                                                @string.Format(new CultureInfo("en-FR"), "{0:C2}", detail.BuyUnitPrice * detail.Quantity)  
                                                break;  
                                            default:  
                                                @string.Format(new CultureInfo("tr-TR"), "{0:C2}", detail.BuyUnitPrice * detail.Quantity)  
                                                break;  
                                        }  
                                    </Template>  
                                    <FooterTemplate>  
                                        @if(SelectedOrders?.FirstOrDefault()?.OrderDetails.GroupBy(x => x.Currency).Count() == 1)  
                                        {  
                                            @switch (SelectedOrders?.FirstOrDefault()?.OrderDetails.FirstOrDefault().Currency)  
                                            {  
                                                case "Dolar":  
                                                    <b>@string.Format(new CultureInfo("tr-TR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalBuyPrice))</b>  
                                                    break;  
                                                case "Euro":  
                                                    <b>@string.Format(new CultureInfo("en-FR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalBuyPrice))</b>  
                                                    break;  
                                                default:  
                                                    <b>@string.Format(new CultureInfo("tr-TR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalBuyPrice))</b>  
                                                    break;  
                                            }  
                                              
                                        }  
                                    </FooterTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="CostRatio" Title="Cost Ratio" OrderIndex="9">  
                                    <Template Context="detail">  
                                        @string.Format(new CultureInfo("tr-TR"), "{0:D2}","%" + detail.CostRatio/100)  
                                    </Template>  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenNumeric TValue="double" Min="1" @bind-Value="orderDetail.CostRatio" Style="width: 100%; display: block" Name="CostRatio"/>  
                                        <RadzenRequiredValidator Text="Cost Ratio is required" Component="CostRatio" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="UnitCost" Title="Unit Cost" OrderIndex="10">  
                                    <Template Context="detail">  
                                        @switch (detail.Currency)  
                                        {  
                                            case "Dolar":  
                                                @string.Format(new CultureInfo("en-US"), "{0:C}", (detail.BuyUnitPrice * (detail.CostRatio / 100)) + detail.BuyUnitPrice)  
                                                break;  
                                            case "Euro":  
                                                @string.Format(new CultureInfo("en-FR"), "{0:C}", (detail.BuyUnitPrice * (detail.CostRatio / 100)) + detail.BuyUnitPrice)  
                                                break;  
                                            default:  
                                                @string.Format(new CultureInfo("tr-TR"), "{0:C}", (detail.BuyUnitPrice * (detail.CostRatio / 100)) + detail.BuyUnitPrice)  
                                                break;  
                                        }  
                                    </Template>  
                                </RadzenDataGridColumn>  
                            <RadzenDataGridColumn TItem="OrderDetail" Property="TotalUnitCost" Title="Total Unit Cost" OrderIndex="11">  
                                <Template Context="detail">  
                                    @switch (detail.Currency)  
                                    {  
                                        case "Dolar":  
                                            @string.Format(new CultureInfo("en-US"), "{0:C}", (detail.Quantity * detail.UnitCost))  
                                            break;  
                                        case "Euro":  
                                            @string.Format(new CultureInfo("en-FR"), "{0:C}", (detail.Quantity * detail.UnitCost))  
                                            break;  
                                        default:  
                                            @string.Format(new CultureInfo("tr-TR"), "{0:C}", (detail.Quantity * detail.UnitCost))  
                                            break;  
                                    }  
                                </Template>  
                            </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="SellUnitPrice" Title="Sell Unit Price" OrderIndex="12">  
                                    <Template Context="detail">  
                                        @switch (detail.Currency)  
                                        {  
                                            case "Dolar":  
                                                @string.Format(new CultureInfo("en-US"), "{0:C2}", detail.SellUnitPrice)  
                                                break;  
                                            case "Euro":  
                                                @string.Format(new CultureInfo("en-FR"), "{0:C2}", detail.SellUnitPrice)  
                                                break;  
                                            default:  
                                                @string.Format(new CultureInfo("tr-TR"), "{0:C2}", detail.SellUnitPrice)  
                                                break;  
                                        }  
                                    </Template>  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenNumeric TValue="double" Min="1" @bind-Value="orderDetail.SellUnitPrice" Style="width: 100%; display: block" Name="SellUnitPrice"/>  
                                        <RadzenRequiredValidator Text="Sell Unit price is required" Component="SellUnitPrice" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="TotalSellPrice" Title="Total Sell" OrderIndex="13">  
                                    <Template Context="detail">  
                                        @switch (detail.Currency)  
                                        {  
                                            case "Dolar":  
                                                @string.Format(new CultureInfo("en-US"), "{0:C2}", detail.SellUnitPrice * detail.Quantity)  
                                                break;  
                                            case "Euro":  
                                                @string.Format(new CultureInfo("en-FR"), "{0:C2}", detail.SellUnitPrice * detail.Quantity)  
                                                break;  
                                            default:  
                                                @string.Format(new CultureInfo("tr-TR"), "{0:C2}", detail.SellUnitPrice * detail.Quantity)  
                                                break;  
                                        }  
                                    </Template>  
                                    <FooterTemplate>  
                                        @if(SelectedOrders?.FirstOrDefault()?.OrderDetails.GroupBy(x => x.Currency).Count() == 1)  
                                        {  
                                            @switch (SelectedOrders?.FirstOrDefault()?.OrderDetails.FirstOrDefault().Currency)  
                                            {  
                                                case "Dolar":  
                                                    <b>@string.Format(new CultureInfo("tr-TR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalSellPrice))</b>  
                                                    break;  
                                                case "Euro":  
                                                    <b>@string.Format(new CultureInfo("en-FR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalSellPrice))</b>  
                                                    break;  
                                                default:  
                                                    <b>@string.Format(new CultureInfo("tr-TR"), "{0:C2}", SelectedOrders?.FirstOrDefault()?.OrderDetails.Sum(o => o.TotalSellPrice))</b>  
                                                    break;  
                                            }  
                                              
                                        }  
                                    </FooterTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="ShippingNumber" Title="Shipment" OrderIndex="14">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.ShippingNumber" Style="width: 100%; display: block" Name="ShippingNumber"/>  
                                        <RadzenRequiredValidator Text="Shipping Number is required" Component="ShippingNumber" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="TrackingNumber" Title="Tracking Number" OrderIndex="15">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.TrackingNumber" Style="width: 100%; display: block" Name="TrackingNumber"/>  
                                        <RadzenRequiredValidator Text="Tracking Number is required" Component="TrackingNumber" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Description" Title="Description" OrderIndex="16">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.Description" Style="width: 100%; display: block" Name="Description"/>  
                                        <RadzenRequiredValidator Text="Description is required" Component="Description" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="Status" Title="Status" OrderIndex="17">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenDropDown AllowClear="true" TValue="string" Class="w-100" Data=@detailStatusList @bind-Value="orderDetail.Status" Name="Status" Change=@(args => OnChange(args, order.Id)) />  
                                        <RadzenRequiredValidator Text="Status is required" Component="Status" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="CustomerStockCode" Title="Customer Stock" OrderIndex="18">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.CustomerStockCode" Style="width: 100%; display: block" Name="CustomerStockCode"/>  
                                        <RadzenRequiredValidator Text="Customer Stock Code is required" Component="CustomerStockCode" Popup="true" Style="position: absolute"/>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="CustomerOrderNumber" Title="Customer Order" OrderIndex="19">  
                                    <EditTemplate Context="orderDetail">  
                                        <RadzenTextBox @bind-Value="orderDetail.CustomerOrderNumber" Style="width: 100%; display: block" Name="CustomerOrderNumber"/>  
                                        <RadzenRequiredValidator Text="Customer Order Number is required" Component="CustomerOrderNumber" Popup="true" Style="position: absolute" />  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                                <RadzenDataGridColumn TItem="OrderDetail" Property="OrderId" Title="Order Id" OrderIndex="20"/>  
                                <RadzenDataGridColumn TItem="OrderDetail" Context="orderDetail" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="200px" OrderIndex="20">  
                                    <Template Context="detail">  
                                        <RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRowDetail(detail))" @onclick:stopPropagation="true">  
                                        </RadzenButton>  
                                    </Template>  
                                    <EditTemplate Context="detail">  
                                        <RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRowDetail(detail))">  
                                        </RadzenButton>  
                                        <RadzenButton Icon="close" ButtonStyle="ButtonStyle.Light" Class="m-1" Click="@(args => CancelEditDetail(detail))">  
                                        </RadzenButton>  
                                        <RadzenButton Icon="delete" ButtonStyle="ButtonStyle.Danger" Class="m-1" Click="@(args => PassiveDetail(detail))">  
                                        </RadzenButton>  
                                    </EditTemplate>  
                                </RadzenDataGridColumn>  
                            </Columns>  
                        </RadzenDataGrid>  
                    </RadzenTabsItem>  
      
                </Tabs>  
            </RadzenTabs>  
        </Template>  
        <Columns>  
            <RadzenDataGridColumn TItem="Order" Property="Id" Title="Order ID" Width="120px"/>  
            <RadzenDataGridColumn TItem="Order" Property="Customer.Name" Title="Customer" Width="200px">  
                <EditTemplate Context="order">  
                    <RadzenDropDownDataGrid TValue="int"  AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterOperator="StringFilterOperator.Contains"  
                                            Data=@_customers Count="5" TextProperty="Name" ValueProperty="Id"  
                                            Class="w-100" @bind-Value="order.CustomerId"/>  
                                          
                </EditTemplate>  
            </RadzenDataGridColumn>  
            <RadzenDataGridColumn TItem="Order" Property="OrderDateTime" Title="Order Date" Width="200px">  
                <Template Context="order">  
                    @($"{order.OrderDateTime:dd/MM/yyyy}")  
                </Template>  
                <EditTemplate Context="order">  
                    <RadzenDatePicker @bind-Value="order.OrderDateTime" DateFormat="dd/MM/yyyy HH:mm" Class="w-100"/>  
                </EditTemplate>  
            </RadzenDataGridColumn>  
            <RadzenDataGridColumn TItem="Order" Property="Status" Title="Status" Width="100px">  
                @*<EditTemplate Context="order">  
                      
                    <RadzenDropDown AllowClear="true" TValue="string" Class="w-150" Data=@orderStatusList Name="Status" @bind-Value="order.Status"/>  
                    <RadzenRequiredValidator Text="Status is required" Component="Status" Popup="true" Style="position: absolute"/>  
                </EditTemplate>*@  
            </RadzenDataGridColumn>  
            @*<RadzenDataGridColumn TItem="Order" Property="DoneBy" Title="Employee">  
                <EditTemplate Context="order">  
                    <RadzenTextBox @bind-Value="order.DoneBy" Style="width: 100%; display: block" Name="DoneBy"/>  
                    <RadzenRequiredValidator Text="DoneBy is required" Component="DoneBy" Popup="true" Style="position: absolute"/>  
                </EditTemplate>  
            </RadzenDataGridColumn>*@  
            <RadzenDataGridColumn TItem="Order" Context="order" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="120px">  
                <Template Context="order">  
                    <RadzenButton Icon="edit" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => EditRow(order))" @onclick:stopPropagation="true">  
                    </RadzenButton>  
                </Template>  
                <EditTemplate Context="order">  
                    <RadzenButton Icon="check" ButtonStyle="ButtonStyle.Primary" Class="m-1" Click="@(args => SaveRow(order))">  
                    </RadzenButton>  
                    <RadzenButton Icon="close" ButtonStyle="ButtonStyle.Light" Class="m-1" Click="@(args => CancelEdit(order))">  
                    </RadzenButton>  
                </EditTemplate>  
            </RadzenDataGridColumn>  
      
        </Columns>  
    </RadzenDataGrid>  
      
    @code {  
        [Parameter]  
        public bool DisplayAlert { get; set; } = false;   
        [Parameter]  
        public string? SelectedStatus { get; set; }  
      
        // Options to display in the roles dropdown when editing a user  
        readonly List<string> detailStatusList = new() { "At customs", "Being supplied", "Cancelled", "Completed", "Getting ready", "In warehouse",  "Shipped" };  
        readonly List<string> orderStatusList = new() { "Continues", "Cancelled", "Completed" };  
        readonly List<string> currency = new() { "TL", "Dolar", "Euro"};  
      
        IList<Order?> SelectedOrders { get; set; }  
        IEnumerable<Order?> _orders = new List<Order?>();  
        IEnumerable<Vendor?> _vendors;  
        IEnumerable<Customer?> _customers;  
        IQueryable<Order?> filter;  
        IQueryable<OrderDetail?> filterDetail;  
      
        RadzenDataGrid<Order?> _grid;  
        RadzenDataGrid<OrderDetail> _gridDetail;  
      
        Order? _orderToInsert;  
        OrderDetail? _detailToInsert;  
      
        ClaimsPrincipal user;  
      
      
        protected override async Task OnInitializedAsync()  
        {  
            user = (await _authenticationStateProvider.GetAuthenticationStateAsync()).User;  
      
            //userName = user.Identity.Name;  
            if (!user.Identity.IsAuthenticated)  
            {  
                NavigationManager.NavigateTo("/Identity/Account/Login", false);  
            }  
            _orders = await ViewAllOrdersUseCase.ExecuteAsync(user);  
            SelectedOrders = new List<Order?> { _orders.FirstOrDefault() };  
            _vendors = await ViewAllVendorsUseCase.ExecuteAsync();  
            _customers = await ViewAllCustomersUseCase.ExecuteAsync();  
        }  
      
      
        private void OnChange(object args, int id)  
        {  
            if(args != null){  
                SelectedStatus = args.ToString();  
            }  
      
        }  
      
        private async Task RowClick(DataGridRowMouseEventArgs<Order> mouseClick) {  
      
            await _grid!.ExpandRow(mouseClick.Data);  
      
        }  
      
        private async Task InsertRow()  
        {  
            _orderToInsert = new Order  
            {  
                OrderDateTime = DateTime.Now,  
                OrderDetails = new List<OrderDetail>()  
            };  
            await _grid.InsertRow(_orderToInsert);  
        }  
      
        private async Task InsertDetailRow(int id)  
        {  
            _detailToInsert = new OrderDetail  
            {  
                OrderId = id  
            };  
            await _gridDetail.InsertRow(_detailToInsert);  
        }  
      
        private async Task OnCreateRow(Order? order)  
        {  
            if (order != null)  
            {  
                await AddOrd
    
    0 comments No comments

  2. Cenk 956 Reputation points
    2022-09-16T12:53:17.843+00:00

    They are in different repositories, is it because of this? I mean something to mark as modified or something.

    Order Repository

    namespace IMS.Plugins.EFCore  
    {  
        public class OrderRepository : IOrderRepository  
        {  
            private readonly IMSContext _db;  
              
            public OrderRepository(IMSContext db)  
            {  
                _db = db;  
                 
            }  
      
            public async Task<IEnumerable<Order?>> GetAllOrders(ClaimsPrincipal user)  
            {  
                if (user.IsInRole("Administrators"))  
                {  
                    return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync();  
                }  
                  
                return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync();  
      
            }  
      
              
      
             
        }  
    }  
    

    Order Detail Repository

    namespace IMS.Plugins.EFCore  
    {  
        public class OrderDetailRepository : IOrderDetailRepository  
        {  
            private readonly IMSContext _db;  
      
            public OrderDetailRepository(IMSContext db)  
            {  
                _db = db;  
            }  
      
      
            public async Task PassiveOrderDetailAsync(OrderDetail orderDetail)  
            {  
                 
                var detail = await this._db.OrdersDetail.FindAsync(orderDetail.Id);  
                if (detail != null)  
                {  
                      
                    detail.IsActive = 0; // 0-Passive  
                      
                    await _db.SaveChangesAsync();  
                }  
            }  
             
        }  
    }  
      
      
    
    0 comments No comments

  3. Cenk 956 Reputation points
    2022-09-17T10:30:03.103+00:00

    It seems that this problem occurs because they are different repositories. I tried something like this in the Order Detail repository.

    public async Task<IEnumerable<OrderDetail>> GetOrderDetailsByOrderId(int orderId)  
            {  
                return await _db.OrdersDetail  
                    .Where(x => x.OrderId == orderId && x.IsActive == 1)  
                    .OrderBy(x => x.VendorId).ToListAsync();  
            }  
    

    And on the Blazor page, I tried something like this and this time the query below gets only the active ones.

    async Task PassiveDetail(OrderDetail orderDetail)  
        {  
            if (orderDetail == _detailToInsert)  
            {  
                _detailToInsert = null;  
            }  
      
      
            await _gridDetail.UpdateRow(orderDetail);  
      
            await PassiveOrderDetailUseCase.ExecuteAsync(orderDetail);  
              
            var _ordersdetails = await ViewOrderDetailsByOrderIdUseCase.ExecuteAsync(orderDetail.OrderId); //gets  only the active ones  
      
            StateHasChanged();  
              
      
        }  
    

    So the question is how I can make this work. Somehow replacing the order detail with LINQ or when I save changes of the order details in the repository, should I also add this order detail to the orders and save the orders? Any ideas?


  4. Cenk 956 Reputation points
    2022-09-19T15:07:37.393+00:00

    I think I found the suspect. The query below shouldn't get the IsActive=0 but it somehow gets! Any ideas for this situation?

    Here is the query:

    public async Task<IEnumerable<Order?>> GetAllOrders(ClaimsPrincipal user)  
        {  
            if (user.IsInRole("Administrators"))  
            {  
                return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync();  
            }  
              
            return await _db.Orders.Include(d => d.OrderDetails.Where(od => od.IsActive == 1)).ThenInclude(v => v.Vendor).ToListAsync();  
      
        }  
    

    The record is updated, why is the query doesn't work the way it is expected? First I am updating then I am querying IsActive = 1

    await PassiveOrderDetailUseCase.ExecuteAsync(orderDetail); //sets to IsActive = 0  
    _orders = await ViewAllOrdersUseCase.ExecuteAsync(user); // call GetAllOrders method above, should get only the actives IsActive = 1  
    

    But IsActive = 0 also comes inside of _orders as seen in the screenshot below.
    242621-isactive.png


  5. Cenk 956 Reputation points
    2022-09-20T06:31:36.813+00:00

    @Zhi Lv - MSFT do you have a solution for this issue? Why the query gets IsActive = 0?