Home > Enterprise >  Changing value in database for specific cell
Changing value in database for specific cell

Time:05-28

working on something and stuck at this:

My Razor Page looks like this:

<tbody>
     @foreach(var item in Model.Terminy)
    {
            <tr>
       <form method="post"> <td> <center><button   asp-route-day="" asp-route-value="@item.Dzień_Tygodnia">@item.Dzień_Tygodnia</button><br /></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina)" asp-route-id="@item.Id" asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina">@item.Godzina</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina1)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina1">@item.Godzina1</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina2)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina2">@item.Godzina2</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina3)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina3">@item.Godzina3</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina4)" asp-route-id="@item.Id"   asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina4">@item.Godzina4</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina5)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina5">@item.Godzina5</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina6)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina6">@item.Godzina6</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina7)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina7">@item.Godzina7</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina8)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina8">@item.Godzina8</button></center></td></form>
       <form method="post"> <td> <center><button  asp-route-column="@nameof(@item.Godzina9)" asp-route-id="@item.Id"  asp-route-day="@item.Dzień_Tygodnia" asp-route-value="@item.Godzina9">@item.Godzina9</button></center></td></form>
        </tr>
    }
</tbody>

It looks like this: Table like this

After clicking one of button my backend do some staff and looks like this:

    public async Task<IActionResult> OnPostAsync(int id, string column, string day, string value)
        {
            return RedirectToPage("Potwierdzenie");
        }

Now i want to change value of clicked button from in example 5 to None in database. Any ideas how i can do this? I have got class where i can schedule these values:

      public IActionResult OnPostEdit()
            {
                if (ModelState.IsValid)
                {
                    Terminy.Id = Id;
                    repo.UpdateAsync(Terminy);
                    repo.SaveChangesAsync();
                }
                return RedirectToPage("ADMIN_ListaTerminów");
            }

and now i need to create this one: from value to none.

After switching value in database for specific cell i am going to implement color change of button

CodePudding user response:

Ok, so i am done with it.

My solution is: After clicking button my backend update value in database, so my view will automatically render button with "None" value.

After this my implementation will check if value is equal "None" and if yes mark this button as

 <button type="submit" >None</button>

After upgrade

thanks all for comments. i really appreciate this

  • Related