How to fill link the column in FormEdit and Edit action?

sblb 1,231 Reputation points
2022-09-24T09:10:34.817+00:00

Hi,
My app : blazor wasm aps.net core5.

First of all I tried, I will try to explain the configuration of my application is : DataGridView with several column of which ECR & ECO

244526-capture.png

The column ECR is fill when the user click on AddEcr. Thanks to @AgaveJoe the number is incremented with the current year. it's ok.
We can acces to ECO column when we click on Edit button. I want that the user can take or not the number ECO xxx/YY (with the same format that ECR).

The button Update correspond to the Edit.razor this means populate all data in table from database.

Edit.razor

 <FormEdit ButtonText="Update" dev="dev"  
       OnValidSubmit="@EditDeveloper" />  
      
 @code {  
      
     [Parameter] public int developerId { get; set; }  
     Developer dev = new Developer();  
      
      
     protected async override Task OnParametersSetAsync()  
     {  
         dev = await http.GetFromJsonAsync<Developer>($"api/developer/{developerId}");  
     }  
      
     async Task EditDeveloper()  
     {  
         await http.PutAsJsonAsync("api/developer", dev);  
         await js.InvokeVoidAsync("alert", $"Updated Successfully!");  
         uriHelper.NavigateTo("developer");  
                             
     }  

Now the button Number ECO allows to user take the number .

The definition of the button Number ECO is in FormEdit.razor

 <EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">  
     <DataAnnotationsValidator />  
      
      
  <button type="submit" @onclick="@OnSubmitEcoNumber" >Submit</button>  
      
 </EditForm>  
      
 @code {  
  [Parameter] public Developer dev { get; set; }  
  [Parameter] public EventCallback OnValidSubmit { get; set; }  
          
     Developer[] developers { get; set; }   
 protected void OnSubmitEcoNumber()  
 {  
   //It's here that I've to call the method   
 }  
   }  

My question is : how to do the link between the button Number ECO (I think I have to put check box) with the Edit.razor to fill the column ECO?

the api is define below to fill the ECO number with a good format

  [HttpPost]  
        public async Task<IActionResult> Post(Developer developer)  
        {  
            YearCountECO deveco = await IncrementECODeveloperIdAsync();  
  
            developer.YearECO = deveco.YearECO;  
            developer.CountECO = deveco.CountECO;  
  
            YearCount dev = await IncrementDeveloperIdAsync();  
  
            developer.Year = dev.Year;  
            developer.Count = dev.Count;  
  
            _context.Add(developer);  
            await _context.SaveChangesAsync();  
            return Ok(developer.Id);  
        }        
    
  
 private async Task<YearCountECO> IncrementECODeveloperIdAsync()  
        {  
            if (!await _context.Developers.AnyAsync(d => d.Year == DateTime.Now.Year))  
            {  
                return new YearCountECO() { CountECO = 1, YearECO= DateTime.Now.Year };  
            }  
  
            int max = await _context.Developers.Where(d => d.Year == DateTime.Now.Year).MaxAsync(d => d.Count) + 1;  
            return new YearCountECO() { CountECO = max, YearECO = DateTime.Now.Year };  
        }  
Developer technologies | .NET | Blazor
{count} votes

11 answers

Sort by: Most helpful
  1. sblb 1,231 Reputation points
    2022-09-27T10:26:11.95+00:00

    There is no logical reason to have an ECO column in a table since the ECO value is combination of the count and the year.

    The ECR number is generated by the system. You're right is nit necessary to add the column ECR with the format xxx/YY. I can only rendering Count et Year with the format xxx/YY.

    The ECO value must be independent of the ECR value and therefore of Count & Year. Why? the ECO number corresponds to a specific document reference which is different from the ECR number.

    I would like to generate the number with the same logic as you proposed for ECR, leaving the possibility to the user to take the number.

    Below is a screen shot of the scenario for taking an ECO number.
    The user has to go in the Edit mode for example to the line corresponding to ECR: 003/22. The user decides to take the 1st ECO number (i.e. for line 1&2 the user decided not to take an ECO number).
    The user validates the check box "take ECo Number" and the system must generate an ECO number which will be the 1st one in the list, therefore it will be 001/2022.

    245019-capture.png

    what do you want from this community?

    Firstly, to make myself understood. Secondly, to help me find the solution to my questions.

    0 comments No comments

  2. AgaveJoe 30,126 Reputation points
    2022-09-27T11:35:32.087+00:00

    The ECO value must be independent of the ECR value and therefore of Count & Year. Why? the ECO number corresponds to a specific document reference which is different from the ECR number

    For the second time, there is no logical reason for the ECO column since you have the YearECO and CountECO. You've created extra logic which is causing this problem.

    I would like to generate the number with the same logic as you proposed for ECR, leaving the possibility to the user to take the number.

    There are always many ways to solve a problem, I would add a bit column in the table named SelectedECO and an "if" in the ECO getter. Create a new action that handles the ECO values only - not a Put action for the whole object - that sets the ECO values (year and count) and returns the updated Developer object. Don't set the ECP values in the POST. I added a working example - not production code - in the GitHub repo that does this. My example uses a Get. If you have more than an id to submit the use a Put.

    You might have to tweak the code to suit your ever changing needs.

    Firstly, to make myself understood. Secondly, to help me find the solution to my questions.

    The problem is your solutions are nonsensical and you refuse to change your approach. This post is a great example with the empty setter and arguing about the ECO column. I found the only way to get you to move on is if I write your code.

    0 comments No comments

  3. sblb 1,231 Reputation points
    2022-09-27T12:15:40.31+00:00

    , I would add a bit column in the table named SelectedECO and an "if" in the ECO getter. Create a new action that handles the ECO values only .

    This is exactly what I would like to do but I don't know how.
    To be sure you understand, what would you put in the SelectedECO column?
    How do you do an action that handles the ECO values?


  4. sblb 1,231 Reputation points
    2022-09-27T15:44:31.997+00:00

    I am here to get help. Thank you once again
    I don't understand why I can't link my checkbox with selectEcoId.

    0 comments No comments

  5. sblb 1,231 Reputation points
    2022-09-27T17:10:43.027+00:00

    I think I can do

    if(checkValue1 == true)   
    {  
    dev = await http.GetFromJsonAsync<Developer>($"api/developer/SelectEcoById/{id}");  
    }   
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.