morry329#
morry329#
CC#
Created by morry329# on 12/1/2024 in #help
Edit function does not work
So I would like a second set of eyes. I wanted to try editing the pre-existing record on my card view (see the screenshot attached) like Beachfront Villa -> Beachfront Villa 8. Even this easy modification does not succeed, as on clicking the save button I got "record not found" And this comes from here in the controller
[HttpPost]
public async Task<IActionResult> Update(ListingProjects updatedUserModelRef)
{


if (oldListingProjects == null)
{
if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return Json(new { success = false, message = "Record not found." }); //this is the error i see on View
}
return NotFound();
}
[HttpPost]
public async Task<IActionResult> Update(ListingProjects updatedUserModelRef)
{


if (oldListingProjects == null)
{
if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return Json(new { success = false, message = "Record not found." }); //this is the error i see on View
}
return NotFound();
}
and this is what the frontend devtool says: https://imgur.com/a/xs8LLlD my database has not the id "1" referred in that devtool:
mysql> Select * from ListingDBTable;
+----+----------------------+----------------------------------+------------+------------+
| Id | ListingName | ImageUrl | CategoryId | LocationId |
+----+----------------------+----------------------------------+------------+------------+
| 5 | Beachfront Villa | http://example.com/villa.jpg | 1 | 1 |
| 6 | hidden moon building | hiddenmoon | 1 | 1 |
| 74 | New Listing | http://example.com/new_image.jpg | 1 | 1 |
+----+----------------------+----------------------------------+------------+------------+
mysql> Select * from ListingDBTable;
+----+----------------------+----------------------------------+------------+------------+
| Id | ListingName | ImageUrl | CategoryId | LocationId |
+----+----------------------+----------------------------------+------------+------------+
| 5 | Beachfront Villa | http://example.com/villa.jpg | 1 | 1 |
| 6 | hidden moon building | hiddenmoon | 1 | 1 |
| 74 | New Listing | http://example.com/new_image.jpg | 1 | 1 |
+----+----------------------+----------------------------------+------------+------------+
` my save button on View should have been picking up any ids listed here (5,6, or 74) but as the devtool shows it picks up 1 instead. i suppose if it picks up 5,6,74 it will let me edit the ListingName property. so could anyone kindly point me in the right direction? Relevant code snippets here https://pastebin.com/9U9zjvaG
20 replies
CC#
Created by morry329# on 11/29/2024 in #help
✅ always gets the invalid data received
I have been creating a simple CRUD app with the ASP.NET. My update function does not work as expected: the save button triggers the error message "invalid data received" ; somehow the model reference is considred null on clicking the save button

//clicking the save btn prompts this method to work
public async Task<IActionResult> Update(ListingProjects updatedUserModelRef)
{
if (updatedUserModelRef == null || updatedUserModelRef.ListingName == null)
{
if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return Json(new { success = false, message = "Invalid data received." }); //however it always falls into this invalid message..
}
return NotFound();
}

//clicking the save btn prompts this method to work
public async Task<IActionResult> Update(ListingProjects updatedUserModelRef)
{
if (updatedUserModelRef == null || updatedUserModelRef.ListingName == null)
{
if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return Json(new { success = false, message = "Invalid data received." }); //however it always falls into this invalid message..
}
return NotFound();
}
could anyone kindly advice me on why the save button does not save the user input as expected? the full code here https://pastebin.com/4C2aYF78
2 replies
CC#
Created by morry329# on 11/11/2024 in #help
Insert Method does not insert or save the user input as wanted
I have a working UI with a text field to enter a property name like "Ca* Oro Bridge" on my MVC view. The save button is also displayed on the view. Onclick it does not save the userinput in the text field (henceforth it is also not saved in the DB). I have debugged the follwing code responsible for handling user inputs
public IActionResult InsertListings()
{
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult InsertListings([Bind("ListingName")] ListingProjects listingProject) // Change to ListingProjects model
{

try
{
if (ModelState.IsValid)
{
_context.ListingDBTable.Add(listingProject);
_context.SaveChanges();
return RedirectToAction("TestDashboard1"); // Redirect to dashboard
}
else
{
// Model is invalid, handle it (e.g., show validation errors)
return View(listingProject); // Return the view with error messages
}
}
catch (DbUpdateException dbUpdateException)
{
ModelState.AddModelError("", "Unable to save changes. " +
"Try again, and if the problem persists " +
"see your system administrator.");
}

return View(listingProject);
}
public IActionResult InsertListings()
{
return View();
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult InsertListings([Bind("ListingName")] ListingProjects listingProject) // Change to ListingProjects model
{

try
{
if (ModelState.IsValid)
{
_context.ListingDBTable.Add(listingProject);
_context.SaveChanges();
return RedirectToAction("TestDashboard1"); // Redirect to dashboard
}
else
{
// Model is invalid, handle it (e.g., show validation errors)
return View(listingProject); // Return the view with error messages
}
}
catch (DbUpdateException dbUpdateException)
{
ModelState.AddModelError("", "Unable to save changes. " +
"Try again, and if the problem persists " +
"see your system administrator.");
}

return View(listingProject);
}
` I am not versed in the world of debugging, but it looks like the HttpGet method refers or returns null. InsertListing method (HttpPost method) deems it as !ModelState.Isvalid (which means my code does not save the input at all) Now I don't quite understand what caused all this null and invalidity. https://pastebin.com/DhCg4Md2 Can anyone kindly point me in the right direction?
1 replies
CC#
Created by morry329# on 11/8/2024 in #help
Save button does not save the inserted data
No description
15 replies
CC#
Created by morry329# on 11/4/2024 in #help
OnClick delete button directs to 404 Error
No description
1 replies
CC#
Created by morry329# on 11/3/2024 in #help
Does this make sense? |
No description
5 replies
CC#
Created by morry329# on 10/13/2024 in #help
my MVC view thinks my model is null!
No description
1 replies
CC#
Created by morry329# on 10/7/2024 in #help
Not found 404 at await fetch
No description
6 replies
CC#
Created by morry329# on 9/30/2024 in #help
Does it make sense to two references (to database migration and data seeding) in the same using
I am totally new to this, so I rely on chatGPT a lot With the help of GPT I have wrote a code like this
var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
var services = scope.ServiceProvider;

var seeder = new DataSeed(db);
seeder.SeedModels();
}
var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
db.Database.Migrate();
var services = scope.ServiceProvider;

var seeder = new DataSeed(db);
seeder.SeedModels();
}
As you see this is the Program.cs snippet (ASP.NET Core 7). My concern is that this code might make no sense to have db.Database.Migrate(); and seeder.SeedModels(); under the same roof (the same using). I don't know much about all this ASP.NET world but I migrated database a couple of times via the commandline like dotnet ef add-migration etc. so I started wondering if db.Database.Migrate(); in Program.cs makes any sense.
What do you all think of this snippet?
6 replies
CC#
Created by morry329# on 9/24/2024 in #help
created a new view but that view only outputs the html (of the login page!)
No description
23 replies
CC#
Created by morry329# on 9/18/2024 in #help
MySqlException: Column 'Age' cannot be null
So this error occured in the following scenario: I have created a simple ASP.NET Core web app with some simple db configurations. On running dotnet run from Rider, the browser displayed my web app (a login form). I have click "register a new user". Then I was redirected to a register form page with three textfields , email, password and repeat password. I filled in all of them and hit register. Now I was bugged with this bunch of exception texts https://pastebin.com/7DqbUai5 I don't understand this error Column 'Age' cannot be null. I made extra sure that my DB has the column Age with non-null values like this:
mysql> SELECT * FROM PortalUsers;
+---------------+------+-------------+-------------------------------------------------+
| Name | Age | Location | DisplayInfo |
+---------------+------+-------------+-------------------------------------------------+
| Alice Smith | 30 | New York | Name: Alice Smith Age: 30 Location: New York |
| Bob Johnson | 25 | Los Angeles | Name: Bob Johnson Age: 25 Location: Los Angeles |
| Charlie Brown | 35 | Chicago | Name: Charlie Brown Age: 35 Location: Chicago |
+---------------+------+-------------+-------------------------------------------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM PortalUsers;
+---------------+------+-------------+-------------------------------------------------+
| Name | Age | Location | DisplayInfo |
+---------------+------+-------------+-------------------------------------------------+
| Alice Smith | 30 | New York | Name: Alice Smith Age: 30 Location: New York |
| Bob Johnson | 25 | Los Angeles | Name: Bob Johnson Age: 25 Location: Los Angeles |
| Charlie Brown | 35 | Chicago | Name: Charlie Brown Age: 35 Location: Chicago |
+---------------+------+-------------+-------------------------------------------------+
3 rows in set (0.00 sec)
` For your reference this is the link to the codes https://pastebin.com/k88fKn7r Could anyone point me in the right direction? I want to solve this error but I need another set of eyes PS: I am just thinking that this error may refer to the column Age which belongs to another table from another DB. The output displayed here came from the table PortalUser in the searchhome DB, but I may have another PortalUser table in my second DB. If that is the case will this error point to that another PortalUser which may have no column values? Hope all this makes sense.
7 replies
CC#
Created by morry329# on 9/17/2024 in #help
MySqlException: Field 'CreatedOnUtc' doesn't have a default value
So I have been creating a very simple ASP.NET Core application lately with a simple mariaDB configuration and nginx Once the dotnet run has been typed, a web app pops up on Chrome prompting me to enter login credentials. As the combination of root-root (for both of username and password) is not allowed there, I opted to create a new user. The web app now prompted me to create brand new credentials (email, password, username). Once those have been entered and the submit button has been hit, the following error got triggered https://pastebin.com/GrcSaHQZ I tried to find that field in question: MySqlException: Field 'CreatedOnUtc' doesn't have a default value ChatGPT gave me this collection of potential fixes https://pastebin.com/nUDiybVk but none of them could not find that field/column CreatedOnUtc Would it be a good idea to create that column on my db with the default value? Do you have any other idea how to fix this error??
4 replies
CC#
Created by morry329# on 9/14/2024 in #help
MySqlException: Table 'searchhome.aspnetusers' doesn't exist
So I wanted to do the following: I have already created a simple database with a table. On that db table some values have been added. I wanted to display that added value on my simple ASP.NET Core app. However, the dotnet run gave me the error as per screenshot attached (aspnetusers does not exist) The dotnet ef database update leads to the same error (aspnetusers does not exist). I have tried adding that aspnetuser table or tried updating the database( INSERT INTO __EFMigrationsHistory (MigrationId, ProductVersion) VALUES ('00000000000000_CreateIdentitySchema', '7.0.2');) None of these helped me out. All my codes are here https://pastebin.com/kdgjhGTu Could anyone kindly point me in the right direction??
16 replies
CC#
Created by morry329# on 7/10/2024 in #help
Dealing with the professor: advice appreciated
Hi all I would like some inputs to deal with the oral exam / the nasty professor. I just had to deal with him during one of his oral exams and in two weeks I have the other oral exam with him. I will describe what exactly was the problem. Any advice as to how to ace the exam appreciated. Problem: the 20 minutes is the standard time for all the exams which that Prof is in charge of. He does not make use of it effectively: the entire exam time he was the one who mostly did the talking. I tried to just talk to myself to show them what I learned but his interruption won the race. Even though I answered his questions correctly he said I had to answer the same question again to which I was like "gosh I just told you have you not heard it? " At the tail end of this exam I went on to explain the quick summary of the subject matters to the third examiner. Like "so you can use this app to record your medical checkups, you log into the app and your personal data is stored in the DB which is the integral part of the three tier architecture. This architecture is (the Prof blocked me). I will see if those few minutes of quick app ran down will save my grade. But how would you all behave if you were in my shoes? I have another one for another class with the same professor. Any advice for getting my point across better appreciated TL:DR A prof did not dare to listen to me during my oral exam, I resorted to interrupt him and just talk to myself. How could I deal with him better next time so I could finish my sentences ?
13 replies
CC#
Created by morry329# on 6/14/2024 in #help
KMP-Algorithm in C#
No description
10 replies
CC#
Created by morry329# on 5/12/2024 in #help
Fighting with the longest common prefix puzzle
No description
44 replies
CC#
Created by morry329# on 4/14/2024 in #help
IndexOutOfBoundsException triggered | LeetCode Where will the ball fall
Link to the puzzle description https://leetcode.com/problems/where-will-the-ball-fall/description/ I have been fighting with this puzzle for more than a month. Still my code cannot output correctly. I tried this testcase Input: grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]] Output: [1,-1,-1,-1,-1] And my WIP code (it triggers IndexOutOfBoundsException at line int currRow = 0. Could anyone kindly point me in the right direction?:
public int[] FindBall(int[][] grid){
int col = grid[0].Length;
int row= grid.Length;
int[] result = new int[col];

for(int i=0; i< col; i++){
result [i]= Helper(grid,row,col);
}

return result;
}

public int Helper(int[][] grid, int row, int col){
int currCol = 0;
int currRow = 0; //OutOfBoundsException
while(currRow < row){
if (grid[currRow][currCol]==1){
if(currCol == col - 1 || grid[currRow][currCol+1]==-1){
return -1;
break;
} else {
currCol++;
currRow++;
}
} else if (grid[currRow][currCol] ==-1){
if(currCol <0 || grid[currRow][currCol-1]==1){
return -1;
break;
} else {
currCol--;
currRow++;
}
}
currRow++;
}
if(currRow==row){
currCol = grid[currRow][currCol];
}
return currCol;
}
public int[] FindBall(int[][] grid){
int col = grid[0].Length;
int row= grid.Length;
int[] result = new int[col];

for(int i=0; i< col; i++){
result [i]= Helper(grid,row,col);
}

return result;
}

public int Helper(int[][] grid, int row, int col){
int currCol = 0;
int currRow = 0; //OutOfBoundsException
while(currRow < row){
if (grid[currRow][currCol]==1){
if(currCol == col - 1 || grid[currRow][currCol+1]==-1){
return -1;
break;
} else {
currCol++;
currRow++;
}
} else if (grid[currRow][currCol] ==-1){
if(currCol <0 || grid[currRow][currCol-1]==1){
return -1;
break;
} else {
currCol--;
currRow++;
}
}
currRow++;
}
if(currRow==row){
currCol = grid[currRow][currCol];
}
return currCol;
}
7 replies
CC#
Created by morry329# on 4/6/2024 in #help
A small hiccup for the LeetCode puzzle Where the ball will fall
Link to the original puzzle https://leetcode.com/problems/where-will-the-ball-fall/ My code does not print out the right output just yet
public class ZigZagBallFallsTry
{

public int[] FindBall(int[][] grid)
{
int col = grid[0].Length-1;
int row = grid.Length-1;
int[] result = new int[col];

for (int i = 0; i < col; i++)
{
result[i] = BallHelp(grid, row, col);
}

return result;

}

private int BallHelp(int[][] grid, int row, int col)
{
int currRow = 0;
int currCol = col;

while (currRow <= row)
{
if (grid[currRow][currCol] == 1)
{
if (currCol == col || grid[currRow][currCol + 1] == -1)
{
return -1;
}
else
{
currCol++;
currRow++;
}
}
else if (grid[currRow][currCol] == -1)
{
if (currCol == 0 || grid[currRow][currCol - 1] == 1)
{
return -1;
}
else
{
currCol--;
currRow++;
}
}
else
{
currRow++;
}
}

return currCol;
}

}
public class ZigZagBallFallsTry
{

public int[] FindBall(int[][] grid)
{
int col = grid[0].Length-1;
int row = grid.Length-1;
int[] result = new int[col];

for (int i = 0; i < col; i++)
{
result[i] = BallHelp(grid, row, col);
}

return result;

}

private int BallHelp(int[][] grid, int row, int col)
{
int currRow = 0;
int currCol = col;

while (currRow <= row)
{
if (grid[currRow][currCol] == 1)
{
if (currCol == col || grid[currRow][currCol + 1] == -1)
{
return -1;
}
else
{
currCol++;
currRow++;
}
}
else if (grid[currRow][currCol] == -1)
{
if (currCol == 0 || grid[currRow][currCol - 1] == 1)
{
return -1;
}
else
{
currCol--;
currRow++;
}
}
else
{
currRow++;
}
}

return currCol;
}

}
The output is -1, -1, -1, -1 whilst it is supposed to be 1, -1, -1, -1, -1. The input here is grid = [[1,1,1,-1,-1],[1,1,1,-1,-1],[-1,-1,-1,1,1],[1,1,1,1,-1],[-1,-1,-1,-1,-1]]` Could anyone kindly point me in the right direction?
1 replies
CC#
Created by morry329# on 3/17/2024 in #help
Not able to pass the test case correctly
The link to the original task https://leetcode.com/problems/where-will-the-ball-fall/ This is my WIP code
public class ZigZagBallFallsTry
{
public int[] FindBall(int[][] grid)
{
int m = grid.Length - 1;
int n = grid[0].Length - 1;

int[] result = new int[grid[0].Length]; // Initialize result array with correct size

for (int row = 0; row <= m; row++) // Loop until row <= m
{
result[row] = RecordBallMovements(grid, m, n); // Pass row index to RecordBallMovements
}

return result;
}

private int RecordBallMovements(int[][] grid, int m, int n)
{
int helperCol = 0; // Initialize helperCol here
for (int helperRow = 0; helperRow < m; helperRow++) // Loop until helperRow <= row
{
for (; helperCol >= 0 && helperCol <= n; helperCol++) // Correct loop condition and increment helperCol
{
if (grid[helperRow][helperCol] == 1)
{
if (helperCol == n || grid[helperRow][helperCol + 1] == -1) // Use == instead of >
{
return -1;
break;
}
}
else if (grid[helperRow][helperCol] == -1)
{
if (helperCol == 0 || grid[helperRow][helperCol - 1] == 1) // Use == instead of <
{
return -1;
break;
}
helperCol--; // Decrement helperCol for left movement
}
}
}
return helperCol;
}


}
public class ZigZagBallFallsTry
{
public int[] FindBall(int[][] grid)
{
int m = grid.Length - 1;
int n = grid[0].Length - 1;

int[] result = new int[grid[0].Length]; // Initialize result array with correct size

for (int row = 0; row <= m; row++) // Loop until row <= m
{
result[row] = RecordBallMovements(grid, m, n); // Pass row index to RecordBallMovements
}

return result;
}

private int RecordBallMovements(int[][] grid, int m, int n)
{
int helperCol = 0; // Initialize helperCol here
for (int helperRow = 0; helperRow < m; helperRow++) // Loop until helperRow <= row
{
for (; helperCol >= 0 && helperCol <= n; helperCol++) // Correct loop condition and increment helperCol
{
if (grid[helperRow][helperCol] == 1)
{
if (helperCol == n || grid[helperRow][helperCol + 1] == -1) // Use == instead of >
{
return -1;
break;
}
}
else if (grid[helperRow][helperCol] == -1)
{
if (helperCol == 0 || grid[helperRow][helperCol - 1] == 1) // Use == instead of <
{
return -1;
break;
}
helperCol--; // Decrement helperCol for left movement
}
}
}
return helperCol;
}


}
The output for this code is ==> -1 ==> -1 ==> -1 ==> -1 ==> -1 But it was supposed to be ==> 1 ==> -1 ==> -1 ==> -1 ==> -1` instead I don't understand why my code stores -1 instead of 1 at the first index on my array. Could anyone kindly point me in the right direction?
3 replies
CC#
Created by morry329# on 3/4/2024 in #help
Create Migration always fail
So I wanted to create a SQL Server database table based on your C# model. I have typed down dotnet ef migrations add InitialCreate but it never gets to migrate. The dotnet build shows no noticeable errors like this
PM> dotnet ef migrations add InitialCreate
Build started...
Build failed. Use dotnet build to see the errors.
PM> dotnet build
MSBuild version 17.7.1+971bf70db for .NET
Determining projects to restore...
All projects are up-to-date for restore.
CRUD_HomeFinder -> C:\Users\Mami Kawamura\Source\Repos\CRUD_HomeFinder\CRUD_HomeFinder\bin\Debug\net6.0\MVCCore.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:02.35
PM> dotnet ef migrations add InitialCreate
Build started...
Build failed. Use dotnet build to see the errors.
PM> dotnet build
MSBuild version 17.7.1+971bf70db for .NET
Determining projects to restore...
All projects are up-to-date for restore.
CRUD_HomeFinder -> C:\Users\Mami Kawamura\Source\Repos\CRUD_HomeFinder\CRUD_HomeFinder\bin\Debug\net6.0\MVCCore.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:02.35
` The link to all other database-related code https://pastebin.com/qFyNtM04 Could anyone point me in the right direction?
4 replies